From 18b8a37a47b9aee3adf9f767e0059ca9c5cf1a00 Mon Sep 17 00:00:00 2001 From: Martin Pentrak Date: Mon, 30 Sep 2024 21:49:16 +0200 Subject: [PATCH] add get all applications plans test GET /admin/api/application_plans --- tests/integration/conftest.py | 7 ++++++- tests/integration/test_integration_application_plan.py | 5 +++++ threescale_api/client.py | 8 ++++++++ threescale_api/resources.py | 4 +++- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 61ce47a..9e24c33 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -13,7 +13,7 @@ Proxy, Backend, Metric, MappingRule, BackendMappingRule, BackendUsage, ActiveDoc, Webhooks, InvoiceState, - ApplicationKey) + ApplicationKey, ApplicationPlans) load_dotenv() @@ -127,6 +127,11 @@ def application_plan(api, service, application_plan_params) -> ApplicationPlan: resource = service.app_plans.create(params=application_plan_params) yield resource +@pytest.fixture(scope='module') +def application_plans(api) -> ApplicationPlans: + application_plans = api.application_plans + yield application_plans + @pytest.fixture(scope='module') def application_params(application_plan): diff --git a/tests/integration/test_integration_application_plan.py b/tests/integration/test_integration_application_plan.py index 4803401..06e2e61 100644 --- a/tests/integration/test_integration_application_plan.py +++ b/tests/integration/test_integration_application_plan.py @@ -20,6 +20,11 @@ def test_application_plans_list(service): assert len(app_plans) == 1 +def test_application_plans_list_all(application_plans): + app_plans = application_plans.list() + assert len(app_plans) >= 1 + + def test_application_plan_update(application_plan, update_params): updated_app_plan = application_plan.update(params=update_params) asserts.assert_resource(updated_app_plan) diff --git a/threescale_api/client.py b/threescale_api/client.py index 6e40251..d728e6f 100644 --- a/threescale_api/client.py +++ b/threescale_api/client.py @@ -37,6 +37,7 @@ def __init__(self, url: str, token: str, self._access_tokens = \ resources.AccessTokens(self, instance_klass=resources.AccessToken) self._active_docs = resources.ActiveDocs(self, instance_klass=resources.ActiveDoc) + self._application_plans =resources.ApplicationPlans(self, instance_klass=resources.ApplicationPlan) self._account_plans = resources.AccountPlans(self, instance_klass=resources.AccountPlan) self._settings = resources.SettingsClient(self) self._admin_portal_auth_providers = resources.AdminPortalAuthProviders( @@ -142,6 +143,13 @@ def master_api_url(self) -> str: """ return self.url + "/master/api" + @property + def application_plans(self) -> resources.ApplicationPlans: + """Get applications_plan client + Returns(resources.ApplicationPlans): ApplicationPlans client + """ + return self._application_plans + @property def services(self) -> resources.Services: """Gets services client diff --git a/threescale_api/resources.py b/threescale_api/resources.py index a4a2b0a..5f06db9 100644 --- a/threescale_api/resources.py +++ b/threescale_api/resources.py @@ -128,7 +128,9 @@ def __init__(self, *args, entity_name='application_plan', entity_collection='pla @property def url(self) -> str: - return self.parent.url + '/application_plans' + if type(self.parent) is Service: + return self.parent.url + '/application_plans' + return self.threescale_client.admin_api_url +'/application_plans' @property def plans_url(self) -> str: