diff --git a/tests/unit/actions/test_client.py b/tests/unit/actions/test_client.py index 389d06f7..e3c266b2 100644 --- a/tests/unit/actions/test_client.py +++ b/tests/unit/actions/test_client.py @@ -1,5 +1,6 @@ from __future__ import annotations +import inspect from unittest import mock import pytest @@ -12,9 +13,48 @@ BoundAction, ResourceActionsClient, ) +from hcloud.certificates import BoundCertificate, CertificatesClient +from hcloud.core import BoundModelBase, ResourceClientBase +from hcloud.firewalls import BoundFirewall, FirewallsClient +from hcloud.floating_ips import BoundFloatingIP, FloatingIPsClient +from hcloud.images import BoundImage, ImagesClient +from hcloud.load_balancers import BoundLoadBalancer, LoadBalancersClient +from hcloud.networks import BoundNetwork, NetworksClient +from hcloud.primary_ips import BoundPrimaryIP, PrimaryIPsClient +from hcloud.servers import BoundServer, ServersClient +from hcloud.volumes import BoundVolume, VolumesClient from ..conftest import assert_bound_action1, assert_bound_action2 +resources_with_actions: dict[str, tuple[ResourceClientBase, BoundModelBase]] = { + "certificates": (CertificatesClient, BoundCertificate), + "firewalls": (FirewallsClient, BoundFirewall), + "floating_ips": (FloatingIPsClient, BoundFloatingIP), + "images": (ImagesClient, BoundImage), + "load_balancers": (LoadBalancersClient, BoundLoadBalancer), + "networks": (NetworksClient, BoundNetwork), + "primary_ips": (PrimaryIPsClient, BoundPrimaryIP), + "servers": (ServersClient, BoundServer), + "volumes": (VolumesClient, BoundVolume), +} + + +def test_resources_with_actions(client: Client): + """ + Ensure that the list of resource clients above is up to date. + """ + members = inspect.getmembers( + client, + predicate=lambda p: isinstance(p, ResourceClientBase) and hasattr(p, "actions"), + ) + for name, member in members: + assert name in resources_with_actions + + resource_client_class, _ = resources_with_actions[name] + assert member.__class__ is resource_client_class + + assert len(members) == len(resources_with_actions) + class TestBoundAction: @pytest.fixture() @@ -90,48 +130,62 @@ def test_wait_until_finished_max_retries( class TestResourceActionsClient: + """ + //actions + //actions/ + """ + + @pytest.fixture(params=resources_with_actions.keys()) + def resource(self, request) -> str: + return request.param + @pytest.fixture() - def actions_client(self, client: Client): - return ResourceActionsClient(client, resource="/resource") + def resource_client(self, client: Client, resource: str) -> ResourceActionsClient: + """ + Extract the resource actions client from the client. + """ + return getattr(client, resource).actions def test_get_by_id( self, request_mock: mock.MagicMock, - actions_client: ActionsClient, + resource_client: ResourceActionsClient, + resource: str, action_response, ): request_mock.return_value = action_response - action = actions_client.get_by_id(1) + action = resource_client.get_by_id(1) request_mock.assert_called_with( method="GET", - url="/resource/actions/1", + url=f"/{resource}/actions/1", ) - assert_bound_action1(action, actions_client._parent.actions) + assert_bound_action1(action, resource_client._parent.actions) @pytest.mark.parametrize( "params", [ {}, - {"status": ["active"], "sort": ["status"], "page": 2, "per_page": 10}, + {"status": ["running"], "sort": ["status"], "page": 2, "per_page": 10}, ], ) def test_get_list( self, request_mock: mock.MagicMock, - actions_client: ActionsClient, + resource_client: ResourceActionsClient, + resource: str, action_list_response, params, ): request_mock.return_value = action_list_response - result = actions_client.get_list(**params) + result = resource_client.get_list(**params) request_mock.assert_called_with( method="GET", - url="/resource/actions", + url=f"/{resource}/actions", params=params, ) @@ -139,36 +193,199 @@ def test_get_list( actions = result.actions assert len(actions) == 2 - assert_bound_action1(actions[0], actions_client._parent.actions) - assert_bound_action2(actions[1], actions_client._parent.actions) + assert_bound_action1(actions[0], resource_client._parent.actions) + assert_bound_action2(actions[1], resource_client._parent.actions) - @pytest.mark.parametrize("params", [{}, {"status": ["active"], "sort": ["status"]}]) + @pytest.mark.parametrize( + "params", + [ + {}, + {"status": ["running"], "sort": ["status"]}, + ], + ) def test_get_all( self, request_mock: mock.MagicMock, - actions_client: ActionsClient, + resource_client: ResourceActionsClient, + resource: str, + action_list_response, + params, + ): + request_mock.return_value = action_list_response + + actions = resource_client.get_all(**params) + + request_mock.assert_called_with( + method="GET", + url=f"/{resource}/actions", + params={**params, "page": 1, "per_page": 50}, + ) + + assert len(actions) == 2 + assert_bound_action1(actions[0], resource_client._parent.actions) + assert_bound_action2(actions[1], resource_client._parent.actions) + + +class TestResourceObjectActionsClient: + """ + ///actions + """ + + @pytest.fixture(params=resources_with_actions.keys()) + def resource(self, request): + if request.param == "primary_ips": + pytest.skip("not implemented yet") + return request.param + + @pytest.fixture() + def resource_client(self, client: Client, resource: str) -> ResourceClientBase: + return getattr(client, resource) + + @pytest.mark.parametrize( + "params", + [ + {}, + {"status": ["running"], "sort": ["status"], "page": 2, "per_page": 10}, + ], + ) + def test_get_actions_list( + self, + request_mock: mock.MagicMock, + resource_client: ResourceClientBase, + resource: str, + action_list_response, + params, + ): + request_mock.return_value = action_list_response + + result = resource_client.get_actions_list(mock.MagicMock(id=1), **params) + + request_mock.assert_called_with( + method="GET", + url=f"/{resource}/1/actions", + params=params, + ) + + assert result.meta is not None + + actions = result.actions + assert len(actions) == 2 + assert_bound_action1(actions[0], resource_client._parent.actions) + assert_bound_action2(actions[1], resource_client._parent.actions) + + @pytest.mark.parametrize( + "params", + [ + {}, + {"status": ["running"], "sort": ["status"]}, + ], + ) + def test_get_actions( + self, + request_mock: mock.MagicMock, + resource_client: ResourceClientBase, + resource: str, action_list_response, params, ): request_mock.return_value = action_list_response - actions = actions_client.get_all(**params) + actions = resource_client.get_actions(mock.MagicMock(id=1), **params) request_mock.assert_called_with( method="GET", - url="/resource/actions", + url=f"/{resource}/1/actions", params={**params, "page": 1, "per_page": 50}, ) assert len(actions) == 2 - assert_bound_action1(actions[0], actions_client._parent.actions) - assert_bound_action2(actions[1], actions_client._parent.actions) + assert_bound_action1(actions[0], resource_client._parent.actions) + assert_bound_action2(actions[1], resource_client._parent.actions) + + +class TestBoundModelActions: + """ + ///actions + """ + + @pytest.fixture(params=resources_with_actions.keys()) + def resource(self, request): + if request.param == "primary_ips": + pytest.skip("not implemented yet") + return request.param + + @pytest.fixture() + def bound_model(self, client: Client, resource: str) -> ResourceClientBase: + _, bound_model_class = resources_with_actions[resource] + resource_client = getattr(client, resource) + return bound_model_class(resource_client, data={"id": 1}) + + @pytest.mark.parametrize( + "params", + [ + {}, + {"status": ["running"], "sort": ["status"], "page": 2, "per_page": 10}, + ], + ) + def test_get_actions_list( + self, + request_mock: mock.MagicMock, + bound_model: BoundModelBase, + resource: str, + action_list_response, + params, + ): + request_mock.return_value = action_list_response + + result = bound_model.get_actions_list(**params) + + request_mock.assert_called_with( + method="GET", + url=f"/{resource}/1/actions", + params=params, + ) + + assert result.meta is not None + + actions = result.actions + assert len(actions) == 2 + assert_bound_action1(actions[0], bound_model._client._parent.actions) + assert_bound_action2(actions[1], bound_model._client._parent.actions) + + @pytest.mark.parametrize( + "params", + [ + {}, + {"status": ["running"], "sort": ["status"]}, + ], + ) + def test_get_actions( + self, + request_mock: mock.MagicMock, + bound_model: BoundModelBase, + resource: str, + action_list_response, + params, + ): + request_mock.return_value = action_list_response + + actions = bound_model.get_actions(**params) + + request_mock.assert_called_with( + method="GET", + url=f"/{resource}/1/actions", + params={**params, "page": 1, "per_page": 50}, + ) + + assert len(actions) == 2 + assert_bound_action1(actions[0], bound_model._client._parent.actions) + assert_bound_action2(actions[1], bound_model._client._parent.actions) class TestActionsClient: @pytest.fixture() - def actions_client(self, client: Client): - return ActionsClient(client) + def actions_client(self, client: Client) -> ActionsClient: + return client.actions def test_get_by_id( self, @@ -184,13 +401,13 @@ def test_get_by_id( method="GET", url="/actions/1", ) - assert_bound_action1(action, actions_client._parent.actions) + assert_bound_action1(action, actions_client) @pytest.mark.parametrize( "params", [ {}, - {"status": ["active"], "sort": ["status"], "page": 2, "per_page": 10}, + {"status": ["running"], "sort": ["status"], "page": 2, "per_page": 10}, ], ) def test_get_list( @@ -215,10 +432,16 @@ def test_get_list( actions = result.actions assert len(actions) == 2 - assert_bound_action1(actions[0], actions_client._parent.actions) - assert_bound_action2(actions[1], actions_client._parent.actions) + assert_bound_action1(actions[0], actions_client) + assert_bound_action2(actions[1], actions_client) - @pytest.mark.parametrize("params", [{}, {"status": ["active"], "sort": ["status"]}]) + @pytest.mark.parametrize( + "params", + [ + {}, + {"status": ["running"], "sort": ["status"]}, + ], + ) def test_get_all( self, request_mock: mock.MagicMock, @@ -238,5 +461,5 @@ def test_get_all( ) assert len(actions) == 2 - assert_bound_action1(actions[0], actions_client._parent.actions) - assert_bound_action2(actions[1], actions_client._parent.actions) + assert_bound_action1(actions[0], actions_client) + assert_bound_action2(actions[1], actions_client) diff --git a/tests/unit/certificates/test_client.py b/tests/unit/certificates/test_client.py index 26434074..cd1c8a60 100644 --- a/tests/unit/certificates/test_client.py +++ b/tests/unit/certificates/test_client.py @@ -5,7 +5,6 @@ import pytest from hcloud import Client -from hcloud.actions import BoundAction from hcloud.certificates import ( BoundCertificate, Certificate, @@ -19,59 +18,6 @@ class TestBoundCertificate: def bound_certificate(self, client: Client): return BoundCertificate(client.certificates, data=dict(id=14)) - @pytest.mark.parametrize("params", [{"page": 1, "per_page": 10}, {}]) - def test_get_actions_list( - self, - request_mock: mock.MagicMock, - client: Client, - bound_certificate, - response_get_actions, - params, - ): - request_mock.return_value = response_get_actions - - result = bound_certificate.get_actions_list(**params) - - request_mock.assert_called_with( - method="GET", - url="/certificates/14/actions", - params=params, - ) - - actions = result.actions - assert result.meta is not None - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == client.actions - assert actions[0].id == 13 - assert actions[0].command == "change_protection" - - def test_get_actions( - self, - request_mock: mock.MagicMock, - client: Client, - bound_certificate, - 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( - method="GET", - url="/certificates/14/actions", - params=params, - ) - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == client.actions - assert actions[0].id == 13 - assert actions[0].command == "change_protection" - def test_bound_certificate_init(self, certificate_response): bound_certificate = BoundCertificate( client=mock.MagicMock(), data=certificate_response["certificate"] @@ -397,69 +343,3 @@ def test_retry_issuance( assert action.id == 14 assert action.command == "issue_certificate" - - def test_actions_get_by_id( - self, - request_mock: mock.MagicMock, - certificates_client: CertificatesClient, - response_get_actions, - ): - request_mock.return_value = {"action": response_get_actions["actions"][0]} - action = certificates_client.actions.get_by_id(13) - - request_mock.assert_called_with( - method="GET", - url="/certificates/actions/13", - ) - - assert isinstance(action, BoundAction) - assert action._client == certificates_client._parent.actions - assert action.id == 13 - assert action.command == "change_protection" - - def test_actions_get_list( - self, - request_mock: mock.MagicMock, - certificates_client: CertificatesClient, - response_get_actions, - ): - request_mock.return_value = response_get_actions - - result = certificates_client.actions.get_list() - - request_mock.assert_called_with( - method="GET", - url="/certificates/actions", - params={}, - ) - - actions = result.actions - assert result.meta is not None - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == certificates_client._parent.actions - assert actions[0].id == 13 - assert actions[0].command == "change_protection" - - def test_actions_get_all( - self, - request_mock: mock.MagicMock, - certificates_client: CertificatesClient, - response_get_actions, - ): - request_mock.return_value = response_get_actions - - actions = certificates_client.actions.get_all() - - request_mock.assert_called_with( - method="GET", - url="/certificates/actions", - params={"page": 1, "per_page": 50}, - ) - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == certificates_client._parent.actions - assert actions[0].id == 13 - assert actions[0].command == "change_protection" diff --git a/tests/unit/firewalls/test_client.py b/tests/unit/firewalls/test_client.py index 9c65a26b..78b66409 100644 --- a/tests/unit/firewalls/test_client.py +++ b/tests/unit/firewalls/test_client.py @@ -5,7 +5,6 @@ import pytest from hcloud import Client -from hcloud.actions import BoundAction from hcloud.firewalls import ( BoundFirewall, Firewall, @@ -72,63 +71,6 @@ def test_bound_firewall_init(self, firewall_response): ] assert firewall_out_rule.description == "allow http out" - @pytest.mark.parametrize( - "params", [{}, {"sort": ["created"], "page": 1, "per_page": 2}] - ) - def test_get_actions_list( - self, - request_mock: mock.MagicMock, - client: Client, - bound_firewall, - response_get_actions, - params, - ): - request_mock.return_value = response_get_actions - - result = bound_firewall.get_actions_list(**params) - - request_mock.assert_called_with( - method="GET", - url="/firewalls/1/actions", - params=params, - ) - - actions = result.actions - assert result.meta is not None - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == client.actions - assert actions[0].id == 13 - assert actions[0].command == "set_firewall_rules" - - @pytest.mark.parametrize("params", [{}, {"sort": ["created"]}]) - def test_get_actions( - self, - request_mock: mock.MagicMock, - client: Client, - bound_firewall, - response_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( - method="GET", - url="/firewalls/1/actions", - params=params, - ) - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == client.actions - assert actions[0].id == 13 - assert actions[0].command == "set_firewall_rules" - def test_update( self, request_mock: mock.MagicMock, @@ -379,36 +321,6 @@ def test_get_by_name( assert firewall.id == 38 assert firewall.name == "Corporate Intranet Protection" - @pytest.mark.parametrize( - "firewall", [Firewall(id=1), BoundFirewall(mock.MagicMock(), dict(id=1))] - ) - def test_get_actions_list( - self, - request_mock: mock.MagicMock, - firewalls_client: FirewallsClient, - firewall, - response_get_actions, - ): - request_mock.return_value = response_get_actions - - result = firewalls_client.get_actions_list(firewall) - - request_mock.assert_called_with( - method="GET", - url="/firewalls/1/actions", - params={}, - ) - - actions = result.actions - assert result.meta is not None - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - - assert actions[0]._client == firewalls_client._parent.actions - assert actions[0].id == 13 - assert actions[0].command == "set_firewall_rules" - def test_create( self, request_mock: mock.MagicMock, @@ -599,69 +511,3 @@ def test_remove_from_resources( assert actions[0].id == 13 assert actions[0].progress == 100 - - def test_actions_get_by_id( - self, - request_mock: mock.MagicMock, - firewalls_client: FirewallsClient, - response_get_actions, - ): - request_mock.return_value = {"action": response_get_actions["actions"][0]} - action = firewalls_client.actions.get_by_id(13) - - request_mock.assert_called_with( - method="GET", - url="/firewalls/actions/13", - ) - - assert isinstance(action, BoundAction) - assert action._client == firewalls_client._parent.actions - assert action.id == 13 - assert action.command == "set_firewall_rules" - - def test_actions_get_list( - self, - request_mock: mock.MagicMock, - firewalls_client: FirewallsClient, - response_get_actions, - ): - request_mock.return_value = response_get_actions - - result = firewalls_client.actions.get_list() - - request_mock.assert_called_with( - method="GET", - url="/firewalls/actions", - params={}, - ) - - actions = result.actions - assert result.meta is not None - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == firewalls_client._parent.actions - assert actions[0].id == 13 - assert actions[0].command == "set_firewall_rules" - - def test_actions_get_all( - self, - request_mock: mock.MagicMock, - firewalls_client: FirewallsClient, - response_get_actions, - ): - request_mock.return_value = response_get_actions - - actions = firewalls_client.actions.get_all() - - request_mock.assert_called_with( - method="GET", - url="/firewalls/actions", - params={"page": 1, "per_page": 50}, - ) - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == firewalls_client._parent.actions - assert actions[0].id == 13 - assert actions[0].command == "set_firewall_rules" diff --git a/tests/unit/floating_ips/test_client.py b/tests/unit/floating_ips/test_client.py index fc90419c..acd2b175 100644 --- a/tests/unit/floating_ips/test_client.py +++ b/tests/unit/floating_ips/test_client.py @@ -5,7 +5,6 @@ import pytest from hcloud import Client -from hcloud.actions import BoundAction from hcloud.floating_ips import BoundFloatingIP, FloatingIP, FloatingIPsClient from hcloud.locations import BoundLocation, Location from hcloud.servers import BoundServer, Server @@ -42,29 +41,6 @@ def test_bound_floating_ip_init(self, floating_ip_response): assert bound_floating_ip.home_location.latitude == 50.47612 assert bound_floating_ip.home_location.longitude == 12.370071 - def test_get_actions( - self, - request_mock: mock.MagicMock, - client: Client, - bound_floating_ip, - response_get_actions, - ): - request_mock.return_value = response_get_actions - - actions = bound_floating_ip.get_actions(sort="id") - - request_mock.assert_called_with( - method="GET", - url="/floating_ips/14/actions", - params={"sort": "id", "page": 1, "per_page": 50}, - ) - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == client.actions - assert actions[0].id == 13 - assert actions[0].command == "assign_floating_ip" - def test_update( self, request_mock: mock.MagicMock, @@ -387,33 +363,6 @@ def test_create_with_name( assert bound_floating_ip.name == "Web Frontend" assert action.id == 13 - @pytest.mark.parametrize( - "floating_ip", [FloatingIP(id=1), BoundFloatingIP(mock.MagicMock(), dict(id=1))] - ) - def test_get_actions( - self, - request_mock: mock.MagicMock, - floating_ips_client: FloatingIPsClient, - floating_ip, - response_get_actions, - ): - request_mock.return_value = response_get_actions - - actions = floating_ips_client.get_actions(floating_ip) - - request_mock.assert_called_with( - method="GET", - url="/floating_ips/1/actions", - params={"page": 1, "per_page": 50}, - ) - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - - assert actions[0]._client == floating_ips_client._parent.actions - assert actions[0].id == 13 - assert actions[0].command == "assign_floating_ip" - @pytest.mark.parametrize( "floating_ip", [FloatingIP(id=1), BoundFloatingIP(mock.MagicMock(), dict(id=1))] ) @@ -560,69 +509,3 @@ def test_change_dns_ptr( ) assert action.id == 1 assert action.progress == 0 - - def test_actions_get_by_id( - self, - request_mock: mock.MagicMock, - floating_ips_client: FloatingIPsClient, - response_get_actions, - ): - request_mock.return_value = {"action": response_get_actions["actions"][0]} - action = floating_ips_client.actions.get_by_id(13) - - request_mock.assert_called_with( - method="GET", - url="/floating_ips/actions/13", - ) - - assert isinstance(action, BoundAction) - assert action._client == floating_ips_client._parent.actions - assert action.id == 13 - assert action.command == "assign_floating_ip" - - def test_actions_get_list( - self, - request_mock: mock.MagicMock, - floating_ips_client: FloatingIPsClient, - response_get_actions, - ): - request_mock.return_value = response_get_actions - - result = floating_ips_client.actions.get_list() - - request_mock.assert_called_with( - method="GET", - url="/floating_ips/actions", - params={}, - ) - - actions = result.actions - assert result.meta is not None - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == floating_ips_client._parent.actions - assert actions[0].id == 13 - assert actions[0].command == "assign_floating_ip" - - def test_actions_get_all( - self, - request_mock: mock.MagicMock, - floating_ips_client: FloatingIPsClient, - response_get_actions, - ): - request_mock.return_value = response_get_actions - - actions = floating_ips_client.actions.get_all() - - request_mock.assert_called_with( - method="GET", - url="/floating_ips/actions", - params={"page": 1, "per_page": 50}, - ) - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == floating_ips_client._parent.actions - assert actions[0].id == 13 - assert actions[0].command == "assign_floating_ip" diff --git a/tests/unit/images/test_client.py b/tests/unit/images/test_client.py index 49fc76ac..bc927983 100644 --- a/tests/unit/images/test_client.py +++ b/tests/unit/images/test_client.py @@ -7,7 +7,6 @@ import pytest from hcloud import Client -from hcloud.actions import BoundAction from hcloud.images import BoundImage, Image, ImagesClient from hcloud.servers import BoundServer @@ -47,63 +46,6 @@ def test_bound_image_init(self, image_response): assert bound_image.bound_to.id == 1 assert bound_image.bound_to.complete is False - @pytest.mark.parametrize( - "params", [{}, {"sort": ["status"], "page": 1, "per_page": 2}] - ) - def test_get_actions_list( - self, - request_mock: mock.MagicMock, - client: Client, - bound_image, - response_get_actions, - params, - ): - request_mock.return_value = response_get_actions - - result = bound_image.get_actions_list(**params) - - request_mock.assert_called_with( - method="GET", - url="/images/14/actions", - params=params, - ) - - actions = result.actions - assert result.meta is not None - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == client.actions - assert actions[0].id == 13 - assert actions[0].command == "change_protection" - - @pytest.mark.parametrize("params", [{}, {"sort": ["status"]}]) - def test_get_actions( - self, - request_mock: mock.MagicMock, - client: Client, - bound_image, - response_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( - method="GET", - url="/images/14/actions", - params=params, - ) - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == client.actions - assert actions[0].id == 13 - assert actions[0].command == "change_protection" - def test_update( self, request_mock: mock.MagicMock, @@ -331,36 +273,6 @@ def test_get_by_name_and_architecture( assert image.name == "ubuntu-20.04" assert image.architecture == "x86" - @pytest.mark.parametrize( - "image", [Image(id=1), BoundImage(mock.MagicMock(), dict(id=1))] - ) - def test_get_actions_list( - self, - request_mock: mock.MagicMock, - images_client: ImagesClient, - image, - response_get_actions, - ): - request_mock.return_value = response_get_actions - - result = images_client.get_actions_list(image) - - request_mock.assert_called_with( - method="GET", - url="/images/1/actions", - params={}, - ) - - actions = result.actions - assert result.meta is not None - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - - assert actions[0]._client == images_client._parent.actions - assert actions[0].id == 13 - assert actions[0].command == "change_protection" - @pytest.mark.parametrize( "image", [Image(id=1), BoundImage(mock.MagicMock(), dict(id=1))] ) @@ -433,69 +345,3 @@ def test_delete( ) assert delete_success is True - - def test_actions_get_by_id( - self, - request_mock: mock.MagicMock, - images_client: ImagesClient, - response_get_actions, - ): - request_mock.return_value = {"action": response_get_actions["actions"][0]} - action = images_client.actions.get_by_id(13) - - request_mock.assert_called_with( - method="GET", - url="/images/actions/13", - ) - - assert isinstance(action, BoundAction) - assert action._client == images_client._parent.actions - assert action.id == 13 - assert action.command == "change_protection" - - def test_actions_get_list( - self, - request_mock: mock.MagicMock, - images_client: ImagesClient, - response_get_actions, - ): - request_mock.return_value = response_get_actions - - result = images_client.actions.get_list() - - request_mock.assert_called_with( - method="GET", - url="/images/actions", - params={}, - ) - - actions = result.actions - assert result.meta is not None - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == images_client._parent.actions - assert actions[0].id == 13 - assert actions[0].command == "change_protection" - - def test_actions_get_all( - self, - request_mock: mock.MagicMock, - images_client: ImagesClient, - response_get_actions, - ): - request_mock.return_value = response_get_actions - - actions = images_client.actions.get_all() - - request_mock.assert_called_with( - method="GET", - url="/images/actions", - params={"page": 1, "per_page": 50}, - ) - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == images_client._parent.actions - assert actions[0].id == 13 - assert actions[0].command == "change_protection" diff --git a/tests/unit/load_balancers/test_client.py b/tests/unit/load_balancers/test_client.py index ff60b88c..94e5fb63 100644 --- a/tests/unit/load_balancers/test_client.py +++ b/tests/unit/load_balancers/test_client.py @@ -5,7 +5,6 @@ import pytest from hcloud import Client -from hcloud.actions import BoundAction from hcloud.load_balancer_types import LoadBalancerType from hcloud.load_balancers import ( BoundLoadBalancer, @@ -36,61 +35,6 @@ def test_bound_load_balancer_init(self, response_load_balancer): assert bound_load_balancer.id == 4711 assert bound_load_balancer.name == "Web Frontend" - @pytest.mark.parametrize("params", [{"page": 1, "per_page": 10}, {}]) - def test_get_actions_list( - self, - request_mock: mock.MagicMock, - client: Client, - bound_load_balancer, - response_get_actions, - params, - ): - request_mock.return_value = response_get_actions - - result = bound_load_balancer.get_actions_list(**params) - - request_mock.assert_called_with( - method="GET", - url="/load_balancers/14/actions", - params=params, - ) - - actions = result.actions - assert result.meta is not None - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == client.actions - assert actions[0].id == 13 - assert actions[0].command == "change_protection" - - @pytest.mark.parametrize("params", [{}]) - def test_get_actions( - self, - request_mock: mock.MagicMock, - client: Client, - bound_load_balancer, - response_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( - method="GET", - url="/load_balancers/14/actions", - params=params, - ) - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == client.actions - assert actions[0].id == 13 - assert actions[0].command == "change_protection" - def test_update( self, request_mock: mock.MagicMock, @@ -686,69 +630,3 @@ def test_change_type_with_load_balancer_type_id( assert action.id == 1 assert action.progress == 0 - - def test_actions_get_by_id( - self, - request_mock: mock.MagicMock, - load_balancers_client: LoadBalancersClient, - response_get_actions, - ): - request_mock.return_value = {"action": response_get_actions["actions"][0]} - action = load_balancers_client.actions.get_by_id(13) - - request_mock.assert_called_with( - method="GET", - url="/load_balancers/actions/13", - ) - - assert isinstance(action, BoundAction) - assert action._client == load_balancers_client._parent.actions - assert action.id == 13 - assert action.command == "change_protection" - - def test_actions_get_list( - self, - request_mock: mock.MagicMock, - load_balancers_client: LoadBalancersClient, - response_get_actions, - ): - request_mock.return_value = response_get_actions - - result = load_balancers_client.actions.get_list() - - request_mock.assert_called_with( - method="GET", - url="/load_balancers/actions", - params={}, - ) - - actions = result.actions - assert result.meta is not None - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == load_balancers_client._parent.actions - assert actions[0].id == 13 - assert actions[0].command == "change_protection" - - def test_actions_get_all( - self, - request_mock: mock.MagicMock, - load_balancers_client: LoadBalancersClient, - response_get_actions, - ): - request_mock.return_value = response_get_actions - - actions = load_balancers_client.actions.get_all() - - request_mock.assert_called_with( - method="GET", - url="/load_balancers/actions", - params={"page": 1, "per_page": 50}, - ) - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == load_balancers_client._parent.actions - assert actions[0].id == 13 - assert actions[0].command == "change_protection" diff --git a/tests/unit/networks/test_client.py b/tests/unit/networks/test_client.py index c2985c9f..5b60983b 100644 --- a/tests/unit/networks/test_client.py +++ b/tests/unit/networks/test_client.py @@ -6,7 +6,6 @@ from dateutil.parser import isoparse from hcloud import Client -from hcloud.actions import BoundAction from hcloud.networks import ( BoundNetwork, Network, @@ -50,29 +49,6 @@ def test_bound_network_init(self, network_response): assert bound_network.routes[0].destination == "10.100.1.0/24" assert bound_network.routes[0].gateway == "10.0.1.1" - def test_get_actions( - self, - request_mock: mock.MagicMock, - client: Client, - bound_network, - response_get_actions, - ): - request_mock.return_value = response_get_actions - - actions = bound_network.get_actions(sort="id") - - request_mock.assert_called_with( - method="GET", - url="/networks/14/actions", - params={"page": 1, "per_page": 50, "sort": "id"}, - ) - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == client.actions - assert actions[0].id == 13 - assert actions[0].command == "add_subnet" - def test_update( self, request_mock: mock.MagicMock, @@ -557,34 +533,6 @@ def test_create_with_route_and_subnet( }, ) - @pytest.mark.parametrize( - "network", [Network(id=1), BoundNetwork(mock.MagicMock(), dict(id=1))] - ) - def test_get_actions_list( - self, - request_mock: mock.MagicMock, - networks_client: NetworksClient, - network, - response_get_actions, - ): - request_mock.return_value = response_get_actions - - result = networks_client.get_actions_list(network, sort="id") - - request_mock.assert_called_with( - method="GET", - url="/networks/1/actions", - params={"sort": "id"}, - ) - - actions = result.actions - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - - assert actions[0]._client == networks_client._parent.actions - assert actions[0].id == 13 - assert actions[0].command == "add_subnet" - @pytest.mark.parametrize( "network", [Network(id=1), BoundNetwork(mock.MagicMock(), dict(id=1))] ) @@ -806,69 +754,3 @@ def test_change_ip_range( assert action.id == 1 assert action.progress == 0 - - def test_actions_get_by_id( - self, - request_mock: mock.MagicMock, - networks_client: NetworksClient, - response_get_actions, - ): - request_mock.return_value = {"action": response_get_actions["actions"][0]} - action = networks_client.actions.get_by_id(13) - - request_mock.assert_called_with( - method="GET", - url="/networks/actions/13", - ) - - assert isinstance(action, BoundAction) - assert action._client == networks_client._parent.actions - assert action.id == 13 - assert action.command == "add_subnet" - - def test_actions_get_list( - self, - request_mock: mock.MagicMock, - networks_client: NetworksClient, - response_get_actions, - ): - request_mock.return_value = response_get_actions - - result = networks_client.actions.get_list() - - request_mock.assert_called_with( - method="GET", - url="/networks/actions", - params={}, - ) - - actions = result.actions - assert result.meta is not None - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == networks_client._parent.actions - assert actions[0].id == 13 - assert actions[0].command == "add_subnet" - - def test_actions_get_all( - self, - request_mock: mock.MagicMock, - networks_client: NetworksClient, - response_get_actions, - ): - request_mock.return_value = response_get_actions - - actions = networks_client.actions.get_all() - - request_mock.assert_called_with( - method="GET", - url="/networks/actions", - params={"page": 1, "per_page": 50}, - ) - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == networks_client._parent.actions - assert actions[0].id == 13 - assert actions[0].command == "add_subnet" diff --git a/tests/unit/primary_ips/test_client.py b/tests/unit/primary_ips/test_client.py index 6bec0e76..ee3f5b4d 100644 --- a/tests/unit/primary_ips/test_client.py +++ b/tests/unit/primary_ips/test_client.py @@ -5,7 +5,6 @@ import pytest from hcloud import Client -from hcloud.actions import BoundAction from hcloud.datacenters import BoundDatacenter, Datacenter from hcloud.primary_ips import BoundPrimaryIP, PrimaryIP, PrimaryIPsClient @@ -427,69 +426,3 @@ def test_change_dns_ptr( ) assert action.id == 1 assert action.progress == 0 - - def test_actions_get_by_id( - self, - request_mock: mock.MagicMock, - primary_ips_client: PrimaryIPsClient, - response_get_actions, - ): - request_mock.return_value = {"action": response_get_actions["actions"][0]} - action = primary_ips_client.actions.get_by_id(13) - - request_mock.assert_called_with( - method="GET", - url="/primary_ips/actions/13", - ) - - assert isinstance(action, BoundAction) - assert action._client == primary_ips_client._parent.actions - assert action.id == 13 - assert action.command == "assign_primary_ip" - - def test_actions_get_list( - self, - request_mock: mock.MagicMock, - primary_ips_client: PrimaryIPsClient, - response_get_actions, - ): - request_mock.return_value = response_get_actions - - result = primary_ips_client.actions.get_list() - - request_mock.assert_called_with( - method="GET", - url="/primary_ips/actions", - params={}, - ) - - actions = result.actions - assert result.meta is not None - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == primary_ips_client._parent.actions - assert actions[0].id == 13 - assert actions[0].command == "assign_primary_ip" - - def test_actions_get_all( - self, - request_mock: mock.MagicMock, - primary_ips_client: PrimaryIPsClient, - response_get_actions, - ): - request_mock.return_value = response_get_actions - - actions = primary_ips_client.actions.get_all() - - request_mock.assert_called_with( - method="GET", - url="/primary_ips/actions", - params={"page": 1, "per_page": 50}, - ) - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == primary_ips_client._parent.actions - assert actions[0].id == 13 - assert actions[0].command == "assign_primary_ip" diff --git a/tests/unit/servers/test_client.py b/tests/unit/servers/test_client.py index 43088dfb..423dc29b 100644 --- a/tests/unit/servers/test_client.py +++ b/tests/unit/servers/test_client.py @@ -122,74 +122,6 @@ def test_bound_server_init(self, response_full_server): assert bound_server.placement_group.name == "my Placement Group" assert bound_server.placement_group.complete is True - @pytest.mark.parametrize( - "params", - [ - { - "status": [Server.STATUS_RUNNING], - "sort": "status", - "page": 1, - "per_page": 10, - }, - {}, - ], - ) - def test_get_actions_list( - self, - request_mock: mock.MagicMock, - client: Client, - bound_server, - response_get_actions, - params, - ): - request_mock.return_value = response_get_actions - - result = bound_server.get_actions_list(**params) - - request_mock.assert_called_with( - method="GET", - url="/servers/14/actions", - params=params, - ) - - actions = result.actions - assert result.meta is not None - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == client.actions - assert actions[0].id == 13 - assert actions[0].command == "start_server" - - @pytest.mark.parametrize( - "params", [{"status": [Server.STATUS_RUNNING], "sort": "status"}, {}] - ) - def test_get_actions( - self, - request_mock: mock.MagicMock, - client: Client, - bound_server, - response_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( - method="GET", - url="/servers/14/actions", - params=params, - ) - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == client.actions - assert actions[0].id == 13 - assert actions[0].command == "start_server" - def test_update( self, request_mock: mock.MagicMock, @@ -1108,36 +1040,6 @@ def test_create_with_placement_group( assert next_actions[0].id == 13 - @pytest.mark.parametrize( - "server", [Server(id=1), BoundServer(mock.MagicMock(), dict(id=1))] - ) - def test_get_actions_list( - self, - request_mock: mock.MagicMock, - servers_client: ServersClient, - server, - response_get_actions, - ): - request_mock.return_value = response_get_actions - - result = servers_client.get_actions_list(server) - - request_mock.assert_called_with( - method="GET", - url="/servers/1/actions", - params={}, - ) - - actions = result.actions - assert result.meta is not None - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - - assert actions[0]._client == servers_client._parent.actions - assert actions[0].id == 13 - assert actions[0].command == "start_server" - @pytest.mark.parametrize( "server", [Server(id=1), BoundServer(mock.MagicMock(), dict(id=1))] ) @@ -1738,69 +1640,3 @@ def test_change_alias_ips( assert action.id == 1 assert action.progress == 0 assert action.command == "change_alias_ips" - - def test_actions_get_by_id( - self, - request_mock: mock.MagicMock, - servers_client: ServersClient, - response_get_actions, - ): - request_mock.return_value = {"action": response_get_actions["actions"][0]} - action = servers_client.actions.get_by_id(13) - - request_mock.assert_called_with( - method="GET", - url="/servers/actions/13", - ) - - assert isinstance(action, BoundAction) - assert action._client == servers_client._parent.actions - assert action.id == 13 - assert action.command == "start_server" - - def test_actions_get_list( - self, - request_mock: mock.MagicMock, - servers_client: ServersClient, - response_get_actions, - ): - request_mock.return_value = response_get_actions - - result = servers_client.actions.get_list() - - request_mock.assert_called_with( - method="GET", - url="/servers/actions", - params={}, - ) - - actions = result.actions - assert result.meta is not None - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == servers_client._parent.actions - assert actions[0].id == 13 - assert actions[0].command == "start_server" - - def test_actions_get_all( - self, - request_mock: mock.MagicMock, - servers_client: ServersClient, - response_get_actions, - ): - request_mock.return_value = response_get_actions - - actions = servers_client.actions.get_all() - - request_mock.assert_called_with( - method="GET", - url="/servers/actions", - params={"page": 1, "per_page": 50}, - ) - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == servers_client._parent.actions - assert actions[0].id == 13 - assert actions[0].command == "start_server" diff --git a/tests/unit/volumes/test_client.py b/tests/unit/volumes/test_client.py index e01ffe46..9a1d0b20 100644 --- a/tests/unit/volumes/test_client.py +++ b/tests/unit/volumes/test_client.py @@ -6,7 +6,6 @@ from dateutil.parser import isoparse from hcloud import Client -from hcloud.actions import BoundAction from hcloud.locations import BoundLocation, Location from hcloud.servers import BoundServer, Server from hcloud.volumes import BoundVolume, Volume, VolumesClient @@ -42,29 +41,6 @@ def test_bound_volume_init(self, volume_response): assert bound_volume.location.latitude == 50.47612 assert bound_volume.location.longitude == 12.370071 - def test_get_actions( - self, - request_mock: mock.MagicMock, - client: Client, - bound_volume, - response_get_actions, - ): - request_mock.return_value = response_get_actions - - actions = bound_volume.get_actions(sort="id") - - request_mock.assert_called_with( - method="GET", - url="/volumes/14/actions", - params={"page": 1, "per_page": 50, "sort": "id"}, - ) - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == client.actions - assert actions[0].id == 13 - assert actions[0].command == "attach_volume" - def test_update( self, request_mock: mock.MagicMock, @@ -413,34 +389,6 @@ def test_create_wrong_location_server_combination( request_mock.assert_not_called() - @pytest.mark.parametrize( - "volume", [Volume(id=1), BoundVolume(mock.MagicMock(), dict(id=1))] - ) - def test_get_actions_list( - self, - request_mock: mock.MagicMock, - volumes_client: VolumesClient, - volume, - response_get_actions, - ): - request_mock.return_value = response_get_actions - - result = volumes_client.get_actions_list(volume, sort="id") - - request_mock.assert_called_with( - method="GET", - url="/volumes/1/actions", - params={"sort": "id"}, - ) - - actions = result.actions - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - - assert actions[0]._client == volumes_client._parent.actions - assert actions[0].id == 13 - assert actions[0].command == "attach_volume" - @pytest.mark.parametrize( "volume", [Volume(id=1), BoundVolume(mock.MagicMock(), dict(id=1))] ) @@ -580,69 +528,3 @@ def test_resize( ) assert action.id == 1 assert action.progress == 0 - - def test_actions_get_by_id( - self, - request_mock: mock.MagicMock, - volumes_client: VolumesClient, - response_get_actions, - ): - request_mock.return_value = {"action": response_get_actions["actions"][0]} - action = volumes_client.actions.get_by_id(13) - - request_mock.assert_called_with( - method="GET", - url="/volumes/actions/13", - ) - - assert isinstance(action, BoundAction) - assert action._client == volumes_client._parent.actions - assert action.id == 13 - assert action.command == "attach_volume" - - def test_actions_get_list( - self, - request_mock: mock.MagicMock, - volumes_client: VolumesClient, - response_get_actions, - ): - request_mock.return_value = response_get_actions - - result = volumes_client.actions.get_list() - - request_mock.assert_called_with( - method="GET", - url="/volumes/actions", - params={}, - ) - - actions = result.actions - assert result.meta is not None - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == volumes_client._parent.actions - assert actions[0].id == 13 - assert actions[0].command == "attach_volume" - - def test_actions_get_all( - self, - request_mock: mock.MagicMock, - volumes_client: VolumesClient, - response_get_actions, - ): - request_mock.return_value = response_get_actions - - actions = volumes_client.actions.get_all() - - request_mock.assert_called_with( - method="GET", - url="/volumes/actions", - params={"page": 1, "per_page": 50}, - ) - - assert len(actions) == 1 - assert isinstance(actions[0], BoundAction) - assert actions[0]._client == volumes_client._parent.actions - assert actions[0].id == 13 - assert actions[0].command == "attach_volume"