|
2 | 2 | import pytest |
3 | 3 |
|
4 | 4 | from hcloud.firewalls.client import BoundFirewall |
| 5 | +from hcloud.firewalls.domain import Firewall |
5 | 6 | from hcloud.floating_ips.client import BoundFloatingIP |
6 | 7 | from hcloud.isos.client import BoundIso |
7 | 8 | from hcloud.servers.client import ServersClient, BoundServer |
@@ -576,6 +577,46 @@ def test_create_with_networks(self, servers_client, response_create_simple_serve |
576 | 577 |
|
577 | 578 | assert next_actions[0].id == 13 |
578 | 579 |
|
| 580 | + def test_create_with_firewalls(self, servers_client, response_create_simple_server): |
| 581 | + servers_client._client.request.return_value = response_create_simple_server |
| 582 | + firewalls = [Firewall(id=1), BoundFirewall(mock.MagicMock(), dict(id=2))] |
| 583 | + response = servers_client.create( |
| 584 | + "my-server", |
| 585 | + server_type=ServerType(name="cx11"), |
| 586 | + image=Image(id=4711), |
| 587 | + firewalls=firewalls, |
| 588 | + start_after_create=False |
| 589 | + ) |
| 590 | + servers_client._client.request.assert_called_with( |
| 591 | + url="/servers", |
| 592 | + method="POST", |
| 593 | + json={ |
| 594 | + 'name': "my-server", |
| 595 | + 'server_type': "cx11", |
| 596 | + 'image': 4711, |
| 597 | + 'firewalls': [{"id": 1}, {"id": 2}], |
| 598 | + "start_after_create": False |
| 599 | + } |
| 600 | + ) |
| 601 | + |
| 602 | + bound_server = response.server |
| 603 | + bound_action = response.action |
| 604 | + next_actions = response.next_actions |
| 605 | + root_password = response.root_password |
| 606 | + |
| 607 | + assert root_password == "YItygq1v3GYjjMomLaKc" |
| 608 | + |
| 609 | + assert bound_server._client is servers_client |
| 610 | + assert bound_server.id == 1 |
| 611 | + assert bound_server.name == "my-server" |
| 612 | + |
| 613 | + assert isinstance(bound_action, BoundAction) |
| 614 | + assert bound_action._client == servers_client._client.actions |
| 615 | + assert bound_action.id == 1 |
| 616 | + assert bound_action.command == "create_server" |
| 617 | + |
| 618 | + assert next_actions[0].id == 13 |
| 619 | + |
579 | 620 | @pytest.mark.parametrize("server", [Server(id=1), BoundServer(mock.MagicMock(), dict(id=1))]) |
580 | 621 | def test_get_actions_list(self, servers_client, server, response_get_actions): |
581 | 622 | servers_client._client.request.return_value = response_get_actions |
|
0 commit comments