From 20a44df120cee8bfd5f05e0304e35ce567277ff9 Mon Sep 17 00:00:00 2001 From: Martin Pentrak Date: Mon, 30 Sep 2024 21:49:16 +0200 Subject: [PATCH 1/5] 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 | 9 +++++++++ threescale_api/resources.py | 4 +++- 4 files changed, 23 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..3d90fb2 100644 --- a/tests/integration/test_integration_application_plan.py +++ b/tests/integration/test_integration_application_plan.py @@ -24,3 +24,8 @@ def test_application_plan_update(application_plan, update_params): updated_app_plan = application_plan.update(params=update_params) asserts.assert_resource(updated_app_plan) asserts.assert_resource_params(updated_app_plan, update_params) + + +def test_application_plans_list_all(application_plans): + app_plans = application_plans.list() + assert len(app_plans) >= 1 diff --git a/threescale_api/client.py b/threescale_api/client.py index 6e40251..aa44dc6 100644 --- a/threescale_api/client.py +++ b/threescale_api/client.py @@ -37,6 +37,8 @@ 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 +144,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..b63cd34 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: From 7b7f1e4c2c46621d2beae2a8f3565fb9e4847fe5 Mon Sep 17 00:00:00 2001 From: Martin Pentrak Date: Tue, 8 Oct 2024 14:44:32 +0200 Subject: [PATCH 2/5] done /adim/api/active_docs/{id}.json --- tests/integration/conftest.py | 16 ++++++++++++++++ .../integration/test_integration_activedocs.py | 18 +++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 9e24c33..4db7474 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -427,6 +427,22 @@ def tenant_params(): email="email@invalid.invalid", org_name="org") + +@pytest.fixture(scope='module') +def active_docs_update_body(): + return """ + {"swagger":"2.0","info":{"version":"1.0.1","title":"Test"},"paths":{"/test":{"get":{"operationId":"Test", + "parameters":[],"responses":{"400":{"description":"bad input parameters"}}}}},"definitions":{}} + """ + + +@pytest.fixture(scope='module') +def active_docs_update_params(active_docs_update_body): + suffix = get_suffix() + name = f"updated-{suffix}" + return dict(name=name, body=active_docs_update_body) + + @pytest.fixture(scope='module') def active_docs_body(): return """ diff --git a/tests/integration/test_integration_activedocs.py b/tests/integration/test_integration_activedocs.py index 7ef574d..d7f8d08 100644 --- a/tests/integration/test_integration_activedocs.py +++ b/tests/integration/test_integration_activedocs.py @@ -1,7 +1,23 @@ from tests.integration import asserts -from .asserts import assert_resource, assert_resource_params + + +def test_active_docs_can_be_created(active_doc, active_docs_params): + asserts.assert_resource(active_doc) + asserts.assert_resource_params(active_doc, active_docs_params) + def test_active_docs_fetch(active_doc): ac = active_doc.client.fetch(int(active_doc['id'])) assert ac assert ac['id'] == active_doc['id'] + + +def test_active_docs_list(api, active_doc): + active_docs = api.active_docs.list() + assert len(active_docs) >= 1 + + +def test_active_docs_update(active_doc, active_docs_update_params): + updated_active_doc = active_doc.update(params=active_docs_update_params) + asserts.assert_resource(updated_active_doc) + asserts.assert_resource_params(updated_active_doc, active_docs_update_params) From e8e0f714445414e400c8a8b48398b158604ea583 Mon Sep 17 00:00:00 2001 From: Martin Pentrak Date: Mon, 14 Oct 2024 13:16:47 +0200 Subject: [PATCH 3/5] done /adim/api/acount_plans/{id}.json --- tests/integration/conftest.py | 7 ++++++ .../test_integration_account_plans.py | 22 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tests/integration/test_integration_account_plans.py diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 4db7474..33249f1 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -498,6 +498,13 @@ def webhook(api): return api.webhooks +@pytest.fixture(scope='module') +def account_plans_update_params(): + suffix = secrets.token_urlsafe(8) + name = f"updated-{suffix}" + return dict(name=name, description=name) + + @pytest.fixture(scope='module') def account_plans_params(): suffix = get_suffix() diff --git a/tests/integration/test_integration_account_plans.py b/tests/integration/test_integration_account_plans.py new file mode 100644 index 0000000..c8e1bcd --- /dev/null +++ b/tests/integration/test_integration_account_plans.py @@ -0,0 +1,22 @@ +from tests.integration import asserts + +def test_account_plans_list(api, account_plan): + account_plans = api.account_plans.list() + assert len(account_plans) >= 1 + + +def test_account_plan_can_be_created(api, account_plan, account_plans_params): + asserts.assert_resource(account_plan) + asserts.assert_resource_params(account_plan, account_plans_params) + + +def test_account_plan_update(account_plan, account_plans_update_params): + updated_account_plan = account_plan.update(params=account_plans_update_params) + asserts.assert_resource(updated_account_plan) + asserts.assert_resource_params(updated_account_plan, account_plans_update_params) + + +def test_account_plan_can_be_read(api, account_plan, account_plans_params): + read = api.account_plans.read(account_plan.entity_id) + asserts.assert_resource(read) + asserts.assert_resource_params(read, account_plans_params) From c3b1704cf328e0c36edc15f956a73afa02a47751 Mon Sep 17 00:00:00 2001 From: Martin Pentrak Date: Mon, 14 Oct 2024 13:32:43 +0200 Subject: [PATCH 4/5] PUT /admin/api/accounts/{id} --- tests/integration/conftest.py | 7 +++++++ tests/integration/test_integration_accounts.py | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 33249f1..32c2767 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -102,6 +102,13 @@ def access_token(access_token_params, api): cleanup(entity) +@pytest.fixture(scope='module') +def update_account_params(): + suffix = secrets.token_urlsafe(8) + name = f"updated-{suffix}" + return dict(name=name, username=name, org_name=name) + + @pytest.fixture(scope='module') def account_params(): suffix = get_suffix() diff --git a/tests/integration/test_integration_accounts.py b/tests/integration/test_integration_accounts.py index 9eda751..4394bd8 100644 --- a/tests/integration/test_integration_accounts.py +++ b/tests/integration/test_integration_accounts.py @@ -11,6 +11,12 @@ def test_account_can_be_created(api, account, account_params): asserts.assert_resource_params(account, account_params) +def test_account_update(api,account,update_account_params): + updated_account = account.update(params=update_account_params) + asserts.assert_resource(updated_account) + asserts.assert_resource_params(updated_account,update_account_params) + + def test_account_can_be_read(api, account, account_params): read = api.accounts.read(account.entity_id) asserts.assert_resource(read) @@ -23,5 +29,6 @@ def test_account_can_be_read_by_name(api, account, account_params): asserts.assert_resource(read) asserts.assert_resource_params(read, account_params) + def test_users_list(api, account): assert len(account.users.list()) >= 1 From f0c604690f72174a47f4713204673ae94a3b5b3e Mon Sep 17 00:00:00 2001 From: Martin Pentrak Date: Tue, 15 Oct 2024 17:57:04 +0200 Subject: [PATCH 5/5] done /adim/api/service/{id}/backend_usages/{id} --- tests/integration/conftest.py | 19 ++++++++++++------- .../test_integration_account_plans.py | 1 + .../test_integration_backend_usages.py | 17 +++++++++++++++++ 3 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 tests/integration/test_integration_backend_usages.py diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 32c2767..bfdb8ab 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -179,13 +179,18 @@ def proxy(service, application, api_backend) -> Proxy: @pytest.fixture(scope='module') -def backend_usage(service, backend, application) -> BackendUsage: - params = { - 'service_id': service['id'], - 'backend_api_id': backend['id'], - 'path': '/get', - } - resource = service.backend_usages.create(params=params) +def backend_usage_update_params(service, backend): + return dict(service_id=service['id'], backend_api_id=backend['id'], path='/put') + + +@pytest.fixture(scope='module') +def backend_usage_params(service, backend): + return dict(service_id=service['id'], backend_api_id=backend['id'], path='/get') + + +@pytest.fixture(scope='module') +def backend_usage(service, backend, application, backend_usage_params) -> BackendUsage: + resource = service.backend_usages.create(params=backend_usage_params) yield resource cleanup(resource) diff --git a/tests/integration/test_integration_account_plans.py b/tests/integration/test_integration_account_plans.py index c8e1bcd..6f75f8f 100644 --- a/tests/integration/test_integration_account_plans.py +++ b/tests/integration/test_integration_account_plans.py @@ -1,5 +1,6 @@ from tests.integration import asserts + def test_account_plans_list(api, account_plan): account_plans = api.account_plans.list() assert len(account_plans) >= 1 diff --git a/tests/integration/test_integration_backend_usages.py b/tests/integration/test_integration_backend_usages.py new file mode 100644 index 0000000..fdf779e --- /dev/null +++ b/tests/integration/test_integration_backend_usages.py @@ -0,0 +1,17 @@ +from tests.integration import asserts +from tests.integration.conftest import backend + + +def test_backend_usage_can_be_created(backend_usage, backend_usage_params): + asserts.assert_resource(backend_usage) + asserts.assert_resource_params(backend_usage, backend_usage_params) + + +def test_backend_usages_list(api, backend_usage, backend): + assert len(backend.usages()) >= 1 + + +def test_backend_usage_update(backend_usage, backend, backend_usage_update_params): + updated_backend_usage = backend_usage.update(backend_usage_update_params) + asserts.assert_resource(updated_backend_usage) + asserts.assert_resource_params(updated_backend_usage, backend_usage_update_params)