From 9913377704c5c41a78d79cfe950ddb5fa690997c Mon Sep 17 00:00:00 2001 From: Jose Manuel Castano Date: Mon, 17 Feb 2025 08:14:20 +0100 Subject: [PATCH 1/6] Add tests into ServiceSubscriptions resource --- .../test_integration_service_subscriptions.py | 19 +++++++++++++++++++ threescale_api/resources.py | 6 +++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/tests/integration/test_integration_service_subscriptions.py b/tests/integration/test_integration_service_subscriptions.py index e2c9a5a..8ad9f22 100644 --- a/tests/integration/test_integration_service_subscriptions.py +++ b/tests/integration/test_integration_service_subscriptions.py @@ -14,3 +14,22 @@ def test_read_service_subscription(account, service_subscription, service_subscr resource = account.service_subscriptions.read(service_subscription.entity_id) asserts.assert_resource(resource) asserts.assert_resource_params(service_subscription,service_subscription_params) + + +def test_change_plan_service_subscription(account, account_plan, service_subscription): + asserts.assert_resource(account) + asserts.assert_resource(account_plan) + resource = account.service_subscriptions.change_plan(service_subscription.entity_id, + account_plan.entity_id) + asserts.assert_resource(resource) + + +# TODO: https://issues.redhat.com/browse/THREESCALE-11693 +def test_approve_service_subscription(account, service_subscription,service_subscription_params): + asserts.assert_resource(service_subscription) + service_subscription['state'] = 'pending' + account.service_subscriptions.update(service_subscription.entity_id, + service_subscription_params) + resource = account.service_subscriptions.approve(service_subscription.entity_id) + asserts.assert_resource(resource) + asserts.assert_resource_params(service_subscription, service_subscription_params) \ No newline at end of file diff --git a/threescale_api/resources.py b/threescale_api/resources.py index 8306e0e..8e8d946 100644 --- a/threescale_api/resources.py +++ b/threescale_api/resources.py @@ -286,15 +286,15 @@ def url(self) -> str: return self.parent.url + '/service_subscriptions' def approve(self, entity_id: int, **kwargs): - url = self.url + f"/{entity_id}/approve.json" + url = self.url + f"/{entity_id}/approve" response = self.rest.put(url=url, **kwargs) instance = utils.extract_response(response=response) return instance def change_plan(self, entity_id: int, plan_id: int, **kwargs): params = {"plan_id": plan_id} - url = self.url + f"/{entity_id}/change_plan.json" - response = self.rest.put(url=url, json=params, **kwargs) + url = self.url + f"/{entity_id}/change_plan" + response = self.rest.put(url=url, params=params) instance = utils.extract_response(response=response) return instance From d22f05689e23d3207d9c11b95c7f70b9d24ef00b Mon Sep 17 00:00:00 2001 From: Jose Manuel Castano Date: Tue, 25 Feb 2025 10:55:11 +0100 Subject: [PATCH 2/6] Modify test for Service Subscriptions --- .../test_integration_service_subscriptions.py | 12 +++--------- threescale_api/resources.py | 2 +- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/tests/integration/test_integration_service_subscriptions.py b/tests/integration/test_integration_service_subscriptions.py index 8ad9f22..411291a 100644 --- a/tests/integration/test_integration_service_subscriptions.py +++ b/tests/integration/test_integration_service_subscriptions.py @@ -1,5 +1,4 @@ - from tests.integration import asserts def test_list_service_subscriptions(account): @@ -15,21 +14,16 @@ def test_read_service_subscription(account, service_subscription, service_subscr asserts.assert_resource(resource) asserts.assert_resource_params(service_subscription,service_subscription_params) - -def test_change_plan_service_subscription(account, account_plan, service_subscription): +def test_change_plan_service_subscription(account, account_plan, service_plan, service_subscription): asserts.assert_resource(account) asserts.assert_resource(account_plan) - resource = account.service_subscriptions.change_plan(service_subscription.entity_id, - account_plan.entity_id) - asserts.assert_resource(resource) - + account.service_subscriptions.change_plan(service_subscription.entity_id, + service_plan.entity_id) # TODO: https://issues.redhat.com/browse/THREESCALE-11693 def test_approve_service_subscription(account, service_subscription,service_subscription_params): asserts.assert_resource(service_subscription) service_subscription['state'] = 'pending' - account.service_subscriptions.update(service_subscription.entity_id, - service_subscription_params) resource = account.service_subscriptions.approve(service_subscription.entity_id) asserts.assert_resource(resource) asserts.assert_resource_params(service_subscription, service_subscription_params) \ No newline at end of file diff --git a/threescale_api/resources.py b/threescale_api/resources.py index 8e8d946..cbad303 100644 --- a/threescale_api/resources.py +++ b/threescale_api/resources.py @@ -294,7 +294,7 @@ def approve(self, entity_id: int, **kwargs): def change_plan(self, entity_id: int, plan_id: int, **kwargs): params = {"plan_id": plan_id} url = self.url + f"/{entity_id}/change_plan" - response = self.rest.put(url=url, params=params) + response = self.rest.put(url=url, json=params, **kwargs) instance = utils.extract_response(response=response) return instance From caacdacba0862a6f5c1721bc4dfc80126098e990 Mon Sep 17 00:00:00 2001 From: Jose Manuel Castano Date: Wed, 5 Mar 2025 15:39:01 +0100 Subject: [PATCH 3/6] Update tests for Service Subscriptions, approve and change plan. --- tests/integration/conftest.py | 2 +- .../test_integration_service_subscriptions.py | 11 ++++++----- threescale_api/resources.py | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index ebc2147..5b3ebdf 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -152,7 +152,7 @@ def account_user(account,account_user_params) -> AccountUser: @pytest.fixture(scope='module') def service_plan_params() -> dict: suffix = get_suffix() - return {"name":f'test-{suffix}'} + return {"name":f'test-{suffix}', "approval_required":'True'} @pytest.fixture(scope='module') def service_plan(service, service_plan_params) -> ServicePlan: diff --git a/tests/integration/test_integration_service_subscriptions.py b/tests/integration/test_integration_service_subscriptions.py index 411291a..c05ea17 100644 --- a/tests/integration/test_integration_service_subscriptions.py +++ b/tests/integration/test_integration_service_subscriptions.py @@ -14,16 +14,17 @@ def test_read_service_subscription(account, service_subscription, service_subscr asserts.assert_resource(resource) asserts.assert_resource_params(service_subscription,service_subscription_params) -def test_change_plan_service_subscription(account, account_plan, service_plan, service_subscription): +def test_change_plan_service_subscription(account, account_plan, service_plan, + service_subscription): asserts.assert_resource(account) asserts.assert_resource(account_plan) + asserts.assert_resource(service_plan) account.service_subscriptions.change_plan(service_subscription.entity_id, service_plan.entity_id) -# TODO: https://issues.redhat.com/browse/THREESCALE-11693 -def test_approve_service_subscription(account, service_subscription,service_subscription_params): +def test_approve_service_subscription(account, service_subscription, service_plan): asserts.assert_resource(service_subscription) - service_subscription['state'] = 'pending' + asserts.assert_resource(account) + asserts.assert_resource(service_plan) resource = account.service_subscriptions.approve(service_subscription.entity_id) asserts.assert_resource(resource) - asserts.assert_resource_params(service_subscription, service_subscription_params) \ No newline at end of file diff --git a/threescale_api/resources.py b/threescale_api/resources.py index cbad303..357e9b5 100644 --- a/threescale_api/resources.py +++ b/threescale_api/resources.py @@ -288,7 +288,7 @@ def url(self) -> str: def approve(self, entity_id: int, **kwargs): url = self.url + f"/{entity_id}/approve" response = self.rest.put(url=url, **kwargs) - instance = utils.extract_response(response=response) + instance = self._create_instance(response=response) return instance def change_plan(self, entity_id: int, plan_id: int, **kwargs): From 9027664d7a173701ab9536f931f1f273bd03c4df Mon Sep 17 00:00:00 2001 From: Jose Manuel Castano Date: Thu, 6 Mar 2025 11:01:11 +0100 Subject: [PATCH 4/6] Fix bugs after PR review. --- tests/integration/test_integration_service_subscriptions.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/integration/test_integration_service_subscriptions.py b/tests/integration/test_integration_service_subscriptions.py index c05ea17..ee85a73 100644 --- a/tests/integration/test_integration_service_subscriptions.py +++ b/tests/integration/test_integration_service_subscriptions.py @@ -26,5 +26,6 @@ def test_approve_service_subscription(account, service_subscription, service_pla asserts.assert_resource(service_subscription) asserts.assert_resource(account) asserts.assert_resource(service_plan) - resource = account.service_subscriptions.approve(service_subscription.entity_id) + svc_subs_id = service_subscription.entity_id + resource = account.service_subscriptions.approve(svc_subs_id) asserts.assert_resource(resource) From 5e31794f2ad312af84fae1bd18cf60e712ad9e4b Mon Sep 17 00:00:00 2001 From: Jose Manuel Castano Date: Thu, 6 Mar 2025 11:10:59 +0100 Subject: [PATCH 5/6] Simplify test for approve service subscription after PR review. --- tests/integration/test_integration_service_subscriptions.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/integration/test_integration_service_subscriptions.py b/tests/integration/test_integration_service_subscriptions.py index ee85a73..5e07441 100644 --- a/tests/integration/test_integration_service_subscriptions.py +++ b/tests/integration/test_integration_service_subscriptions.py @@ -26,6 +26,5 @@ def test_approve_service_subscription(account, service_subscription, service_pla asserts.assert_resource(service_subscription) asserts.assert_resource(account) asserts.assert_resource(service_plan) - svc_subs_id = service_subscription.entity_id - resource = account.service_subscriptions.approve(svc_subs_id) + resource = service_subscription.approve() asserts.assert_resource(resource) From 4a9f2b53391c461f4b87e118611d11ca0faa07a4 Mon Sep 17 00:00:00 2001 From: Jose Manuel Castano Date: Thu, 6 Mar 2025 11:53:42 +0100 Subject: [PATCH 6/6] Change test setup for set 'approval_required' parameter to bool for Service Plans. --- tests/integration/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 5b3ebdf..f7b7720 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -152,7 +152,7 @@ def account_user(account,account_user_params) -> AccountUser: @pytest.fixture(scope='module') def service_plan_params() -> dict: suffix = get_suffix() - return {"name":f'test-{suffix}', "approval_required":'True'} + return {"name":f'test-{suffix}', "approval_required": True} @pytest.fixture(scope='module') def service_plan(service, service_plan_params) -> ServicePlan: