Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 48 additions & 8 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Proxy, Backend, Metric, MappingRule,
BackendMappingRule, BackendUsage,
ActiveDoc, Webhooks, InvoiceState,
ApplicationKey)
ApplicationKey, ApplicationPlans)

load_dotenv()

Expand Down Expand Up @@ -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()
Expand All @@ -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):
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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 """
Expand Down Expand Up @@ -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()
Expand Down
23 changes: 23 additions & 0 deletions tests/integration/test_integration_account_plans.py
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions tests/integration/test_integration_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
18 changes: 17 additions & 1 deletion tests/integration/test_integration_activedocs.py
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions tests/integration/test_integration_application_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions tests/integration/test_integration_backend_usages.py
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 9 additions & 0 deletions threescale_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion threescale_api/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading