From 0b21eaae32fa7bb97153d10a8e52c369453ae4db Mon Sep 17 00:00:00 2001 From: jo Date: Fri, 15 Aug 2025 16:53:31 +0200 Subject: [PATCH] style: format test case - Make it more breathable, - Break calls on multiple lines --- tests/unit/actions/test_client.py | 52 ++- tests/unit/certificates/test_client.py | 91 ++++- tests/unit/datacenters/test_client.py | 31 +- tests/unit/firewalls/test_client.py | 103 ++++-- tests/unit/floating_ips/test_client.py | 115 +++++-- tests/unit/images/test_client.py | 94 ++++- tests/unit/isos/test_client.py | 29 +- tests/unit/load_balancer_types/test_client.py | 23 +- tests/unit/load_balancers/test_client.py | 146 ++++++-- tests/unit/locations/test_client.py | 29 +- tests/unit/networks/test_client.py | 147 ++++++-- tests/unit/placement_groups/test_client.py | 38 +- tests/unit/primary_ips/test_client.py | 95 +++-- tests/unit/server_types/test_client.py | 23 +- tests/unit/servers/test_client.py | 324 ++++++++++++++---- tests/unit/ssh_keys/test_client.py | 69 +++- tests/unit/volumes/test_client.py | 136 ++++++-- 17 files changed, 1242 insertions(+), 303 deletions(-) diff --git a/tests/unit/actions/test_client.py b/tests/unit/actions/test_client.py index fcd3d12c..761452d0 100644 --- a/tests/unit/actions/test_client.py +++ b/tests/unit/actions/test_client.py @@ -30,9 +30,17 @@ def test_wait_until_finished( running_action, successfully_action, ): - request_mock.side_effect = [running_action, successfully_action] + request_mock.side_effect = [ + running_action, + successfully_action, + ] + bound_running_action.wait_until_finished() - request_mock.assert_called_with(url="/actions/2", method="GET") + + request_mock.assert_called_with( + method="GET", + url="/actions/2", + ) assert bound_running_action.status == "success" assert request_mock.call_count == 2 @@ -83,8 +91,13 @@ def test_get_by_id( generic_action, ): request_mock.return_value = generic_action + action = actions_client.get_by_id(1) - request_mock.assert_called_with(url="/resource/actions/1", method="GET") + + request_mock.assert_called_with( + method="GET", + url="/resource/actions/1", + ) assert action._client == actions_client._parent.actions assert action.id == 1 assert action.command == "stop_server" @@ -101,9 +114,13 @@ def test_get_list( params, ): request_mock.return_value = generic_action_list + result = actions_client.get_list(**params) + request_mock.assert_called_with( - url="/resource/actions", method="GET", params=params + method="GET", + url="/resource/actions", + params=params, ) assert result.meta is not None @@ -131,12 +148,15 @@ def test_get_all( params, ): request_mock.return_value = generic_action_list + actions = actions_client.get_all(**params) params.update({"page": 1, "per_page": 50}) request_mock.assert_called_with( - url="/resource/actions", method="GET", params=params + method="GET", + url="/resource/actions", + params=params, ) assert len(actions) == 2 @@ -165,8 +185,13 @@ def test_get_by_id( generic_action, ): request_mock.return_value = generic_action + action = actions_client.get_by_id(1) - request_mock.assert_called_with(url="/actions/1", method="GET") + + request_mock.assert_called_with( + method="GET", + url="/actions/1", + ) assert action._client == actions_client._parent.actions assert action.id == 1 assert action.command == "stop_server" @@ -183,9 +208,15 @@ def test_get_list( params, ): request_mock.return_value = generic_action_list + with pytest.deprecated_call(): result = actions_client.get_list(**params) - request_mock.assert_called_with(url="/actions", method="GET", params=params) + + request_mock.assert_called_with( + method="GET", + url="/actions", + params=params, + ) assert result.meta is not None @@ -212,12 +243,17 @@ def test_get_all( params, ): request_mock.return_value = generic_action_list + with pytest.deprecated_call(): actions = actions_client.get_all(**params) params.update({"page": 1, "per_page": 50}) - request_mock.assert_called_with(url="/actions", method="GET", params=params) + request_mock.assert_called_with( + method="GET", + url="/actions", + params=params, + ) assert len(actions) == 2 diff --git a/tests/unit/certificates/test_client.py b/tests/unit/certificates/test_client.py index 1ef152fa..0c7c8c7f 100644 --- a/tests/unit/certificates/test_client.py +++ b/tests/unit/certificates/test_client.py @@ -29,9 +29,13 @@ def test_get_actions_list( params, ): request_mock.return_value = response_get_actions + result = bound_certificate.get_actions_list(**params) + request_mock.assert_called_with( - url="/certificates/14/actions", method="GET", params=params + method="GET", + url="/certificates/14/actions", + params=params, ) actions = result.actions @@ -51,12 +55,15 @@ def test_get_actions( response_get_actions, ): request_mock.return_value = response_get_actions + actions = bound_certificate.get_actions() params = {"page": 1, "per_page": 50} request_mock.assert_called_with( - url="/certificates/14/actions", method="GET", params=params + method="GET", + url="/certificates/14/actions", + params=params, ) assert len(actions) == 1 @@ -95,9 +102,13 @@ def test_update( response_update_certificate, ): request_mock.return_value = response_update_certificate + certificate = bound_certificate.update(name="New name") + request_mock.assert_called_with( - url="/certificates/14", method="PUT", json={"name": "New name"} + method="PUT", + url="/certificates/14", + json={"name": "New name"}, ) assert certificate.id == 2323 @@ -110,8 +121,13 @@ def test_delete( generic_action, ): request_mock.return_value = generic_action + delete_success = bound_certificate.delete() - request_mock.assert_called_with(url="/certificates/14", method="DELETE") + + request_mock.assert_called_with( + method="DELETE", + url="/certificates/14", + ) assert delete_success is True @@ -122,9 +138,12 @@ def test_retry_issuance( response_retry_issuance_action, ): request_mock.return_value = response_retry_issuance_action + action = bound_certificate.retry_issuance() + request_mock.assert_called_with( - url="/certificates/14/actions/retry", method="POST" + method="POST", + url="/certificates/14/actions/retry", ) assert action.id == 14 @@ -143,8 +162,13 @@ def test_get_by_id( certificate_response, ): request_mock.return_value = certificate_response + certificate = certificates_client.get_by_id(1) - request_mock.assert_called_with(url="/certificates/1", method="GET") + + request_mock.assert_called_with( + method="GET", + url="/certificates/1", + ) assert certificate._client is certificates_client assert certificate.id == 2323 assert certificate.name == "My Certificate" @@ -170,9 +194,13 @@ def test_get_list( params, ): request_mock.return_value = two_certificates_response + result = certificates_client.get_list(**params) + request_mock.assert_called_with( - url="/certificates", method="GET", params=params + method="GET", + url="/certificates", + params=params, ) certificates = result.certificates @@ -200,11 +228,15 @@ def test_get_all( params, ): request_mock.return_value = two_certificates_response + certificates = certificates_client.get_all(**params) params.update({"page": 1, "per_page": 50}) + request_mock.assert_called_with( - url="/certificates", method="GET", params=params + method="GET", + url="/certificates", + params=params, ) assert len(certificates) == 2 @@ -227,11 +259,15 @@ def test_get_by_name( one_certificates_response, ): request_mock.return_value = one_certificates_response + certificates = certificates_client.get_by_name("My Certificate") params = {"name": "My Certificate"} + request_mock.assert_called_with( - url="/certificates", method="GET", params=params + method="GET", + url="/certificates", + params=params, ) assert certificates._client is certificates_client @@ -245,14 +281,16 @@ def test_create( certificate_response, ): request_mock.return_value = certificate_response + certificate = certificates_client.create( name="My Certificate", certificate="-----BEGIN CERTIFICATE-----\n...", private_key="-----BEGIN PRIVATE KEY-----\n...", ) + request_mock.assert_called_with( - url="/certificates", method="POST", + url="/certificates", json={ "name": "My Certificate", "certificate": "-----BEGIN CERTIFICATE-----\n...", @@ -271,12 +309,14 @@ def test_create_managed( create_managed_certificate_response, ): request_mock.return_value = create_managed_certificate_response + create_managed_certificate_rsp = certificates_client.create_managed( name="My Certificate", domain_names=["example.com", "*.example.org"] ) + request_mock.assert_called_with( - url="/certificates", method="POST", + url="/certificates", json={ "name": "My Certificate", "domain_names": ["example.com", "*.example.org"], @@ -301,9 +341,13 @@ def test_update( response_update_certificate, ): request_mock.return_value = response_update_certificate + certificate = certificates_client.update(certificate, name="New name") + request_mock.assert_called_with( - url="/certificates/1", method="PUT", json={"name": "New name"} + method="PUT", + url="/certificates/1", + json={"name": "New name"}, ) assert certificate.id == 2323 @@ -321,8 +365,13 @@ def test_delete( generic_action, ): request_mock.return_value = generic_action + delete_success = certificates_client.delete(certificate) - request_mock.assert_called_with(url="/certificates/1", method="DELETE") + + request_mock.assert_called_with( + method="DELETE", + url="/certificates/1", + ) assert delete_success is True @@ -338,9 +387,12 @@ def test_retry_issuance( response_retry_issuance_action, ): request_mock.return_value = response_retry_issuance_action + action = certificates_client.retry_issuance(certificate) + request_mock.assert_called_with( - url="/certificates/1/actions/retry", method="POST" + method="POST", + url="/certificates/1/actions/retry", ) assert action.id == 14 @@ -355,7 +407,10 @@ def test_actions_get_by_id( request_mock.return_value = {"action": response_get_actions["actions"][0]} action = certificates_client.actions.get_by_id(13) - request_mock.assert_called_with(url="/certificates/actions/13", method="GET") + request_mock.assert_called_with( + method="GET", + url="/certificates/actions/13", + ) assert isinstance(action, BoundAction) assert action._client == certificates_client._parent.actions @@ -369,11 +424,12 @@ def test_actions_get_list( response_get_actions, ): request_mock.return_value = response_get_actions + result = certificates_client.actions.get_list() request_mock.assert_called_with( - url="/certificates/actions", method="GET", + url="/certificates/actions", params={}, ) @@ -393,11 +449,12 @@ def test_actions_get_all( response_get_actions, ): request_mock.return_value = response_get_actions + actions = certificates_client.actions.get_all() request_mock.assert_called_with( - url="/certificates/actions", method="GET", + url="/certificates/actions", params={"page": 1, "per_page": 50}, ) diff --git a/tests/unit/datacenters/test_client.py b/tests/unit/datacenters/test_client.py index c51331bd..7f5ca96b 100644 --- a/tests/unit/datacenters/test_client.py +++ b/tests/unit/datacenters/test_client.py @@ -69,8 +69,13 @@ def test_get_by_id( datacenter_response, ): request_mock.return_value = datacenter_response + datacenter = datacenters_client.get_by_id(1) - request_mock.assert_called_with(url="/datacenters/1", method="GET") + + request_mock.assert_called_with( + method="GET", + url="/datacenters/1", + ) assert datacenter._client is datacenters_client assert datacenter.id == 1 assert datacenter.name == "fsn1-dc8" @@ -86,8 +91,14 @@ def test_get_list( params, ): request_mock.return_value = two_datacenters_response + result = datacenters_client.get_list(**params) - request_mock.assert_called_with(url="/datacenters", method="GET", params=params) + + request_mock.assert_called_with( + method="GET", + url="/datacenters", + params=params, + ) datacenters = result.datacenters assert result.meta is not None @@ -116,10 +127,16 @@ def test_get_all( params, ): request_mock.return_value = two_datacenters_response + datacenters = datacenters_client.get_all(**params) params.update({"page": 1, "per_page": 50}) - request_mock.assert_called_with(url="/datacenters", method="GET", params=params) + + request_mock.assert_called_with( + method="GET", + url="/datacenters", + params=params, + ) assert len(datacenters) == 2 @@ -143,10 +160,16 @@ def test_get_by_name( one_datacenters_response, ): request_mock.return_value = one_datacenters_response + datacenter = datacenters_client.get_by_name("fsn1-dc8") params = {"name": "fsn1-dc8"} - request_mock.assert_called_with(url="/datacenters", method="GET", params=params) + + request_mock.assert_called_with( + method="GET", + url="/datacenters", + params=params, + ) assert datacenter._client is datacenters_client assert datacenter.id == 1 diff --git a/tests/unit/firewalls/test_client.py b/tests/unit/firewalls/test_client.py index a2f91375..9c65a26b 100644 --- a/tests/unit/firewalls/test_client.py +++ b/tests/unit/firewalls/test_client.py @@ -84,9 +84,13 @@ def test_get_actions_list( params, ): request_mock.return_value = response_get_actions + result = bound_firewall.get_actions_list(**params) + request_mock.assert_called_with( - url="/firewalls/1/actions", method="GET", params=params + method="GET", + url="/firewalls/1/actions", + params=params, ) actions = result.actions @@ -108,12 +112,15 @@ def test_get_actions( params, ): request_mock.return_value = response_get_actions + actions = bound_firewall.get_actions(**params) params.update({"page": 1, "per_page": 50}) request_mock.assert_called_with( - url="/firewalls/1/actions", method="GET", params=params + method="GET", + url="/firewalls/1/actions", + params=params, ) assert len(actions) == 1 @@ -129,12 +136,14 @@ def test_update( response_update_firewall, ): request_mock.return_value = response_update_firewall + firewall = bound_firewall.update( name="New Corporate Intranet Protection", labels={} ) + request_mock.assert_called_with( - url="/firewalls/1", method="PUT", + url="/firewalls/1", json={"name": "New Corporate Intranet Protection", "labels": {}}, ) @@ -147,7 +156,11 @@ def test_delete( bound_firewall, ): delete_success = bound_firewall.delete() - request_mock.assert_called_with(url="/firewalls/1", method="DELETE") + + request_mock.assert_called_with( + method="DELETE", + url="/firewalls/1", + ) assert delete_success is True @@ -158,6 +171,7 @@ def test_set_rules( response_set_rules, ): request_mock.return_value = response_set_rules + actions = bound_firewall.set_rules( [ FirewallRule( @@ -168,9 +182,10 @@ def test_set_rules( ) ] ) + request_mock.assert_called_with( - url="/firewalls/1/actions/set_rules", method="POST", + url="/firewalls/1/actions/set_rules", json={ "rules": [ { @@ -193,12 +208,14 @@ def test_apply_to_resources( response_set_rules, ): request_mock.return_value = response_set_rules + actions = bound_firewall.apply_to_resources( [FirewallResource(type=FirewallResource.TYPE_SERVER, server=Server(id=5))] ) + request_mock.assert_called_with( - url="/firewalls/1/actions/apply_to_resources", method="POST", + url="/firewalls/1/actions/apply_to_resources", json={"apply_to": [{"type": "server", "server": {"id": 5}}]}, ) @@ -212,12 +229,14 @@ def test_remove_from_resources( response_set_rules, ): request_mock.return_value = response_set_rules + actions = bound_firewall.remove_from_resources( [FirewallResource(type=FirewallResource.TYPE_SERVER, server=Server(id=5))] ) + request_mock.assert_called_with( - url="/firewalls/1/actions/remove_from_resources", method="POST", + url="/firewalls/1/actions/remove_from_resources", json={"remove_from": [{"type": "server", "server": {"id": 5}}]}, ) @@ -237,8 +256,13 @@ def test_get_by_id( firewall_response, ): request_mock.return_value = firewall_response + firewall = firewalls_client.get_by_id(1) - request_mock.assert_called_with(url="/firewalls/1", method="GET") + + request_mock.assert_called_with( + method="GET", + url="/firewalls/1", + ) assert firewall._client is firewalls_client assert firewall.id == 38 assert firewall.name == "Corporate Intranet Protection" @@ -265,8 +289,14 @@ def test_get_list( params, ): request_mock.return_value = two_firewalls_response + result = firewalls_client.get_list(**params) - request_mock.assert_called_with(url="/firewalls", method="GET", params=params) + + request_mock.assert_called_with( + method="GET", + url="/firewalls", + params=params, + ) firewalls = result.firewalls assert result.meta is not None @@ -303,11 +333,16 @@ def test_get_all( params, ): request_mock.return_value = two_firewalls_response + firewalls = firewalls_client.get_all(**params) params.update({"page": 1, "per_page": 50}) - request_mock.assert_called_with(url="/firewalls", method="GET", params=params) + request_mock.assert_called_with( + method="GET", + url="/firewalls", + params=params, + ) assert len(firewalls) == 2 @@ -329,11 +364,16 @@ def test_get_by_name( one_firewalls_response, ): request_mock.return_value = one_firewalls_response + firewall = firewalls_client.get_by_name("Corporate Intranet Protection") params = {"name": "Corporate Intranet Protection"} - request_mock.assert_called_with(url="/firewalls", method="GET", params=params) + request_mock.assert_called_with( + method="GET", + url="/firewalls", + params=params, + ) assert firewall._client is firewalls_client assert firewall.id == 38 @@ -350,9 +390,13 @@ def test_get_actions_list( response_get_actions, ): request_mock.return_value = response_get_actions + result = firewalls_client.get_actions_list(firewall) + request_mock.assert_called_with( - url="/firewalls/1/actions", method="GET", params={} + method="GET", + url="/firewalls/1/actions", + params={}, ) actions = result.actions @@ -372,6 +416,7 @@ def test_create( response_create_firewall, ): request_mock.return_value = response_create_firewall + response = firewalls_client.create( "Corporate Intranet Protection", rules=[ @@ -391,9 +436,10 @@ def test_create( ), ], ) + request_mock.assert_called_with( - url="/firewalls", method="POST", + url="/firewalls", json={ "name": "Corporate Intranet Protection", "rules": [ @@ -430,12 +476,14 @@ def test_update( response_update_firewall, ): request_mock.return_value = response_update_firewall + firewall = firewalls_client.update( firewall, name="New Corporate Intranet Protection", labels={} ) + request_mock.assert_called_with( - url="/firewalls/38", method="PUT", + url="/firewalls/38", json={"name": "New Corporate Intranet Protection", "labels": {}}, ) @@ -453,6 +501,7 @@ def test_set_rules( response_set_rules, ): request_mock.return_value = response_set_rules + actions = firewalls_client.set_rules( firewall, [ @@ -463,9 +512,10 @@ def test_set_rules( ) ], ) + request_mock.assert_called_with( - url="/firewalls/1/actions/set_rules", method="POST", + url="/firewalls/1/actions/set_rules", json={ "rules": [ { @@ -490,7 +540,11 @@ def test_delete( firewall, ): delete_success = firewalls_client.delete(firewall) - request_mock.assert_called_with(url="/firewalls/1", method="DELETE") + + request_mock.assert_called_with( + method="DELETE", + url="/firewalls/1", + ) assert delete_success is True @@ -510,9 +564,10 @@ def test_apply_to_resources( firewall, [FirewallResource(type=FirewallResource.TYPE_SERVER, server=Server(id=5))], ) + request_mock.assert_called_with( - url="/firewalls/1/actions/apply_to_resources", method="POST", + url="/firewalls/1/actions/apply_to_resources", json={"apply_to": [{"type": "server", "server": {"id": 5}}]}, ) @@ -535,9 +590,10 @@ def test_remove_from_resources( firewall, [FirewallResource(type=FirewallResource.TYPE_SERVER, server=Server(id=5))], ) + request_mock.assert_called_with( - url="/firewalls/1/actions/remove_from_resources", method="POST", + url="/firewalls/1/actions/remove_from_resources", json={"remove_from": [{"type": "server", "server": {"id": 5}}]}, ) @@ -553,7 +609,10 @@ def test_actions_get_by_id( request_mock.return_value = {"action": response_get_actions["actions"][0]} action = firewalls_client.actions.get_by_id(13) - request_mock.assert_called_with(url="/firewalls/actions/13", method="GET") + request_mock.assert_called_with( + method="GET", + url="/firewalls/actions/13", + ) assert isinstance(action, BoundAction) assert action._client == firewalls_client._parent.actions @@ -567,11 +626,12 @@ def test_actions_get_list( response_get_actions, ): request_mock.return_value = response_get_actions + result = firewalls_client.actions.get_list() request_mock.assert_called_with( - url="/firewalls/actions", method="GET", + url="/firewalls/actions", params={}, ) @@ -591,11 +651,12 @@ def test_actions_get_all( response_get_actions, ): request_mock.return_value = response_get_actions + actions = firewalls_client.actions.get_all() request_mock.assert_called_with( - url="/firewalls/actions", method="GET", + url="/firewalls/actions", params={"page": 1, "per_page": 50}, ) diff --git a/tests/unit/floating_ips/test_client.py b/tests/unit/floating_ips/test_client.py index 032d4914..1cc5bd1f 100644 --- a/tests/unit/floating_ips/test_client.py +++ b/tests/unit/floating_ips/test_client.py @@ -50,10 +50,12 @@ def test_get_actions( response_get_actions, ): request_mock.return_value = response_get_actions + actions = bound_floating_ip.get_actions(sort="id") + request_mock.assert_called_with( - url="/floating_ips/14/actions", method="GET", + url="/floating_ips/14/actions", params={"sort": "id", "page": 1, "per_page": 50}, ) @@ -70,12 +72,14 @@ def test_update( response_update_floating_ip, ): request_mock.return_value = response_update_floating_ip + floating_ip = bound_floating_ip.update( description="New description", name="New name" ) + request_mock.assert_called_with( - url="/floating_ips/14", method="PUT", + url="/floating_ips/14", json={"description": "New description", "name": "New name"}, ) @@ -90,8 +94,13 @@ def test_delete( generic_action, ): request_mock.return_value = generic_action + delete_success = bound_floating_ip.delete() - request_mock.assert_called_with(url="/floating_ips/14", method="DELETE") + + request_mock.assert_called_with( + method="DELETE", + url="/floating_ips/14", + ) assert delete_success is True @@ -102,10 +111,12 @@ def test_change_protection( generic_action, ): request_mock.return_value = generic_action + action = bound_floating_ip.change_protection(True) + request_mock.assert_called_with( - url="/floating_ips/14/actions/change_protection", method="POST", + url="/floating_ips/14/actions/change_protection", json={"delete": True}, ) @@ -123,9 +134,13 @@ def test_assign( generic_action, ): request_mock.return_value = generic_action + action = bound_floating_ip.assign(server) + request_mock.assert_called_with( - url="/floating_ips/14/actions/assign", method="POST", json={"server": 1} + method="POST", + url="/floating_ips/14/actions/assign", + json={"server": 1}, ) assert action.id == 1 assert action.progress == 0 @@ -137,9 +152,12 @@ def test_unassign( generic_action, ): request_mock.return_value = generic_action + action = bound_floating_ip.unassign() + request_mock.assert_called_with( - url="/floating_ips/14/actions/unassign", method="POST" + method="POST", + url="/floating_ips/14/actions/unassign", ) assert action.id == 1 assert action.progress == 0 @@ -151,10 +169,12 @@ def test_change_dns_ptr( generic_action, ): request_mock.return_value = generic_action + action = bound_floating_ip.change_dns_ptr("1.2.3.4", "server02.example.com") + request_mock.assert_called_with( - url="/floating_ips/14/actions/change_dns_ptr", method="POST", + url="/floating_ips/14/actions/change_dns_ptr", json={"ip": "1.2.3.4", "dns_ptr": "server02.example.com"}, ) assert action.id == 1 @@ -173,8 +193,13 @@ def test_get_by_id( floating_ip_response, ): request_mock.return_value = floating_ip_response + bound_floating_ip = floating_ips_client.get_by_id(1) - request_mock.assert_called_with(url="/floating_ips/1", method="GET") + + request_mock.assert_called_with( + method="GET", + url="/floating_ips/1", + ) assert bound_floating_ip._client is floating_ips_client assert bound_floating_ip.id == 4711 assert bound_floating_ip.description == "Web Frontend" @@ -186,9 +211,13 @@ def test_get_by_name( one_floating_ips_response, ): request_mock.return_value = one_floating_ips_response + bound_floating_ip = floating_ips_client.get_by_name("Web Frontend") + request_mock.assert_called_with( - url="/floating_ips", method="GET", params={"name": "Web Frontend"} + method="GET", + url="/floating_ips", + params={"name": "Web Frontend"}, ) assert bound_floating_ip._client is floating_ips_client assert bound_floating_ip.id == 4711 @@ -207,9 +236,13 @@ def test_get_list( params, ): request_mock.return_value = two_floating_ips_response + result = floating_ips_client.get_list(**params) + request_mock.assert_called_with( - url="/floating_ips", method="GET", params=params + method="GET", + url="/floating_ips", + params=params, ) bound_floating_ips = result.floating_ips @@ -237,12 +270,15 @@ def test_get_all( params, ): request_mock.return_value = two_floating_ips_response + bound_floating_ips = floating_ips_client.get_all(**params) params.update({"page": 1, "per_page": 50}) request_mock.assert_called_with( - url="/floating_ips", method="GET", params=params + method="GET", + url="/floating_ips", + params=params, ) assert len(bound_floating_ips) == 2 @@ -265,12 +301,14 @@ def test_create_with_location( floating_ip_response, ): request_mock.return_value = floating_ip_response + response = floating_ips_client.create( "ipv6", "Web Frontend", home_location=Location(name="location") ) + request_mock.assert_called_with( - url="/floating_ips", method="POST", + url="/floating_ips", json={ "description": "Web Frontend", "type": "ipv6", @@ -297,12 +335,14 @@ def test_create_with_server( floating_ip_create_response, ): request_mock.return_value = floating_ip_create_response + response = floating_ips_client.create( type="ipv6", description="Web Frontend", server=server ) + request_mock.assert_called_with( - url="/floating_ips", method="POST", + url="/floating_ips", json={"description": "Web Frontend", "type": "ipv6", "server": 1}, ) bound_floating_ip = response.floating_ip @@ -324,12 +364,14 @@ def test_create_with_name( floating_ip_create_response, ): request_mock.return_value = floating_ip_create_response + response = floating_ips_client.create( type="ipv6", description="Web Frontend", name="Web Frontend" ) + request_mock.assert_called_with( - url="/floating_ips", method="POST", + url="/floating_ips", json={ "description": "Web Frontend", "type": "ipv6", @@ -356,10 +398,12 @@ def test_get_actions( response_get_actions, ): request_mock.return_value = response_get_actions + actions = floating_ips_client.get_actions(floating_ip) + request_mock.assert_called_with( - url="/floating_ips/1/actions", method="GET", + url="/floating_ips/1/actions", params={"page": 1, "per_page": 50}, ) @@ -381,12 +425,14 @@ def test_update( response_update_floating_ip, ): request_mock.return_value = response_update_floating_ip + floating_ip = floating_ips_client.update( floating_ip, description="New description", name="New name" ) + request_mock.assert_called_with( - url="/floating_ips/1", method="PUT", + url="/floating_ips/1", json={"description": "New description", "name": "New name"}, ) @@ -405,10 +451,12 @@ def test_change_protection( generic_action, ): request_mock.return_value = generic_action + action = floating_ips_client.change_protection(floating_ip, True) + request_mock.assert_called_with( - url="/floating_ips/1/actions/change_protection", method="POST", + url="/floating_ips/1/actions/change_protection", json={"delete": True}, ) @@ -426,8 +474,13 @@ def test_delete( generic_action, ): request_mock.return_value = generic_action + delete_success = floating_ips_client.delete(floating_ip) - request_mock.assert_called_with(url="/floating_ips/1", method="DELETE") + + request_mock.assert_called_with( + method="DELETE", + url="/floating_ips/1", + ) assert delete_success is True @@ -450,9 +503,13 @@ def test_assign( generic_action, ): request_mock.return_value = generic_action + action = floating_ips_client.assign(floating_ip, server) + request_mock.assert_called_with( - url="/floating_ips/12/actions/assign", method="POST", json={"server": 1} + method="POST", + url="/floating_ips/12/actions/assign", + json={"server": 1}, ) assert action.id == 1 assert action.progress == 0 @@ -469,9 +526,12 @@ def test_unassign( generic_action, ): request_mock.return_value = generic_action + action = floating_ips_client.unassign(floating_ip) + request_mock.assert_called_with( - url="/floating_ips/12/actions/unassign", method="POST" + method="POST", + url="/floating_ips/12/actions/unassign", ) assert action.id == 1 assert action.progress == 0 @@ -488,12 +548,14 @@ def test_change_dns_ptr( generic_action, ): request_mock.return_value = generic_action + action = floating_ips_client.change_dns_ptr( floating_ip, "1.2.3.4", "server02.example.com" ) + request_mock.assert_called_with( - url="/floating_ips/12/actions/change_dns_ptr", method="POST", + url="/floating_ips/12/actions/change_dns_ptr", json={"ip": "1.2.3.4", "dns_ptr": "server02.example.com"}, ) assert action.id == 1 @@ -508,7 +570,10 @@ def test_actions_get_by_id( request_mock.return_value = {"action": response_get_actions["actions"][0]} action = floating_ips_client.actions.get_by_id(13) - request_mock.assert_called_with(url="/floating_ips/actions/13", method="GET") + request_mock.assert_called_with( + method="GET", + url="/floating_ips/actions/13", + ) assert isinstance(action, BoundAction) assert action._client == floating_ips_client._parent.actions @@ -522,11 +587,12 @@ def test_actions_get_list( response_get_actions, ): request_mock.return_value = response_get_actions + result = floating_ips_client.actions.get_list() request_mock.assert_called_with( - url="/floating_ips/actions", method="GET", + url="/floating_ips/actions", params={}, ) @@ -546,11 +612,12 @@ def test_actions_get_all( response_get_actions, ): request_mock.return_value = response_get_actions + actions = floating_ips_client.actions.get_all() request_mock.assert_called_with( - url="/floating_ips/actions", method="GET", + url="/floating_ips/actions", params={"page": 1, "per_page": 50}, ) diff --git a/tests/unit/images/test_client.py b/tests/unit/images/test_client.py index 14ea5334..384dce48 100644 --- a/tests/unit/images/test_client.py +++ b/tests/unit/images/test_client.py @@ -59,9 +59,13 @@ def test_get_actions_list( params, ): request_mock.return_value = response_get_actions + result = bound_image.get_actions_list(**params) + request_mock.assert_called_with( - url="/images/14/actions", method="GET", params=params + method="GET", + url="/images/14/actions", + params=params, ) actions = result.actions @@ -83,12 +87,15 @@ def test_get_actions( params, ): request_mock.return_value = response_get_actions + actions = bound_image.get_actions(**params) params.update({"page": 1, "per_page": 50}) request_mock.assert_called_with( - url="/images/14/actions", method="GET", params=params + method="GET", + url="/images/14/actions", + params=params, ) assert len(actions) == 1 @@ -104,12 +111,14 @@ def test_update( response_update_image, ): request_mock.return_value = response_update_image + image = bound_image.update( description="My new Image description", type="snapshot", labels={} ) + request_mock.assert_called_with( - url="/images/14", method="PUT", + url="/images/14", json={ "description": "My new Image description", "type": "snapshot", @@ -127,8 +136,13 @@ def test_delete( generic_action, ): request_mock.return_value = generic_action + delete_success = bound_image.delete() - request_mock.assert_called_with(url="/images/14", method="DELETE") + + request_mock.assert_called_with( + method="DELETE", + url="/images/14", + ) assert delete_success is True @@ -139,10 +153,12 @@ def test_change_protection( generic_action, ): request_mock.return_value = generic_action + action = bound_image.change_protection(True) + request_mock.assert_called_with( - url="/images/14/actions/change_protection", method="POST", + url="/images/14/actions/change_protection", json={"delete": True}, ) @@ -162,8 +178,13 @@ def test_get_by_id( image_response, ): request_mock.return_value = image_response + image = images_client.get_by_id(1) - request_mock.assert_called_with(url="/images/1", method="GET") + + request_mock.assert_called_with( + method="GET", + url="/images/1", + ) assert image._client is images_client assert image.id == 4711 assert image.name == "ubuntu-20.04" @@ -193,8 +214,14 @@ def test_get_list( params, ): request_mock.return_value = two_images_response + result = images_client.get_list(**params) - request_mock.assert_called_with(url="/images", method="GET", params=params) + + request_mock.assert_called_with( + method="GET", + url="/images", + params=params, + ) images = result.images assert result.meta is not None @@ -234,11 +261,16 @@ def test_get_all( params, ): request_mock.return_value = two_images_response + images = images_client.get_all(**params) params.update({"page": 1, "per_page": 50}) - request_mock.assert_called_with(url="/images", method="GET", params=params) + request_mock.assert_called_with( + method="GET", + url="/images", + params=params, + ) assert len(images) == 2 @@ -260,12 +292,17 @@ def test_get_by_name( one_images_response, ): request_mock.return_value = one_images_response + with pytest.deprecated_call(): image = images_client.get_by_name("ubuntu-20.04") params = {"name": "ubuntu-20.04"} - request_mock.assert_called_with(url="/images", method="GET", params=params) + request_mock.assert_called_with( + method="GET", + url="/images", + params=params, + ) assert image._client is images_client assert image.id == 4711 @@ -278,11 +315,16 @@ def test_get_by_name_and_architecture( one_images_response, ): request_mock.return_value = one_images_response + image = images_client.get_by_name_and_architecture("ubuntu-20.04", "x86") params = {"name": "ubuntu-20.04", "architecture": ["x86"]} - request_mock.assert_called_with(url="/images", method="GET", params=params) + request_mock.assert_called_with( + method="GET", + url="/images", + params=params, + ) assert image._client is images_client assert image.id == 4711 @@ -300,9 +342,13 @@ def test_get_actions_list( response_get_actions, ): request_mock.return_value = response_get_actions + result = images_client.get_actions_list(image) + request_mock.assert_called_with( - url="/images/1/actions", method="GET", params={} + method="GET", + url="/images/1/actions", + params={}, ) actions = result.actions @@ -326,12 +372,14 @@ def test_update( response_update_image, ): request_mock.return_value = response_update_image + image = images_client.update( image, description="My new Image description", type="snapshot", labels={} ) + request_mock.assert_called_with( - url="/images/1", method="PUT", + url="/images/1", json={ "description": "My new Image description", "type": "snapshot", @@ -353,10 +401,12 @@ def test_change_protection( generic_action, ): request_mock.return_value = generic_action + action = images_client.change_protection(image, True) + request_mock.assert_called_with( - url="/images/1/actions/change_protection", method="POST", + url="/images/1/actions/change_protection", json={"delete": True}, ) @@ -374,8 +424,13 @@ def test_delete( generic_action, ): request_mock.return_value = generic_action + delete_success = images_client.delete(image) - request_mock.assert_called_with(url="/images/1", method="DELETE") + + request_mock.assert_called_with( + method="DELETE", + url="/images/1", + ) assert delete_success is True @@ -388,7 +443,10 @@ def test_actions_get_by_id( request_mock.return_value = {"action": response_get_actions["actions"][0]} action = images_client.actions.get_by_id(13) - request_mock.assert_called_with(url="/images/actions/13", method="GET") + request_mock.assert_called_with( + method="GET", + url="/images/actions/13", + ) assert isinstance(action, BoundAction) assert action._client == images_client._parent.actions @@ -402,11 +460,12 @@ def test_actions_get_list( response_get_actions, ): request_mock.return_value = response_get_actions + result = images_client.actions.get_list() request_mock.assert_called_with( - url="/images/actions", method="GET", + url="/images/actions", params={}, ) @@ -426,11 +485,12 @@ def test_actions_get_all( response_get_actions, ): request_mock.return_value = response_get_actions + actions = images_client.actions.get_all() request_mock.assert_called_with( - url="/images/actions", method="GET", + url="/images/actions", params={"page": 1, "per_page": 50}, ) diff --git a/tests/unit/isos/test_client.py b/tests/unit/isos/test_client.py index 2f57f170..3735f26d 100644 --- a/tests/unit/isos/test_client.py +++ b/tests/unit/isos/test_client.py @@ -47,8 +47,13 @@ def test_get_by_id( iso_response, ): request_mock.return_value = iso_response + iso = isos_client.get_by_id(1) - request_mock.assert_called_with(url="/isos/1", method="GET") + + request_mock.assert_called_with( + method="GET", + url="/isos/1", + ) assert iso._client is isos_client assert iso.id == 4711 assert iso.name == "FreeBSD-11.0-RELEASE-amd64-dvd1" @@ -69,8 +74,14 @@ def test_get_list( params, ): request_mock.return_value = two_isos_response + result = isos_client.get_list(**params) - request_mock.assert_called_with(url="/isos", method="GET", params=params) + + request_mock.assert_called_with( + method="GET", + url="/isos", + params=params, + ) isos = result.isos assert result.meta is not None @@ -99,11 +110,16 @@ def test_get_all( params, ): request_mock.return_value = two_isos_response + isos = isos_client.get_all(**params) params.update({"page": 1, "per_page": 50}) - request_mock.assert_called_with(url="/isos", method="GET", params=params) + request_mock.assert_called_with( + method="GET", + url="/isos", + params=params, + ) assert len(isos) == 2 @@ -125,11 +141,16 @@ def test_get_by_name( one_isos_response, ): request_mock.return_value = one_isos_response + iso = isos_client.get_by_name("FreeBSD-11.0-RELEASE-amd64-dvd1") params = {"name": "FreeBSD-11.0-RELEASE-amd64-dvd1"} - request_mock.assert_called_with(url="/isos", method="GET", params=params) + request_mock.assert_called_with( + method="GET", + url="/isos", + params=params, + ) assert iso._client is isos_client assert iso.id == 4711 diff --git a/tests/unit/load_balancer_types/test_client.py b/tests/unit/load_balancer_types/test_client.py index 96e65e9a..c9f356dc 100644 --- a/tests/unit/load_balancer_types/test_client.py +++ b/tests/unit/load_balancer_types/test_client.py @@ -20,8 +20,13 @@ def test_get_by_id( load_balancer_type_response, ): request_mock.return_value = load_balancer_type_response + load_balancer_type = load_balancer_types_client.get_by_id(1) - request_mock.assert_called_with(url="/load_balancer_types/1", method="GET") + + request_mock.assert_called_with( + method="GET", + url="/load_balancer_types/1", + ) assert load_balancer_type._client is load_balancer_types_client assert load_balancer_type.id == 1 assert load_balancer_type.name == "LB11" @@ -37,9 +42,13 @@ def test_get_list( params, ): request_mock.return_value = two_load_balancer_types_response + result = load_balancer_types_client.get_list(**params) + request_mock.assert_called_with( - url="/load_balancer_types", method="GET", params=params + method="GET", + url="/load_balancer_types", + params=params, ) load_balancer_types = result.load_balancer_types @@ -67,12 +76,15 @@ def test_get_all( params, ): request_mock.return_value = two_load_balancer_types_response + load_balancer_types = load_balancer_types_client.get_all(**params) params.update({"page": 1, "per_page": 50}) request_mock.assert_called_with( - url="/load_balancer_types", method="GET", params=params + method="GET", + url="/load_balancer_types", + params=params, ) assert len(load_balancer_types) == 2 @@ -95,12 +107,15 @@ def test_get_by_name( one_load_balancer_types_response, ): request_mock.return_value = one_load_balancer_types_response + load_balancer_type = load_balancer_types_client.get_by_name("LB21") params = {"name": "LB21"} request_mock.assert_called_with( - url="/load_balancer_types", method="GET", params=params + method="GET", + url="/load_balancer_types", + params=params, ) assert load_balancer_type._client is load_balancer_types_client diff --git a/tests/unit/load_balancers/test_client.py b/tests/unit/load_balancers/test_client.py index a2bc4388..a41a2c3b 100644 --- a/tests/unit/load_balancers/test_client.py +++ b/tests/unit/load_balancers/test_client.py @@ -46,9 +46,13 @@ def test_get_actions_list( params, ): request_mock.return_value = response_get_actions + result = bound_load_balancer.get_actions_list(**params) + request_mock.assert_called_with( - url="/load_balancers/14/actions", method="GET", params=params + method="GET", + url="/load_balancers/14/actions", + params=params, ) actions = result.actions @@ -70,12 +74,15 @@ def test_get_actions( params, ): request_mock.return_value = response_get_actions + actions = bound_load_balancer.get_actions(**params) params.update({"page": 1, "per_page": 50}) request_mock.assert_called_with( - url="/load_balancers/14/actions", method="GET", params=params + method="GET", + url="/load_balancers/14/actions", + params=params, ) assert len(actions) == 1 @@ -91,10 +98,12 @@ def test_update( response_update_load_balancer, ): request_mock.return_value = response_update_load_balancer + load_balancer = bound_load_balancer.update(name="new-name", labels={}) + request_mock.assert_called_with( - url="/load_balancers/14", method="PUT", + url="/load_balancers/14", json={"name": "new-name", "labels": {}}, ) @@ -108,8 +117,13 @@ def test_delete( generic_action, ): request_mock.return_value = generic_action + delete_success = bound_load_balancer.delete() - request_mock.assert_called_with(url="/load_balancers/14", method="DELETE") + + request_mock.assert_called_with( + method="DELETE", + url="/load_balancers/14", + ) assert delete_success is True @@ -120,14 +134,16 @@ def test_get_metrics( response_get_metrics, ): request_mock.return_value = response_get_metrics + response = bound_load_balancer.get_metrics( type=["requests_per_second"], start="2023-12-14T16:55:32+01:00", end="2023-12-14T16:55:32+01:00", ) + request_mock.assert_called_with( - url="/load_balancers/14/metrics", method="GET", + url="/load_balancers/14/metrics", params={ "type": "requests_per_second", "start": "2023-12-14T16:55:32+01:00", @@ -144,12 +160,14 @@ def test_add_service( response_add_service, ): request_mock.return_value = response_add_service + service = LoadBalancerService(listen_port=80, protocol="http") action = bound_load_balancer.add_service(service) + request_mock.assert_called_with( - json={"protocol": "http", "listen_port": 80}, - url="/load_balancers/14/actions/add_service", method="POST", + url="/load_balancers/14/actions/add_service", + json={"protocol": "http", "listen_port": 80}, ) assert action.id == 13 @@ -163,12 +181,14 @@ def test_delete_service( response_delete_service, ): request_mock.return_value = response_delete_service + service = LoadBalancerService(listen_port=12) action = bound_load_balancer.delete_service(service) + request_mock.assert_called_with( - json={"listen_port": 12}, - url="/load_balancers/14/actions/delete_service", method="POST", + url="/load_balancers/14/actions/delete_service", + json={"listen_port": 12}, ) assert action.id == 13 @@ -206,10 +226,14 @@ def test_add_target( params, ): request_mock.return_value = response_add_target + action = bound_load_balancer.add_target(target) params.update({"type": target.type}) + request_mock.assert_called_with( - url="/load_balancers/14/actions/add_target", method="POST", json=params + method="POST", + url="/load_balancers/14/actions/add_target", + json=params, ) assert action.id == 13 @@ -247,10 +271,14 @@ def test_remove_target( params, ): request_mock.return_value = response_remove_target + action = bound_load_balancer.remove_target(target) params.update({"type": target.type}) + request_mock.assert_called_with( - url="/load_balancers/14/actions/remove_target", method="POST", json=params + method="POST", + url="/load_balancers/14/actions/remove_target", + json=params, ) assert action.id == 13 @@ -264,13 +292,17 @@ def test_update_service( response_update_service, ): request_mock.return_value = response_update_service + new_health_check = LoadBalancerHealthCheck( protocol="http", port=13, interval=1, timeout=1, retries=1 ) service = LoadBalancerService(listen_port=12, health_check=new_health_check) action = bound_load_balancer.update_service(service) + request_mock.assert_called_with( + method="POST", + url="/load_balancers/14/actions/update_service", json={ "listen_port": 12, "health_check": { @@ -281,8 +313,6 @@ def test_update_service( "retries": 1, }, }, - url="/load_balancers/14/actions/update_service", - method="POST", ) assert action.id == 13 @@ -296,12 +326,14 @@ def test_change_algorithm( response_change_algorithm, ): request_mock.return_value = response_change_algorithm + algorithm = LoadBalancerAlgorithm(type="round_robin") action = bound_load_balancer.change_algorithm(algorithm) + request_mock.assert_called_with( - json={"type": "round_robin"}, - url="/load_balancers/14/actions/change_algorithm", method="POST", + url="/load_balancers/14/actions/change_algorithm", + json={"type": "round_robin"}, ) assert action.id == 13 @@ -315,13 +347,15 @@ def test_change_dns_ptr( response_change_reverse_dns_entry, ): request_mock.return_value = response_change_reverse_dns_entry + action = bound_load_balancer.change_dns_ptr( ip="1.2.3.4", dns_ptr="lb1.example.com" ) + request_mock.assert_called_with( - json={"dns_ptr": "lb1.example.com", "ip": "1.2.3.4"}, - url="/load_balancers/14/actions/change_dns_ptr", method="POST", + url="/load_balancers/14/actions/change_dns_ptr", + json={"dns_ptr": "lb1.example.com", "ip": "1.2.3.4"}, ) assert action.id == 13 @@ -335,11 +369,13 @@ def test_change_protection( response_change_protection, ): request_mock.return_value = response_change_protection + action = bound_load_balancer.change_protection(delete=True) + request_mock.assert_called_with( - json={"delete": True}, - url="/load_balancers/14/actions/change_protection", method="POST", + url="/load_balancers/14/actions/change_protection", + json={"delete": True}, ) assert action.id == 13 @@ -353,9 +389,12 @@ def test_enable_public_interface( response_enable_public_interface, ): request_mock.return_value = response_enable_public_interface + action = bound_load_balancer.enable_public_interface() + request_mock.assert_called_with( - url="/load_balancers/14/actions/enable_public_interface", method="POST" + method="POST", + url="/load_balancers/14/actions/enable_public_interface", ) assert action.id == 13 @@ -369,9 +408,12 @@ def test_disable_public_interface( response_disable_public_interface, ): request_mock.return_value = response_disable_public_interface + action = bound_load_balancer.disable_public_interface() + request_mock.assert_called_with( - url="/load_balancers/14/actions/disable_public_interface", method="POST" + method="POST", + url="/load_balancers/14/actions/disable_public_interface", ) assert action.id == 13 @@ -385,11 +427,13 @@ def test_attach_to_network( response_attach_load_balancer_to_network, ): request_mock.return_value = response_attach_load_balancer_to_network + action = bound_load_balancer.attach_to_network(Network(id=1)) + request_mock.assert_called_with( - json={"network": 1}, - url="/load_balancers/14/actions/attach_to_network", method="POST", + url="/load_balancers/14/actions/attach_to_network", + json={"network": 1}, ) assert action.id == 13 @@ -403,11 +447,13 @@ def test_detach_from_network( response_detach_from_network, ): request_mock.return_value = response_detach_from_network + action = bound_load_balancer.detach_from_network(Network(id=1)) + request_mock.assert_called_with( - json={"network": 1}, - url="/load_balancers/14/actions/detach_from_network", method="POST", + url="/load_balancers/14/actions/detach_from_network", + json={"network": 1}, ) assert action.id == 13 @@ -421,10 +467,12 @@ def test_change_type( generic_action, ): request_mock.return_value = generic_action + action = bound_load_balancer.change_type(LoadBalancerType(name="lb21")) + request_mock.assert_called_with( - url="/load_balancers/14/actions/change_type", method="POST", + url="/load_balancers/14/actions/change_type", json={"load_balancer_type": "lb21"}, ) @@ -444,8 +492,13 @@ def test_get_by_id( response_load_balancer, ): request_mock.return_value = response_load_balancer + bound_load_balancer = load_balancers_client.get_by_id(1) - request_mock.assert_called_with(url="/load_balancers/1", method="GET") + + request_mock.assert_called_with( + method="GET", + url="/load_balancers/1", + ) assert bound_load_balancer._client is load_balancers_client assert bound_load_balancer.id == 4711 assert bound_load_balancer.name == "Web Frontend" @@ -474,9 +527,13 @@ def test_get_list( params, ): request_mock.return_value = response_simple_load_balancers + result = load_balancers_client.get_list(**params) + request_mock.assert_called_with( - url="/load_balancers", method="GET", params=params + method="GET", + url="/load_balancers", + params=params, ) bound_load_balancers = result.load_balancers @@ -506,12 +563,15 @@ def test_get_all( params, ): request_mock.return_value = response_simple_load_balancers + bound_load_balancers = load_balancers_client.get_all(**params) params.update({"page": 1, "per_page": 50}) request_mock.assert_called_with( - url="/load_balancers", method="GET", params=params + method="GET", + url="/load_balancers", + params=params, ) assert len(bound_load_balancers) == 2 @@ -534,12 +594,15 @@ def test_get_by_name( response_simple_load_balancers, ): request_mock.return_value = response_simple_load_balancers + bound_load_balancer = load_balancers_client.get_by_name("Web Frontend") params = {"name": "Web Frontend"} request_mock.assert_called_with( - url="/load_balancers", method="GET", params=params + method="GET", + url="/load_balancers", + params=params, ) assert bound_load_balancer._client is load_balancers_client @@ -553,14 +616,16 @@ def test_create( response_create_load_balancer, ): request_mock.return_value = response_create_load_balancer + response = load_balancers_client.create( "my-balancer", load_balancer_type=LoadBalancerType(name="lb11"), location=Location(id=1), ) + request_mock.assert_called_with( - url="/load_balancers", method="POST", + url="/load_balancers", json={"name": "my-balancer", "load_balancer_type": "lb11", "location": 1}, ) @@ -582,12 +647,14 @@ def test_change_type_with_load_balancer_type_name( generic_action, ): request_mock.return_value = generic_action + action = load_balancers_client.change_type( load_balancer, LoadBalancerType(name="lb11") ) + request_mock.assert_called_with( - url="/load_balancers/1/actions/change_type", method="POST", + url="/load_balancers/1/actions/change_type", json={"load_balancer_type": "lb11"}, ) @@ -606,12 +673,14 @@ def test_change_type_with_load_balancer_type_id( generic_action, ): request_mock.return_value = generic_action + action = load_balancers_client.change_type( load_balancer, LoadBalancerType(id=1) ) + request_mock.assert_called_with( - url="/load_balancers/1/actions/change_type", method="POST", + url="/load_balancers/1/actions/change_type", json={"load_balancer_type": 1}, ) @@ -627,7 +696,10 @@ def test_actions_get_by_id( request_mock.return_value = {"action": response_get_actions["actions"][0]} action = load_balancers_client.actions.get_by_id(13) - request_mock.assert_called_with(url="/load_balancers/actions/13", method="GET") + request_mock.assert_called_with( + method="GET", + url="/load_balancers/actions/13", + ) assert isinstance(action, BoundAction) assert action._client == load_balancers_client._parent.actions @@ -641,11 +713,12 @@ def test_actions_get_list( response_get_actions, ): request_mock.return_value = response_get_actions + result = load_balancers_client.actions.get_list() request_mock.assert_called_with( - url="/load_balancers/actions", method="GET", + url="/load_balancers/actions", params={}, ) @@ -665,11 +738,12 @@ def test_actions_get_all( response_get_actions, ): request_mock.return_value = response_get_actions + actions = load_balancers_client.actions.get_all() request_mock.assert_called_with( - url="/load_balancers/actions", method="GET", + url="/load_balancers/actions", params={"page": 1, "per_page": 50}, ) diff --git a/tests/unit/locations/test_client.py b/tests/unit/locations/test_client.py index 9b1b643b..61150c42 100644 --- a/tests/unit/locations/test_client.py +++ b/tests/unit/locations/test_client.py @@ -20,8 +20,13 @@ def test_get_by_id( location_response, ): request_mock.return_value = location_response + location = locations_client.get_by_id(1) - request_mock.assert_called_with(url="/locations/1", method="GET") + + request_mock.assert_called_with( + method="GET", + url="/locations/1", + ) assert location._client is locations_client assert location.id == 1 assert location.name == "fsn1" @@ -38,8 +43,14 @@ def test_get_list( params, ): request_mock.return_value = two_locations_response + result = locations_client.get_list(**params) - request_mock.assert_called_with(url="/locations", method="GET", params=params) + + request_mock.assert_called_with( + method="GET", + url="/locations", + params=params, + ) locations = result.locations assert result.meta is not None @@ -68,11 +79,16 @@ def test_get_all( params, ): request_mock.return_value = two_locations_response + locations = locations_client.get_all(**params) params.update({"page": 1, "per_page": 50}) - request_mock.assert_called_with(url="/locations", method="GET", params=params) + request_mock.assert_called_with( + method="GET", + url="/locations", + params=params, + ) assert len(locations) == 2 @@ -96,11 +112,16 @@ def test_get_by_name( one_locations_response, ): request_mock.return_value = one_locations_response + location = locations_client.get_by_name("fsn1") params = {"name": "fsn1"} - request_mock.assert_called_with(url="/locations", method="GET", params=params) + request_mock.assert_called_with( + method="GET", + url="/locations", + params=params, + ) assert location._client is locations_client assert location.id == 1 diff --git a/tests/unit/networks/test_client.py b/tests/unit/networks/test_client.py index ae98f485..da2ee792 100644 --- a/tests/unit/networks/test_client.py +++ b/tests/unit/networks/test_client.py @@ -58,10 +58,12 @@ def test_get_actions( response_get_actions, ): request_mock.return_value = response_get_actions + actions = bound_network.get_actions(sort="id") + request_mock.assert_called_with( - url="/networks/14/actions", method="GET", + url="/networks/14/actions", params={"page": 1, "per_page": 50, "sort": "id"}, ) @@ -78,9 +80,13 @@ def test_update( response_update_network, ): request_mock.return_value = response_update_network + network = bound_network.update(name="new-name") + request_mock.assert_called_with( - url="/networks/14", method="PUT", json={"name": "new-name"} + method="PUT", + url="/networks/14", + json={"name": "new-name"}, ) assert network.id == 4711 @@ -93,8 +99,13 @@ def test_delete( generic_action, ): request_mock.return_value = generic_action + delete_success = bound_network.delete() - request_mock.assert_called_with(url="/networks/14", method="DELETE") + + request_mock.assert_called_with( + method="DELETE", + url="/networks/14", + ) assert delete_success is True @@ -105,10 +116,12 @@ def test_change_protection( generic_action, ): request_mock.return_value = generic_action + action = bound_network.change_protection(True) + request_mock.assert_called_with( - url="/networks/14/actions/change_protection", method="POST", + url="/networks/14/actions/change_protection", json={"delete": True}, ) @@ -122,15 +135,17 @@ def test_add_subnet( generic_action, ): request_mock.return_value = generic_action + subnet = NetworkSubnet( type=NetworkSubnet.TYPE_CLOUD, ip_range="10.0.1.0/24", network_zone="eu-central", ) action = bound_network.add_subnet(subnet) + request_mock.assert_called_with( - url="/networks/14/actions/add_subnet", method="POST", + url="/networks/14/actions/add_subnet", json={ "type": NetworkSubnet.TYPE_CLOUD, "ip_range": "10.0.1.0/24", @@ -148,11 +163,13 @@ def test_delete_subnet( generic_action, ): request_mock.return_value = generic_action + subnet = NetworkSubnet(ip_range="10.0.1.0/24") action = bound_network.delete_subnet(subnet) + request_mock.assert_called_with( - url="/networks/14/actions/delete_subnet", method="POST", + url="/networks/14/actions/delete_subnet", json={"ip_range": "10.0.1.0/24"}, ) @@ -166,11 +183,13 @@ def test_add_route( generic_action, ): request_mock.return_value = generic_action + route = NetworkRoute(destination="10.100.1.0/24", gateway="10.0.1.1") action = bound_network.add_route(route) + request_mock.assert_called_with( - url="/networks/14/actions/add_route", method="POST", + url="/networks/14/actions/add_route", json={"destination": "10.100.1.0/24", "gateway": "10.0.1.1"}, ) @@ -184,11 +203,13 @@ def test_delete_route( generic_action, ): request_mock.return_value = generic_action + route = NetworkRoute(destination="10.100.1.0/24", gateway="10.0.1.1") action = bound_network.delete_route(route) + request_mock.assert_called_with( - url="/networks/14/actions/delete_route", method="POST", + url="/networks/14/actions/delete_route", json={"destination": "10.100.1.0/24", "gateway": "10.0.1.1"}, ) @@ -202,10 +223,12 @@ def test_change_ip( generic_action, ): request_mock.return_value = generic_action + action = bound_network.change_ip_range("10.0.0.0/12") + request_mock.assert_called_with( - url="/networks/14/actions/change_ip_range", method="POST", + url="/networks/14/actions/change_ip_range", json={"ip_range": "10.0.0.0/12"}, ) @@ -246,8 +269,13 @@ def test_get_by_id( network_response, ): request_mock.return_value = network_response + bound_network = networks_client.get_by_id(1) - request_mock.assert_called_with(url="/networks/1", method="GET") + + request_mock.assert_called_with( + method="GET", + url="/networks/1", + ) assert bound_network._client is networks_client assert bound_network.id == 1 assert bound_network.name == "mynet" @@ -264,8 +292,14 @@ def test_get_list( params, ): request_mock.return_value = two_networks_response + result = networks_client.get_list(**params) - request_mock.assert_called_with(url="/networks", method="GET", params=params) + + request_mock.assert_called_with( + method="GET", + url="/networks", + params=params, + ) bound_networks = result.networks assert result.meta is not None @@ -292,11 +326,16 @@ def test_get_all( params, ): request_mock.return_value = two_networks_response + bound_networks = networks_client.get_all(**params) params.update({"page": 1, "per_page": 50}) - request_mock.assert_called_with(url="/networks", method="GET", params=params) + request_mock.assert_called_with( + method="GET", + url="/networks", + params=params, + ) assert len(bound_networks) == 2 @@ -318,11 +357,16 @@ def test_get_by_name( one_network_response, ): request_mock.return_value = one_network_response + bound_network = networks_client.get_by_name("mynet") params = {"name": "mynet"} - request_mock.assert_called_with(url="/networks", method="GET", params=params) + request_mock.assert_called_with( + method="GET", + url="/networks", + params=params, + ) assert bound_network._client is networks_client assert bound_network.id == 1 @@ -335,10 +379,12 @@ def test_create( network_create_response, ): request_mock.return_value = network_create_response + networks_client.create(name="mynet", ip_range="10.0.0.0/8") + request_mock.assert_called_with( - url="/networks", method="POST", + url="/networks", json={"name": "mynet", "ip_range": "10.0.0.0/8"}, ) @@ -354,9 +400,10 @@ def test_create_with_expose_routes_to_vswitch( networks_client.create( name="mynet", ip_range="10.0.0.0/8", expose_routes_to_vswitch=True ) + request_mock.assert_called_with( - url="/networks", method="POST", + url="/networks", json={ "name": "mynet", "ip_range": "10.0.0.0/8", @@ -372,12 +419,14 @@ def test_create_with_subnet( network_create_response, ): request_mock.return_value = network_create_response + networks_client.create( name="mynet", ip_range="10.0.0.0/8", subnets=[network_subnet] ) + request_mock.assert_called_with( - url="/networks", method="POST", + url="/networks", json={ "name": "mynet", "ip_range": "10.0.0.0/8", @@ -399,14 +448,16 @@ def test_create_with_subnet_vswitch( network_create_response, ): request_mock.return_value = network_create_response + network_subnet.type = NetworkSubnet.TYPE_VSWITCH network_subnet.vswitch_id = 1000 networks_client.create( name="mynet", ip_range="10.0.0.0/8", subnets=[network_subnet] ) + request_mock.assert_called_with( - url="/networks", method="POST", + url="/networks", json={ "name": "mynet", "ip_range": "10.0.0.0/8", @@ -429,12 +480,14 @@ def test_create_with_route( network_create_response, ): request_mock.return_value = network_create_response + networks_client.create( name="mynet", ip_range="10.0.0.0/8", routes=[network_route] ) + request_mock.assert_called_with( - url="/networks", method="POST", + url="/networks", json={ "name": "mynet", "ip_range": "10.0.0.0/8", @@ -458,9 +511,10 @@ def test_create_with_route_and_expose_routes_to_vswitch( routes=[network_route], expose_routes_to_vswitch=True, ) + request_mock.assert_called_with( - url="/networks", method="POST", + url="/networks", json={ "name": "mynet", "ip_range": "10.0.0.0/8", @@ -478,15 +532,17 @@ def test_create_with_route_and_subnet( network_create_response, ): request_mock.return_value = network_create_response + networks_client.create( name="mynet", ip_range="10.0.0.0/8", subnets=[network_subnet], routes=[network_route], ) + request_mock.assert_called_with( - url="/networks", method="POST", + url="/networks", json={ "name": "mynet", "ip_range": "10.0.0.0/8", @@ -512,9 +568,13 @@ def test_get_actions_list( response_get_actions, ): request_mock.return_value = response_get_actions + result = networks_client.get_actions_list(network, sort="id") + request_mock.assert_called_with( - url="/networks/1/actions", method="GET", params={"sort": "id"} + method="GET", + url="/networks/1/actions", + params={"sort": "id"}, ) actions = result.actions @@ -536,12 +596,14 @@ def test_update( response_update_network, ): request_mock.return_value = response_update_network + network = networks_client.update( network, name="new-name", expose_routes_to_vswitch=True ) + request_mock.assert_called_with( - url="/networks/1", method="PUT", + url="/networks/1", json={"name": "new-name", "expose_routes_to_vswitch": True}, ) @@ -560,10 +622,12 @@ def test_change_protection( generic_action, ): request_mock.return_value = generic_action + action = networks_client.change_protection(network, True) + request_mock.assert_called_with( - url="/networks/1/actions/change_protection", method="POST", + url="/networks/1/actions/change_protection", json={"delete": True}, ) @@ -581,8 +645,13 @@ def test_delete( generic_action, ): request_mock.return_value = generic_action + delete_success = networks_client.delete(network) - request_mock.assert_called_with(url="/networks/1", method="DELETE") + + request_mock.assert_called_with( + method="DELETE", + url="/networks/1", + ) assert delete_success is True @@ -600,9 +669,10 @@ def test_add_subnet( request_mock.return_value = generic_action action = networks_client.add_subnet(network, network_subnet) + request_mock.assert_called_with( - url="/networks/1/actions/add_subnet", method="POST", + url="/networks/1/actions/add_subnet", json={ "type": NetworkSubnet.TYPE_CLOUD, "ip_range": "10.0.1.0/24", @@ -627,9 +697,10 @@ def test_add_subnet_vswitch( request_mock.return_value = generic_action action = networks_client.add_subnet(network, network_vswitch_subnet) + request_mock.assert_called_with( - url="/networks/1/actions/add_subnet", method="POST", + url="/networks/1/actions/add_subnet", json={ "type": NetworkSubnet.TYPE_VSWITCH, "ip_range": "10.0.1.0/24", @@ -655,9 +726,10 @@ def test_delete_subnet( request_mock.return_value = generic_action action = networks_client.delete_subnet(network, network_subnet) + request_mock.assert_called_with( - url="/networks/1/actions/delete_subnet", method="POST", + url="/networks/1/actions/delete_subnet", json={"ip_range": "10.0.1.0/24"}, ) @@ -678,9 +750,10 @@ def test_add_route( request_mock.return_value = generic_action action = networks_client.add_route(network, network_route) + request_mock.assert_called_with( - url="/networks/1/actions/add_route", method="POST", + url="/networks/1/actions/add_route", json={"destination": "10.100.1.0/24", "gateway": "10.0.1.1"}, ) @@ -701,9 +774,10 @@ def test_delete_route( request_mock.return_value = generic_action action = networks_client.delete_route(network, network_route) + request_mock.assert_called_with( - url="/networks/1/actions/delete_route", method="POST", + url="/networks/1/actions/delete_route", json={"destination": "10.100.1.0/24", "gateway": "10.0.1.1"}, ) @@ -721,10 +795,12 @@ def test_change_ip_range( generic_action, ): request_mock.return_value = generic_action + action = networks_client.change_ip_range(network, "10.0.0.0/12") + request_mock.assert_called_with( - url="/networks/1/actions/change_ip_range", method="POST", + url="/networks/1/actions/change_ip_range", json={"ip_range": "10.0.0.0/12"}, ) @@ -740,7 +816,10 @@ def test_actions_get_by_id( request_mock.return_value = {"action": response_get_actions["actions"][0]} action = networks_client.actions.get_by_id(13) - request_mock.assert_called_with(url="/networks/actions/13", method="GET") + request_mock.assert_called_with( + method="GET", + url="/networks/actions/13", + ) assert isinstance(action, BoundAction) assert action._client == networks_client._parent.actions @@ -754,11 +833,12 @@ def test_actions_get_list( response_get_actions, ): request_mock.return_value = response_get_actions + result = networks_client.actions.get_list() request_mock.assert_called_with( - url="/networks/actions", method="GET", + url="/networks/actions", params={}, ) @@ -778,11 +858,12 @@ def test_actions_get_all( response_get_actions, ): request_mock.return_value = response_get_actions + actions = networks_client.actions.get_all() request_mock.assert_called_with( - url="/networks/actions", method="GET", + url="/networks/actions", params={"page": 1, "per_page": 50}, ) diff --git a/tests/unit/placement_groups/test_client.py b/tests/unit/placement_groups/test_client.py index 824c50bd..fc1f2d57 100644 --- a/tests/unit/placement_groups/test_client.py +++ b/tests/unit/placement_groups/test_client.py @@ -37,15 +37,17 @@ def test_update( placement_group_response, ): request_mock.return_value = placement_group_response + placement_group = bound_placement_group.update( name=placement_group_response["placement_group"]["name"], labels=placement_group_response["placement_group"]["labels"], ) + request_mock.assert_called_with( + method="PUT", url="/placement_groups/{placement_group_id}".format( placement_group_id=placement_group_response["placement_group"]["id"] ), - method="PUT", json={ "labels": placement_group_response["placement_group"]["labels"], "name": placement_group_response["placement_group"]["name"], @@ -60,7 +62,11 @@ def test_delete( bound_placement_group, ): delete_success = bound_placement_group.delete() - request_mock.assert_called_with(url="/placement_groups/897", method="DELETE") + + request_mock.assert_called_with( + method="DELETE", + url="/placement_groups/897", + ) assert delete_success is True @@ -77,14 +83,16 @@ def test_get_by_id( placement_group_response, ): request_mock.return_value = placement_group_response + placement_group = placement_groups_client.get_by_id( placement_group_response["placement_group"]["id"] ) + request_mock.assert_called_with( + method="GET", url="/placement_groups/{placement_group_id}".format( placement_group_id=placement_group_response["placement_group"]["id"] ), - method="GET", ) assert placement_group._client is placement_groups_client @@ -113,9 +121,13 @@ def test_get_list( params, ): request_mock.return_value = two_placement_groups_response + result = placement_groups_client.get_list(**params) + request_mock.assert_called_with( - url="/placement_groups", method="GET", params=params + method="GET", + url="/placement_groups", + params=params, ) placement_groups = result.placement_groups @@ -151,11 +163,15 @@ def test_get_all( params, ): request_mock.return_value = two_placement_groups_response + placement_groups = placement_groups_client.get_all(**params) params.update({"page": 1, "per_page": 50}) + request_mock.assert_called_with( - url="/placement_groups", method="GET", params=params + method="GET", + url="/placement_groups", + params=params, ) assert len(placement_groups) == len( @@ -176,13 +192,17 @@ def test_get_by_name( one_placement_group_response, ): request_mock.return_value = one_placement_group_response + placement_group = placement_groups_client.get_by_name( one_placement_group_response["placement_groups"][0]["name"] ) params = {"name": one_placement_group_response["placement_groups"][0]["name"]} + request_mock.assert_called_with( - url="/placement_groups", method="GET", params=params + method="GET", + url="/placement_groups", + params=params, ) check_variables( @@ -196,6 +216,7 @@ def test_create( response_create_placement_group, ): request_mock.return_value = response_create_placement_group + response = placement_groups_client.create( name=response_create_placement_group["placement_group"]["name"], type=response_create_placement_group["placement_group"]["type"], @@ -207,8 +228,11 @@ def test_create( "labels": response_create_placement_group["placement_group"]["labels"], "type": response_create_placement_group["placement_group"]["type"], } + request_mock.assert_called_with( - url="/placement_groups", method="POST", json=json + method="POST", + url="/placement_groups", + json=json, ) bound_placement_group = response.placement_group diff --git a/tests/unit/primary_ips/test_client.py b/tests/unit/primary_ips/test_client.py index 33b74669..b7b3c07c 100644 --- a/tests/unit/primary_ips/test_client.py +++ b/tests/unit/primary_ips/test_client.py @@ -47,10 +47,12 @@ def test_update( response_update_primary_ip, ): request_mock.return_value = response_update_primary_ip + primary_ip = bound_primary_ip.update(auto_delete=True, name="my-resource") + request_mock.assert_called_with( - url="/primary_ips/14", method="PUT", + url="/primary_ips/14", json={"auto_delete": True, "name": "my-resource"}, ) @@ -64,8 +66,13 @@ def test_delete( generic_action, ): request_mock.return_value = generic_action + delete_success = bound_primary_ip.delete() - request_mock.assert_called_with(url="/primary_ips/14", method="DELETE") + + request_mock.assert_called_with( + method="DELETE", + url="/primary_ips/14", + ) assert delete_success is True @@ -76,10 +83,12 @@ def test_change_protection( generic_action, ): request_mock.return_value = generic_action + action = bound_primary_ip.change_protection(True) + request_mock.assert_called_with( - url="/primary_ips/14/actions/change_protection", method="POST", + url="/primary_ips/14/actions/change_protection", json={"delete": True}, ) @@ -93,10 +102,12 @@ def test_assign( generic_action, ): request_mock.return_value = generic_action + action = bound_primary_ip.assign(assignee_id=12, assignee_type="server") + request_mock.assert_called_with( - url="/primary_ips/14/actions/assign", method="POST", + url="/primary_ips/14/actions/assign", json={"assignee_id": 12, "assignee_type": "server"}, ) assert action.id == 1 @@ -109,9 +120,12 @@ def test_unassign( generic_action, ): request_mock.return_value = generic_action + action = bound_primary_ip.unassign() + request_mock.assert_called_with( - url="/primary_ips/14/actions/unassign", method="POST" + method="POST", + url="/primary_ips/14/actions/unassign", ) assert action.id == 1 assert action.progress == 0 @@ -123,10 +137,12 @@ def test_change_dns_ptr( generic_action, ): request_mock.return_value = generic_action + action = bound_primary_ip.change_dns_ptr("1.2.3.4", "server02.example.com") + request_mock.assert_called_with( - url="/primary_ips/14/actions/change_dns_ptr", method="POST", + url="/primary_ips/14/actions/change_dns_ptr", json={"ip": "1.2.3.4", "dns_ptr": "server02.example.com"}, ) assert action.id == 1 @@ -145,8 +161,13 @@ def test_get_by_id( primary_ip_response, ): request_mock.return_value = primary_ip_response + bound_primary_ip = primary_ips_client.get_by_id(1) - request_mock.assert_called_with(url="/primary_ips/1", method="GET") + + request_mock.assert_called_with( + method="GET", + url="/primary_ips/1", + ) assert bound_primary_ip._client is primary_ips_client assert bound_primary_ip.id == 42 @@ -157,9 +178,13 @@ def test_get_by_name( one_primary_ips_response, ): request_mock.return_value = one_primary_ips_response + bound_primary_ip = primary_ips_client.get_by_name("my-resource") + request_mock.assert_called_with( - url="/primary_ips", method="GET", params={"name": "my-resource"} + method="GET", + url="/primary_ips", + params={"name": "my-resource"}, ) assert bound_primary_ip._client is primary_ips_client assert bound_primary_ip.id == 42 @@ -174,11 +199,16 @@ def test_get_all( params, ): request_mock.return_value = all_primary_ips_response + bound_primary_ips = primary_ips_client.get_all(**params) params.update({"page": 1, "per_page": 50}) - request_mock.assert_called_with(url="/primary_ips", method="GET", params=params) + request_mock.assert_called_with( + method="GET", + url="/primary_ips", + params=params, + ) assert len(bound_primary_ips) == 1 @@ -195,12 +225,14 @@ def test_create_with_datacenter( primary_ip_response, ): request_mock.return_value = primary_ip_response + response = primary_ips_client.create( type="ipv6", name="my-resource", datacenter=Datacenter(name="datacenter") ) + request_mock.assert_called_with( - url="/primary_ips", method="POST", + url="/primary_ips", json={ "name": "my-resource", "type": "ipv6", @@ -225,15 +257,17 @@ def test_create_with_assignee_id( primary_ip_create_response, ): request_mock.return_value = primary_ip_create_response + response = primary_ips_client.create( type="ipv6", name="my-ip", assignee_id=17, assignee_type="server", ) + request_mock.assert_called_with( - url="/primary_ips", method="POST", + url="/primary_ips", json={ "name": "my-ip", "type": "ipv6", @@ -262,12 +296,14 @@ def test_update( response_update_primary_ip, ): request_mock.return_value = response_update_primary_ip + primary_ip = primary_ips_client.update( primary_ip, auto_delete=True, name="my-resource" ) + request_mock.assert_called_with( - url="/primary_ips/1", method="PUT", + url="/primary_ips/1", json={"auto_delete": True, "name": "my-resource"}, ) @@ -286,10 +322,12 @@ def test_change_protection( generic_action, ): request_mock.return_value = generic_action + action = primary_ips_client.change_protection(primary_ip, True) + request_mock.assert_called_with( - url="/primary_ips/1/actions/change_protection", method="POST", + url="/primary_ips/1/actions/change_protection", json={"delete": True}, ) @@ -307,8 +345,13 @@ def test_delete( generic_action, ): request_mock.return_value = generic_action + delete_success = primary_ips_client.delete(primary_ip) - request_mock.assert_called_with(url="/primary_ips/1", method="DELETE") + + request_mock.assert_called_with( + method="DELETE", + url="/primary_ips/1", + ) assert delete_success is True @@ -329,10 +372,12 @@ def test_assign( generic_action, ): request_mock.return_value = generic_action + action = primary_ips_client.assign(primary_ip, assignee_id, assignee_type) + request_mock.assert_called_with( - url="/primary_ips/12/actions/assign", method="POST", + url="/primary_ips/12/actions/assign", json={"assignee_id": 1, "assignee_type": "server"}, ) assert action.id == 1 @@ -349,9 +394,12 @@ def test_unassign( generic_action, ): request_mock.return_value = generic_action + action = primary_ips_client.unassign(primary_ip) + request_mock.assert_called_with( - url="/primary_ips/12/actions/unassign", method="POST" + method="POST", + url="/primary_ips/12/actions/unassign", ) assert action.id == 1 assert action.progress == 0 @@ -367,12 +415,14 @@ def test_change_dns_ptr( generic_action, ): request_mock.return_value = generic_action + action = primary_ips_client.change_dns_ptr( primary_ip, "1.2.3.4", "server02.example.com" ) + request_mock.assert_called_with( - url="/primary_ips/12/actions/change_dns_ptr", method="POST", + url="/primary_ips/12/actions/change_dns_ptr", json={"ip": "1.2.3.4", "dns_ptr": "server02.example.com"}, ) assert action.id == 1 @@ -387,7 +437,10 @@ def test_actions_get_by_id( request_mock.return_value = {"action": response_get_actions["actions"][0]} action = primary_ips_client.actions.get_by_id(13) - request_mock.assert_called_with(url="/primary_ips/actions/13", method="GET") + request_mock.assert_called_with( + method="GET", + url="/primary_ips/actions/13", + ) assert isinstance(action, BoundAction) assert action._client == primary_ips_client._parent.actions @@ -401,11 +454,12 @@ def test_actions_get_list( response_get_actions, ): request_mock.return_value = response_get_actions + result = primary_ips_client.actions.get_list() request_mock.assert_called_with( - url="/primary_ips/actions", method="GET", + url="/primary_ips/actions", params={}, ) @@ -425,11 +479,12 @@ def test_actions_get_all( response_get_actions, ): request_mock.return_value = response_get_actions + actions = primary_ips_client.actions.get_all() request_mock.assert_called_with( - url="/primary_ips/actions", method="GET", + url="/primary_ips/actions", params={"page": 1, "per_page": 50}, ) diff --git a/tests/unit/server_types/test_client.py b/tests/unit/server_types/test_client.py index 92c9bef7..7917746f 100644 --- a/tests/unit/server_types/test_client.py +++ b/tests/unit/server_types/test_client.py @@ -52,8 +52,13 @@ def test_get_by_id( server_type_response, ): request_mock.return_value = server_type_response + server_type = server_types_client.get_by_id(1) - request_mock.assert_called_with(url="/server_types/1", method="GET") + + request_mock.assert_called_with( + method="GET", + url="/server_types/1", + ) assert server_type._client is server_types_client assert server_type.id == 1 assert server_type.name == "cx11" @@ -69,9 +74,13 @@ def test_get_list( params, ): request_mock.return_value = two_server_types_response + result = server_types_client.get_list(**params) + request_mock.assert_called_with( - url="/server_types", method="GET", params=params + method="GET", + url="/server_types", + params=params, ) server_types = result.server_types @@ -99,12 +108,15 @@ def test_get_all( params, ): request_mock.return_value = two_server_types_response + server_types = server_types_client.get_all(**params) params.update({"page": 1, "per_page": 50}) request_mock.assert_called_with( - url="/server_types", method="GET", params=params + method="GET", + url="/server_types", + params=params, ) assert len(server_types) == 2 @@ -127,12 +139,15 @@ def test_get_by_name( one_server_types_response, ): request_mock.return_value = one_server_types_response + server_type = server_types_client.get_by_name("cx11") params = {"name": "cx11"} request_mock.assert_called_with( - url="/server_types", method="GET", params=params + method="GET", + url="/server_types", + params=params, ) assert server_type._client is server_types_client diff --git a/tests/unit/servers/test_client.py b/tests/unit/servers/test_client.py index cb785b0c..7b496c51 100644 --- a/tests/unit/servers/test_client.py +++ b/tests/unit/servers/test_client.py @@ -143,9 +143,13 @@ def test_get_actions_list( params, ): request_mock.return_value = response_get_actions + result = bound_server.get_actions_list(**params) + request_mock.assert_called_with( - url="/servers/14/actions", method="GET", params=params + method="GET", + url="/servers/14/actions", + params=params, ) actions = result.actions @@ -169,12 +173,15 @@ def test_get_actions( params, ): request_mock.return_value = response_get_actions + actions = bound_server.get_actions(**params) params.update({"page": 1, "per_page": 50}) request_mock.assert_called_with( - url="/servers/14/actions", method="GET", params=params + method="GET", + url="/servers/14/actions", + params=params, ) assert len(actions) == 1 @@ -190,9 +197,13 @@ def test_update( response_update_server, ): request_mock.return_value = response_update_server + server = bound_server.update(name="new-name", labels={}) + request_mock.assert_called_with( - url="/servers/14", method="PUT", json={"name": "new-name", "labels": {}} + method="PUT", + url="/servers/14", + json={"name": "new-name", "labels": {}}, ) assert server.id == 14 @@ -205,8 +216,13 @@ def test_delete( generic_action, ): request_mock.return_value = generic_action + action = bound_server.delete() - request_mock.assert_called_with(url="/servers/14", method="DELETE") + + request_mock.assert_called_with( + method="DELETE", + url="/servers/14", + ) assert action.id == 1 assert action.progress == 0 @@ -218,14 +234,16 @@ def test_get_metrics( response_get_metrics, ): request_mock.return_value = response_get_metrics + response = bound_server.get_metrics( type=["cpu", "disk"], start="2023-12-14T17:40:00+01:00", end="2023-12-14T17:50:00+01:00", ) + request_mock.assert_called_with( - url="/servers/14/metrics", method="GET", + url="/servers/14/metrics", params={ "type": "cpu,disk", "start": "2023-12-14T17:40:00+01:00", @@ -244,9 +262,12 @@ def test_power_off( generic_action, ): request_mock.return_value = generic_action + action = bound_server.power_off() + request_mock.assert_called_with( - url="/servers/14/actions/poweroff", method="POST" + method="POST", + url="/servers/14/actions/poweroff", ) assert action.id == 1 @@ -259,9 +280,12 @@ def test_power_on( generic_action, ): request_mock.return_value = generic_action + action = bound_server.power_on() + request_mock.assert_called_with( - url="/servers/14/actions/poweron", method="POST" + method="POST", + url="/servers/14/actions/poweron", ) assert action.id == 1 @@ -274,8 +298,13 @@ def test_reboot( generic_action, ): request_mock.return_value = generic_action + action = bound_server.reboot() - request_mock.assert_called_with(url="/servers/14/actions/reboot", method="POST") + + request_mock.assert_called_with( + method="POST", + url="/servers/14/actions/reboot", + ) assert action.id == 1 assert action.progress == 0 @@ -287,8 +316,13 @@ def test_reset( generic_action, ): request_mock.return_value = generic_action + action = bound_server.reset() - request_mock.assert_called_with(url="/servers/14/actions/reset", method="POST") + + request_mock.assert_called_with( + method="POST", + url="/servers/14/actions/reset", + ) assert action.id == 1 assert action.progress == 0 @@ -300,9 +334,12 @@ def test_shutdown( generic_action, ): request_mock.return_value = generic_action + action = bound_server.shutdown() + request_mock.assert_called_with( - url="/servers/14/actions/shutdown", method="POST" + method="POST", + url="/servers/14/actions/shutdown", ) assert action.id == 1 @@ -315,9 +352,12 @@ def test_reset_password( response_server_reset_password, ): request_mock.return_value = response_server_reset_password + response = bound_server.reset_password() + request_mock.assert_called_with( - url="/servers/14/actions/reset_password", method="POST" + method="POST", + url="/servers/14/actions/reset_password", ) assert response.action.id == 1 @@ -331,10 +371,12 @@ def test_change_type( generic_action, ): request_mock.return_value = generic_action + action = bound_server.change_type(ServerType(name="cx11"), upgrade_disk=True) + request_mock.assert_called_with( - url="/servers/14/actions/change_type", method="POST", + url="/servers/14/actions/change_type", json={"server_type": "cx11", "upgrade_disk": True}, ) @@ -348,10 +390,12 @@ def test_enable_rescue( response_server_enable_rescue, ): request_mock.return_value = response_server_enable_rescue + response = bound_server.enable_rescue(type="linux64") + request_mock.assert_called_with( - url="/servers/14/actions/enable_rescue", method="POST", + url="/servers/14/actions/enable_rescue", json={"type": "linux64"}, ) @@ -366,9 +410,12 @@ def test_disable_rescue( generic_action, ): request_mock.return_value = generic_action + action = bound_server.disable_rescue() + request_mock.assert_called_with( - url="/servers/14/actions/disable_rescue", method="POST" + method="POST", + url="/servers/14/actions/disable_rescue", ) assert action.id == 1 @@ -381,10 +428,12 @@ def test_create_image( response_server_create_image, ): request_mock.return_value = response_server_create_image + response = bound_server.create_image(description="my image", type="snapshot") + request_mock.assert_called_with( - url="/servers/14/actions/create_image", method="POST", + url="/servers/14/actions/create_image", json={"description": "my image", "type": "snapshot"}, ) @@ -399,13 +448,15 @@ def test_rebuild( generic_action, ): request_mock.return_value = generic_action + response = bound_server.rebuild( Image(name="ubuntu-20.04"), return_response=True, ) + request_mock.assert_called_with( - url="/servers/14/actions/rebuild", method="POST", + url="/servers/14/actions/rebuild", json={"image": "ubuntu-20.04"}, ) @@ -420,9 +471,12 @@ def test_enable_backup( generic_action, ): request_mock.return_value = generic_action + action = bound_server.enable_backup() + request_mock.assert_called_with( - url="/servers/14/actions/enable_backup", method="POST" + method="POST", + url="/servers/14/actions/enable_backup", ) assert action.id == 1 @@ -435,9 +489,12 @@ def test_disable_backup( generic_action, ): request_mock.return_value = generic_action + action = bound_server.disable_backup() + request_mock.assert_called_with( - url="/servers/14/actions/disable_backup", method="POST" + method="POST", + url="/servers/14/actions/disable_backup", ) assert action.id == 1 @@ -450,10 +507,12 @@ def test_attach_iso( generic_action, ): request_mock.return_value = generic_action + action = bound_server.attach_iso(Iso(name="FreeBSD-11.0-RELEASE-amd64-dvd1")) + request_mock.assert_called_with( - url="/servers/14/actions/attach_iso", method="POST", + url="/servers/14/actions/attach_iso", json={"iso": "FreeBSD-11.0-RELEASE-amd64-dvd1"}, ) @@ -467,9 +526,12 @@ def test_detach_iso( generic_action, ): request_mock.return_value = generic_action + action = bound_server.detach_iso() + request_mock.assert_called_with( - url="/servers/14/actions/detach_iso", method="POST" + method="POST", + url="/servers/14/actions/detach_iso", ) assert action.id == 1 @@ -482,10 +544,12 @@ def test_change_dns_ptr( generic_action, ): request_mock.return_value = generic_action + action = bound_server.change_dns_ptr("1.2.3.4", "example.com") + request_mock.assert_called_with( - url="/servers/14/actions/change_dns_ptr", method="POST", + url="/servers/14/actions/change_dns_ptr", json={"ip": "1.2.3.4", "dns_ptr": "example.com"}, ) @@ -499,10 +563,12 @@ def test_change_protection( generic_action, ): request_mock.return_value = generic_action + action = bound_server.change_protection(True, True) + request_mock.assert_called_with( - url="/servers/14/actions/change_protection", method="POST", + url="/servers/14/actions/change_protection", json={"delete": True, "rebuild": True}, ) @@ -516,9 +582,12 @@ def test_request_console( response_server_request_console, ): request_mock.return_value = response_server_request_console + response = bound_server.request_console() + request_mock.assert_called_with( - url="/servers/14/actions/request_console", method="POST" + method="POST", + url="/servers/14/actions/request_console", ) assert response.action.id == 1 @@ -540,12 +609,14 @@ def test_attach_to_network( response_attach_to_network, ): request_mock.return_value = response_attach_to_network + action = bound_server.attach_to_network( network, "10.0.1.1", ["10.0.1.2", "10.0.1.3"] ) + request_mock.assert_called_with( - url="/servers/14/actions/attach_to_network", method="POST", + url="/servers/14/actions/attach_to_network", json={ "network": 4711, "ip": "10.0.1.1", @@ -568,10 +639,12 @@ def test_detach_from_network( response_detach_from_network, ): request_mock.return_value = response_detach_from_network + action = bound_server.detach_from_network(network) + request_mock.assert_called_with( - url="/servers/14/actions/detach_from_network", method="POST", + url="/servers/14/actions/detach_from_network", json={"network": 4711}, ) @@ -590,10 +663,12 @@ def test_change_alias_ips( response_change_alias_ips, ): request_mock.return_value = response_change_alias_ips + action = bound_server.change_alias_ips(network, ["10.0.1.2", "10.0.1.3"]) + request_mock.assert_called_with( - url="/servers/14/actions/change_alias_ips", method="POST", + url="/servers/14/actions/change_alias_ips", json={"network": 4711, "alias_ips": ["10.0.1.2", "10.0.1.3"]}, ) @@ -613,10 +688,12 @@ def test_add_to_placement_group( response_add_to_placement_group, ): request_mock.return_value = response_add_to_placement_group + action = bound_server.add_to_placement_group(placement_group) + request_mock.assert_called_with( - url="/servers/14/actions/add_to_placement_group", method="POST", + url="/servers/14/actions/add_to_placement_group", json={"placement_group": 897}, ) @@ -631,9 +708,12 @@ def test_remove_from_placement_group( response_remove_from_placement_group, ): request_mock.return_value = response_remove_from_placement_group + action = bound_server.remove_from_placement_group() + request_mock.assert_called_with( - url="/servers/14/actions/remove_from_placement_group", method="POST" + method="POST", + url="/servers/14/actions/remove_from_placement_group", ) assert action.id == 13 @@ -653,8 +733,13 @@ def test_get_by_id( response_simple_server, ): request_mock.return_value = response_simple_server + bound_server = servers_client.get_by_id(1) - request_mock.assert_called_with(url="/servers/1", method="GET") + + request_mock.assert_called_with( + method="GET", + url="/servers/1", + ) assert bound_server._client is servers_client assert bound_server.id == 1 assert bound_server.name == "my-server" @@ -675,8 +760,14 @@ def test_get_list( params, ): request_mock.return_value = response_simple_servers + result = servers_client.get_list(**params) - request_mock.assert_called_with(url="/servers", method="GET", params=params) + + request_mock.assert_called_with( + method="GET", + url="/servers", + params=params, + ) bound_servers = result.servers assert result.meta is not None @@ -705,11 +796,16 @@ def test_get_all( params, ): request_mock.return_value = response_simple_servers + bound_servers = servers_client.get_all(**params) params.update({"page": 1, "per_page": 50}) - request_mock.assert_called_with(url="/servers", method="GET", params=params) + request_mock.assert_called_with( + method="GET", + url="/servers", + params=params, + ) assert len(bound_servers) == 2 @@ -731,11 +827,16 @@ def test_get_by_name( response_simple_servers, ): request_mock.return_value = response_simple_servers + bound_server = servers_client.get_by_name("my-server") params = {"name": "my-server"} - request_mock.assert_called_with(url="/servers", method="GET", params=params) + request_mock.assert_called_with( + method="GET", + url="/servers", + params=params, + ) assert bound_server._client is servers_client assert bound_server.id == 1 @@ -748,15 +849,17 @@ def test_create_with_datacenter( response_create_simple_server, ): request_mock.return_value = response_create_simple_server + response = servers_client.create( "my-server", server_type=ServerType(name="cx11"), image=Image(id=4711), datacenter=Datacenter(id=1), ) + request_mock.assert_called_with( - url="/servers", method="POST", + url="/servers", json={ "name": "my-server", "server_type": "cx11", @@ -785,15 +888,17 @@ def test_create_with_location( response_create_simple_server, ): request_mock.return_value = response_create_simple_server + response = servers_client.create( "my-server", server_type=ServerType(name="cx11"), image=Image(name="ubuntu-20.04"), location=Location(name="fsn1"), ) + request_mock.assert_called_with( - url="/servers", method="POST", + url="/servers", json={ "name": "my-server", "server_type": "cx11", @@ -822,6 +927,7 @@ def test_create_with_volumes( response_create_simple_server, ): request_mock.return_value = response_create_simple_server + volumes = [Volume(id=1), BoundVolume(mock.MagicMock(), dict(id=2))] response = servers_client.create( "my-server", @@ -830,9 +936,10 @@ def test_create_with_volumes( volumes=volumes, start_after_create=False, ) + request_mock.assert_called_with( - url="/servers", method="POST", + url="/servers", json={ "name": "my-server", "server_type": "cx11", @@ -867,6 +974,7 @@ def test_create_with_networks( response_create_simple_server, ): request_mock.return_value = response_create_simple_server + networks = [Network(id=1), BoundNetwork(mock.MagicMock(), dict(id=2))] response = servers_client.create( "my-server", @@ -875,9 +983,10 @@ def test_create_with_networks( networks=networks, start_after_create=False, ) + request_mock.assert_called_with( - url="/servers", method="POST", + url="/servers", json={ "name": "my-server", "server_type": "cx11", @@ -912,6 +1021,7 @@ def test_create_with_firewalls( response_create_simple_server, ): request_mock.return_value = response_create_simple_server + firewalls = [Firewall(id=1), BoundFirewall(mock.MagicMock(), dict(id=2))] response = servers_client.create( "my-server", @@ -920,9 +1030,10 @@ def test_create_with_firewalls( firewalls=firewalls, start_after_create=False, ) + request_mock.assert_called_with( - url="/servers", method="POST", + url="/servers", json={ "name": "my-server", "server_type": "cx11", @@ -957,6 +1068,7 @@ def test_create_with_placement_group( response_create_simple_server, ): request_mock.return_value = response_create_simple_server + placement_group = PlacementGroup(id=1) response = servers_client.create( "my-server", @@ -967,8 +1079,8 @@ def test_create_with_placement_group( ) request_mock.assert_called_with( - url="/servers", method="POST", + url="/servers", json={ "name": "my-server", "server_type": "cx11", @@ -1007,9 +1119,13 @@ def test_get_actions_list( response_get_actions, ): request_mock.return_value = response_get_actions + result = servers_client.get_actions_list(server) + request_mock.assert_called_with( - url="/servers/1/actions", method="GET", params={} + method="GET", + url="/servers/1/actions", + params={}, ) actions = result.actions @@ -1033,9 +1149,13 @@ def test_update( response_update_server, ): request_mock.return_value = response_update_server + server = servers_client.update(server, name="new-name", labels={}) + request_mock.assert_called_with( - url="/servers/1", method="PUT", json={"name": "new-name", "labels": {}} + method="PUT", + url="/servers/1", + json={"name": "new-name", "labels": {}}, ) assert server.id == 14 @@ -1052,8 +1172,13 @@ def test_delete( generic_action, ): request_mock.return_value = generic_action + action = servers_client.delete(server) - request_mock.assert_called_with(url="/servers/1", method="DELETE") + + request_mock.assert_called_with( + method="DELETE", + url="/servers/1", + ) assert action.id == 1 assert action.progress == 0 @@ -1069,9 +1194,12 @@ def test_power_off( generic_action, ): request_mock.return_value = generic_action + action = servers_client.power_off(server) + request_mock.assert_called_with( - url="/servers/1/actions/poweroff", method="POST" + method="POST", + url="/servers/1/actions/poweroff", ) assert action.id == 1 @@ -1088,8 +1216,13 @@ def test_power_on( generic_action, ): request_mock.return_value = generic_action + action = servers_client.power_on(server) - request_mock.assert_called_with(url="/servers/1/actions/poweron", method="POST") + + request_mock.assert_called_with( + method="POST", + url="/servers/1/actions/poweron", + ) assert action.id == 1 assert action.progress == 0 @@ -1105,8 +1238,13 @@ def test_reboot( generic_action, ): request_mock.return_value = generic_action + action = servers_client.reboot(server) - request_mock.assert_called_with(url="/servers/1/actions/reboot", method="POST") + + request_mock.assert_called_with( + method="POST", + url="/servers/1/actions/reboot", + ) assert action.id == 1 assert action.progress == 0 @@ -1122,8 +1260,13 @@ def test_reset( generic_action, ): request_mock.return_value = generic_action + action = servers_client.reset(server) - request_mock.assert_called_with(url="/servers/1/actions/reset", method="POST") + + request_mock.assert_called_with( + method="POST", + url="/servers/1/actions/reset", + ) assert action.id == 1 assert action.progress == 0 @@ -1139,9 +1282,12 @@ def test_shutdown( generic_action, ): request_mock.return_value = generic_action + action = servers_client.shutdown(server) + request_mock.assert_called_with( - url="/servers/1/actions/shutdown", method="POST" + method="POST", + url="/servers/1/actions/shutdown", ) assert action.id == 1 @@ -1158,9 +1304,12 @@ def test_reset_password( response_server_reset_password, ): request_mock.return_value = response_server_reset_password + response = servers_client.reset_password(server) + request_mock.assert_called_with( - url="/servers/1/actions/reset_password", method="POST" + method="POST", + url="/servers/1/actions/reset_password", ) assert response.action.id == 1 @@ -1178,12 +1327,14 @@ def test_change_type_with_server_type_name( generic_action, ): request_mock.return_value = generic_action + action = servers_client.change_type( server, ServerType(name="cx11"), upgrade_disk=True ) + request_mock.assert_called_with( - url="/servers/1/actions/change_type", method="POST", + url="/servers/1/actions/change_type", json={"server_type": "cx11", "upgrade_disk": True}, ) @@ -1201,10 +1352,12 @@ def test_change_type_with_server_type_id( generic_action, ): request_mock.return_value = generic_action + action = servers_client.change_type(server, ServerType(id=1), upgrade_disk=True) + request_mock.assert_called_with( - url="/servers/1/actions/change_type", method="POST", + url="/servers/1/actions/change_type", json={"server_type": 1, "upgrade_disk": True}, ) @@ -1223,6 +1376,7 @@ def test_change_type_with_blank_server_type( with pytest.raises(ValueError) as e: servers_client.change_type(server, ServerType(), upgrade_disk=True) assert str(e.value) == "id or name must be set" + request_mock.assert_not_called() @pytest.mark.parametrize( @@ -1236,10 +1390,12 @@ def test_enable_rescue( response_server_enable_rescue, ): request_mock.return_value = response_server_enable_rescue + response = servers_client.enable_rescue(server, "linux64", [2323]) + request_mock.assert_called_with( - url="/servers/1/actions/enable_rescue", method="POST", + url="/servers/1/actions/enable_rescue", json={"type": "linux64", "ssh_keys": [2323]}, ) @@ -1258,9 +1414,12 @@ def test_disable_rescue( generic_action, ): request_mock.return_value = generic_action + action = servers_client.disable_rescue(server) + request_mock.assert_called_with( - url="/servers/1/actions/disable_rescue", method="POST" + method="POST", + url="/servers/1/actions/disable_rescue", ) assert action.id == 1 @@ -1277,12 +1436,14 @@ def test_create_image( response_server_create_image, ): request_mock.return_value = response_server_create_image + response = servers_client.create_image( server, description="my image", type="snapshot", labels={"key": "value"} ) + request_mock.assert_called_with( - url="/servers/1/actions/create_image", method="POST", + url="/servers/1/actions/create_image", json={ "description": "my image", "type": "snapshot", @@ -1305,14 +1466,16 @@ def test_rebuild( generic_action, ): request_mock.return_value = generic_action + response = servers_client.rebuild( server, Image(name="ubuntu-20.04"), return_response=True, ) + request_mock.assert_called_with( - url="/servers/1/actions/rebuild", method="POST", + url="/servers/1/actions/rebuild", json={"image": "ubuntu-20.04"}, ) @@ -1331,9 +1494,12 @@ def test_enable_backup( generic_action, ): request_mock.return_value = generic_action + action = servers_client.enable_backup(server) + request_mock.assert_called_with( - url="/servers/1/actions/enable_backup", method="POST" + method="POST", + url="/servers/1/actions/enable_backup", ) assert action.id == 1 @@ -1350,9 +1516,12 @@ def test_disable_backup( generic_action, ): request_mock.return_value = generic_action + action = servers_client.disable_backup(server) + request_mock.assert_called_with( - url="/servers/1/actions/disable_backup", method="POST" + method="POST", + url="/servers/1/actions/disable_backup", ) assert action.id == 1 @@ -1369,12 +1538,14 @@ def test_attach_iso( generic_action, ): request_mock.return_value = generic_action + action = servers_client.attach_iso( server, Iso(name="FreeBSD-11.0-RELEASE-amd64-dvd1") ) + request_mock.assert_called_with( - url="/servers/1/actions/attach_iso", method="POST", + url="/servers/1/actions/attach_iso", json={"iso": "FreeBSD-11.0-RELEASE-amd64-dvd1"}, ) @@ -1392,9 +1563,12 @@ def test_detach_iso( generic_action, ): request_mock.return_value = generic_action + action = servers_client.detach_iso(server) + request_mock.assert_called_with( - url="/servers/1/actions/detach_iso", method="POST" + method="POST", + url="/servers/1/actions/detach_iso", ) assert action.id == 1 @@ -1411,10 +1585,12 @@ def test_change_dns_ptr( generic_action, ): request_mock.return_value = generic_action + action = servers_client.change_dns_ptr(server, "1.2.3.4", "example.com") + request_mock.assert_called_with( - url="/servers/1/actions/change_dns_ptr", method="POST", + url="/servers/1/actions/change_dns_ptr", json={"ip": "1.2.3.4", "dns_ptr": "example.com"}, ) @@ -1432,10 +1608,12 @@ def test_change_protection( generic_action, ): request_mock.return_value = generic_action + action = servers_client.change_protection(server, True, True) + request_mock.assert_called_with( - url="/servers/1/actions/change_protection", method="POST", + url="/servers/1/actions/change_protection", json={"delete": True, "rebuild": True}, ) @@ -1453,9 +1631,12 @@ def test_request_console( response_server_request_console, ): request_mock.return_value = response_server_request_console + response = servers_client.request_console(server) + request_mock.assert_called_with( - url="/servers/1/actions/request_console", method="POST" + method="POST", + url="/servers/1/actions/request_console", ) assert response.action.id == 1 @@ -1481,12 +1662,14 @@ def test_attach_to_network( response_attach_to_network, ): request_mock.return_value = response_attach_to_network + action = servers_client.attach_to_network( server, network, "10.0.1.1", ["10.0.1.2", "10.0.1.3"] ) + request_mock.assert_called_with( - url="/servers/1/actions/attach_to_network", method="POST", + url="/servers/1/actions/attach_to_network", json={ "network": 4711, "ip": "10.0.1.1", @@ -1513,10 +1696,12 @@ def test_detach_from_network( response_detach_from_network, ): request_mock.return_value = response_detach_from_network + action = servers_client.detach_from_network(server, network) + request_mock.assert_called_with( - url="/servers/1/actions/detach_from_network", method="POST", + url="/servers/1/actions/detach_from_network", json={"network": 4711}, ) @@ -1539,12 +1724,14 @@ def test_change_alias_ips( response_change_alias_ips, ): request_mock.return_value = response_change_alias_ips + action = servers_client.change_alias_ips( server, network, ["10.0.1.2", "10.0.1.3"] ) + request_mock.assert_called_with( - url="/servers/1/actions/change_alias_ips", method="POST", + url="/servers/1/actions/change_alias_ips", json={"network": 4711, "alias_ips": ["10.0.1.2", "10.0.1.3"]}, ) @@ -1561,7 +1748,10 @@ def test_actions_get_by_id( request_mock.return_value = {"action": response_get_actions["actions"][0]} action = servers_client.actions.get_by_id(13) - request_mock.assert_called_with(url="/servers/actions/13", method="GET") + request_mock.assert_called_with( + method="GET", + url="/servers/actions/13", + ) assert isinstance(action, BoundAction) assert action._client == servers_client._parent.actions @@ -1575,11 +1765,12 @@ def test_actions_get_list( response_get_actions, ): request_mock.return_value = response_get_actions + result = servers_client.actions.get_list() request_mock.assert_called_with( - url="/servers/actions", method="GET", + url="/servers/actions", params={}, ) @@ -1599,11 +1790,12 @@ def test_actions_get_all( response_get_actions, ): request_mock.return_value = response_get_actions + actions = servers_client.actions.get_all() request_mock.assert_called_with( - url="/servers/actions", method="GET", + url="/servers/actions", params={"page": 1, "per_page": 50}, ) diff --git a/tests/unit/ssh_keys/test_client.py b/tests/unit/ssh_keys/test_client.py index 5bc90aee..24cf48f7 100644 --- a/tests/unit/ssh_keys/test_client.py +++ b/tests/unit/ssh_keys/test_client.py @@ -33,9 +33,13 @@ def test_update( response_update_ssh_key, ): request_mock.return_value = response_update_ssh_key + ssh_key = bound_ssh_key.update(name="New name") + request_mock.assert_called_with( - url="/ssh_keys/14", method="PUT", json={"name": "New name"} + method="PUT", + url="/ssh_keys/14", + json={"name": "New name"}, ) assert ssh_key.id == 2323 @@ -48,8 +52,13 @@ def test_delete( generic_action, ): request_mock.return_value = generic_action + delete_success = bound_ssh_key.delete() - request_mock.assert_called_with(url="/ssh_keys/14", method="DELETE") + + request_mock.assert_called_with( + method="DELETE", + url="/ssh_keys/14", + ) assert delete_success is True @@ -66,8 +75,13 @@ def test_get_by_id( ssh_key_response, ): request_mock.return_value = ssh_key_response + ssh_key = ssh_keys_client.get_by_id(1) - request_mock.assert_called_with(url="/ssh_keys/1", method="GET") + + request_mock.assert_called_with( + method="GET", + url="/ssh_keys/1", + ) assert ssh_key._client is ssh_keys_client assert ssh_key.id == 2323 assert ssh_key.name == "My ssh key" @@ -94,8 +108,14 @@ def test_get_list( params, ): request_mock.return_value = two_ssh_keys_response + result = ssh_keys_client.get_list(**params) - request_mock.assert_called_with(url="/ssh_keys", method="GET", params=params) + + request_mock.assert_called_with( + method="GET", + url="/ssh_keys", + params=params, + ) ssh_keys = result.ssh_keys assert len(ssh_keys) == 2 @@ -122,10 +142,16 @@ def test_get_all( params, ): request_mock.return_value = two_ssh_keys_response + ssh_keys = ssh_keys_client.get_all(**params) params.update({"page": 1, "per_page": 50}) - request_mock.assert_called_with(url="/ssh_keys", method="GET", params=params) + + request_mock.assert_called_with( + method="GET", + url="/ssh_keys", + params=params, + ) assert len(ssh_keys) == 2 @@ -147,10 +173,16 @@ def test_get_by_name( one_ssh_keys_response, ): request_mock.return_value = one_ssh_keys_response + ssh_keys = ssh_keys_client.get_by_name("SSH-Key") params = {"name": "SSH-Key"} - request_mock.assert_called_with(url="/ssh_keys", method="GET", params=params) + + request_mock.assert_called_with( + method="GET", + url="/ssh_keys", + params=params, + ) assert ssh_keys._client is ssh_keys_client assert ssh_keys.id == 2323 @@ -163,12 +195,18 @@ def test_get_by_fingerprint( one_ssh_keys_response, ): request_mock.return_value = one_ssh_keys_response + ssh_keys = ssh_keys_client.get_by_fingerprint( "b7:2f:30:a0:2f:6c:58:6c:21:04:58:61:ba:06:3b:2f" ) params = {"fingerprint": "b7:2f:30:a0:2f:6c:58:6c:21:04:58:61:ba:06:3b:2f"} - request_mock.assert_called_with(url="/ssh_keys", method="GET", params=params) + + request_mock.assert_called_with( + method="GET", + url="/ssh_keys", + params=params, + ) assert ssh_keys._client is ssh_keys_client assert ssh_keys.id == 2323 @@ -181,12 +219,14 @@ def test_create( ssh_key_response, ): request_mock.return_value = ssh_key_response + ssh_key = ssh_keys_client.create( name="My ssh key", public_key="ssh-rsa AAAjjk76kgf...Xt" ) + request_mock.assert_called_with( - url="/ssh_keys", method="POST", + url="/ssh_keys", json={"name": "My ssh key", "public_key": "ssh-rsa AAAjjk76kgf...Xt"}, ) @@ -204,9 +244,13 @@ def test_update( response_update_ssh_key, ): request_mock.return_value = response_update_ssh_key + ssh_key = ssh_keys_client.update(ssh_key, name="New name") + request_mock.assert_called_with( - url="/ssh_keys/1", method="PUT", json={"name": "New name"} + method="PUT", + url="/ssh_keys/1", + json={"name": "New name"}, ) assert ssh_key.id == 2323 @@ -223,7 +267,12 @@ def test_delete( generic_action, ): request_mock.return_value = generic_action + delete_success = ssh_keys_client.delete(ssh_key) - request_mock.assert_called_with(url="/ssh_keys/1", method="DELETE") + + request_mock.assert_called_with( + method="DELETE", + url="/ssh_keys/1", + ) assert delete_success is True diff --git a/tests/unit/volumes/test_client.py b/tests/unit/volumes/test_client.py index 1f5f7534..fc0bffa2 100644 --- a/tests/unit/volumes/test_client.py +++ b/tests/unit/volumes/test_client.py @@ -50,10 +50,12 @@ def test_get_actions( response_get_actions, ): request_mock.return_value = response_get_actions + actions = bound_volume.get_actions(sort="id") + request_mock.assert_called_with( - url="/volumes/14/actions", method="GET", + url="/volumes/14/actions", params={"page": 1, "per_page": 50, "sort": "id"}, ) @@ -70,9 +72,13 @@ def test_update( response_update_volume, ): request_mock.return_value = response_update_volume + volume = bound_volume.update(name="new-name") + request_mock.assert_called_with( - url="/volumes/14", method="PUT", json={"name": "new-name"} + method="PUT", + url="/volumes/14", + json={"name": "new-name"}, ) assert volume.id == 4711 @@ -85,8 +91,13 @@ def test_delete( generic_action, ): request_mock.return_value = generic_action + delete_success = bound_volume.delete() - request_mock.assert_called_with(url="/volumes/14", method="DELETE") + + request_mock.assert_called_with( + method="DELETE", + url="/volumes/14", + ) assert delete_success is True @@ -97,10 +108,12 @@ def test_change_protection( generic_action, ): request_mock.return_value = generic_action + action = bound_volume.change_protection(True) + request_mock.assert_called_with( - url="/volumes/14/actions/change_protection", method="POST", + url="/volumes/14/actions/change_protection", json={"delete": True}, ) @@ -118,9 +131,13 @@ def test_attach( generic_action, ): request_mock.return_value = generic_action + action = bound_volume.attach(server) + request_mock.assert_called_with( - url="/volumes/14/actions/attach", method="POST", json={"server": 1} + method="POST", + url="/volumes/14/actions/attach", + json={"server": 1}, ) assert action.id == 1 assert action.progress == 0 @@ -136,10 +153,12 @@ def test_attach_with_automount( generic_action, ): request_mock.return_value = generic_action + action = bound_volume.attach(server, False) + request_mock.assert_called_with( - url="/volumes/14/actions/attach", method="POST", + url="/volumes/14/actions/attach", json={"server": 1, "automount": False}, ) assert action.id == 1 @@ -152,8 +171,13 @@ def test_detach( generic_action, ): request_mock.return_value = generic_action + action = bound_volume.detach() - request_mock.assert_called_with(url="/volumes/14/actions/detach", method="POST") + + request_mock.assert_called_with( + method="POST", + url="/volumes/14/actions/detach", + ) assert action.id == 1 assert action.progress == 0 @@ -164,9 +188,13 @@ def test_resize( generic_action, ): request_mock.return_value = generic_action + action = bound_volume.resize(50) + request_mock.assert_called_with( - url="/volumes/14/actions/resize", method="POST", json={"size": 50} + method="POST", + url="/volumes/14/actions/resize", + json={"size": 50}, ) assert action.id == 1 assert action.progress == 0 @@ -184,8 +212,13 @@ def test_get_by_id( volume_response, ): request_mock.return_value = volume_response + bound_volume = volumes_client.get_by_id(1) - request_mock.assert_called_with(url="/volumes/1", method="GET") + + request_mock.assert_called_with( + method="GET", + url="/volumes/1", + ) assert bound_volume._client is volumes_client assert bound_volume.id == 1 assert bound_volume.name == "database-storage" @@ -202,8 +235,14 @@ def test_get_list( params, ): request_mock.return_value = two_volumes_response + result = volumes_client.get_list(**params) - request_mock.assert_called_with(url="/volumes", method="GET", params=params) + + request_mock.assert_called_with( + method="GET", + url="/volumes", + params=params, + ) bound_volumes = result.volumes assert result.meta is not None @@ -230,11 +269,16 @@ def test_get_all( params, ): request_mock.return_value = two_volumes_response + bound_volumes = volumes_client.get_all(**params) params.update({"page": 1, "per_page": 50}) - request_mock.assert_called_with(url="/volumes", method="GET", params=params) + request_mock.assert_called_with( + method="GET", + url="/volumes", + params=params, + ) assert len(bound_volumes) == 2 @@ -256,11 +300,16 @@ def test_get_by_name( one_volumes_response, ): request_mock.return_value = one_volumes_response + bound_volume = volumes_client.get_by_name("database-storage") params = {"name": "database-storage"} - request_mock.assert_called_with(url="/volumes", method="GET", params=params) + request_mock.assert_called_with( + method="GET", + url="/volumes", + params=params, + ) assert bound_volume._client is volumes_client assert bound_volume.id == 1 @@ -273,6 +322,7 @@ def test_create_with_location( volume_create_response, ): request_mock.return_value = volume_create_response + response = volumes_client.create( 100, "database-storage", @@ -280,9 +330,10 @@ def test_create_with_location( automount=False, format="xfs", ) + request_mock.assert_called_with( - url="/volumes", method="POST", + url="/volumes", json={ "name": "database-storage", "size": 100, @@ -314,12 +365,14 @@ def test_create_with_server( volume_create_response, ): request_mock.return_value = volume_create_response + volumes_client.create( 100, "database-storage", server=server, automount=False, format="xfs" ) + request_mock.assert_called_with( - url="/volumes", method="POST", + url="/volumes", json={ "name": "database-storage", "size": 100, @@ -339,6 +392,7 @@ def test_create_negative_size( -100, "database-storage", location=Location(name="location") ) assert str(e.value) == "size must be greater than 0" + request_mock.assert_not_called() @pytest.mark.parametrize( @@ -356,6 +410,7 @@ def test_create_wrong_location_server_combination( 100, "database-storage", location=location, server=server ) assert str(e.value) == "only one of server or location must be provided" + request_mock.assert_not_called() @pytest.mark.parametrize( @@ -369,9 +424,13 @@ def test_get_actions_list( response_get_actions, ): request_mock.return_value = response_get_actions + result = volumes_client.get_actions_list(volume, sort="id") + request_mock.assert_called_with( - url="/volumes/1/actions", method="GET", params={"sort": "id"} + method="GET", + url="/volumes/1/actions", + params={"sort": "id"}, ) actions = result.actions @@ -393,9 +452,13 @@ def test_update( response_update_volume, ): request_mock.return_value = response_update_volume + volume = volumes_client.update(volume, name="new-name") + request_mock.assert_called_with( - url="/volumes/1", method="PUT", json={"name": "new-name"} + method="PUT", + url="/volumes/1", + json={"name": "new-name"}, ) assert volume.id == 4711 @@ -412,10 +475,12 @@ def test_change_protection( generic_action, ): request_mock.return_value = generic_action + action = volumes_client.change_protection(volume, True) + request_mock.assert_called_with( - url="/volumes/1/actions/change_protection", method="POST", + url="/volumes/1/actions/change_protection", json={"delete": True}, ) @@ -433,8 +498,13 @@ def test_delete( generic_action, ): request_mock.return_value = generic_action + delete_success = volumes_client.delete(volume) - request_mock.assert_called_with(url="/volumes/1", method="DELETE") + + request_mock.assert_called_with( + method="DELETE", + url="/volumes/1", + ) assert delete_success is True @@ -457,9 +527,13 @@ def test_attach( generic_action, ): request_mock.return_value = generic_action + action = volumes_client.attach(volume, server) + request_mock.assert_called_with( - url="/volumes/12/actions/attach", method="POST", json={"server": 1} + method="POST", + url="/volumes/12/actions/attach", + json={"server": 1}, ) assert action.id == 1 assert action.progress == 0 @@ -475,8 +549,13 @@ def test_detach( generic_action, ): request_mock.return_value = generic_action + action = volumes_client.detach(volume) - request_mock.assert_called_with(url="/volumes/12/actions/detach", method="POST") + + request_mock.assert_called_with( + method="POST", + url="/volumes/12/actions/detach", + ) assert action.id == 1 assert action.progress == 0 @@ -491,9 +570,13 @@ def test_resize( generic_action, ): request_mock.return_value = generic_action + action = volumes_client.resize(volume, 50) + request_mock.assert_called_with( - url="/volumes/12/actions/resize", method="POST", json={"size": 50} + method="POST", + url="/volumes/12/actions/resize", + json={"size": 50}, ) assert action.id == 1 assert action.progress == 0 @@ -507,7 +590,10 @@ def test_actions_get_by_id( request_mock.return_value = {"action": response_get_actions["actions"][0]} action = volumes_client.actions.get_by_id(13) - request_mock.assert_called_with(url="/volumes/actions/13", method="GET") + request_mock.assert_called_with( + method="GET", + url="/volumes/actions/13", + ) assert isinstance(action, BoundAction) assert action._client == volumes_client._parent.actions @@ -521,11 +607,12 @@ def test_actions_get_list( response_get_actions, ): request_mock.return_value = response_get_actions + result = volumes_client.actions.get_list() request_mock.assert_called_with( - url="/volumes/actions", method="GET", + url="/volumes/actions", params={}, ) @@ -545,11 +632,12 @@ def test_actions_get_all( response_get_actions, ): request_mock.return_value = response_get_actions + actions = volumes_client.actions.get_all() request_mock.assert_called_with( - url="/volumes/actions", method="GET", + url="/volumes/actions", params={"page": 1, "per_page": 50}, )