diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 61ce47a..bfdb8ab 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() @@ -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() @@ -127,6 +134,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): @@ -167,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) @@ -422,6 +439,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 """ @@ -477,6 +510,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..6f75f8f --- /dev/null +++ b/tests/integration/test_integration_account_plans.py @@ -0,0 +1,23 @@ +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) 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 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) 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/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) 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: