Skip to content

Commit 443fabb

Browse files
author
mkudlej
authored
Merge pull request 3scale-qe#162 from Gituser010/master
extended api tests
2 parents d2ff206 + f0c6046 commit 443fabb

File tree

8 files changed

+129
-10
lines changed

8 files changed

+129
-10
lines changed

tests/integration/conftest.py

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
Proxy, Backend, Metric, MappingRule,
1414
BackendMappingRule, BackendUsage,
1515
ActiveDoc, Webhooks, InvoiceState,
16-
ApplicationKey)
16+
ApplicationKey, ApplicationPlans)
1717

1818
load_dotenv()
1919

@@ -102,6 +102,13 @@ def access_token(access_token_params, api):
102102
cleanup(entity)
103103

104104

105+
@pytest.fixture(scope='module')
106+
def update_account_params():
107+
suffix = secrets.token_urlsafe(8)
108+
name = f"updated-{suffix}"
109+
return dict(name=name, username=name, org_name=name)
110+
111+
105112
@pytest.fixture(scope='module')
106113
def account_params():
107114
suffix = get_suffix()
@@ -127,6 +134,11 @@ def application_plan(api, service, application_plan_params) -> ApplicationPlan:
127134
resource = service.app_plans.create(params=application_plan_params)
128135
yield resource
129136

137+
@pytest.fixture(scope='module')
138+
def application_plans(api) -> ApplicationPlans:
139+
application_plans = api.application_plans
140+
yield application_plans
141+
130142

131143
@pytest.fixture(scope='module')
132144
def application_params(application_plan):
@@ -167,13 +179,18 @@ def proxy(service, application, api_backend) -> Proxy:
167179

168180

169181
@pytest.fixture(scope='module')
170-
def backend_usage(service, backend, application) -> BackendUsage:
171-
params = {
172-
'service_id': service['id'],
173-
'backend_api_id': backend['id'],
174-
'path': '/get',
175-
}
176-
resource = service.backend_usages.create(params=params)
182+
def backend_usage_update_params(service, backend):
183+
return dict(service_id=service['id'], backend_api_id=backend['id'], path='/put')
184+
185+
186+
@pytest.fixture(scope='module')
187+
def backend_usage_params(service, backend):
188+
return dict(service_id=service['id'], backend_api_id=backend['id'], path='/get')
189+
190+
191+
@pytest.fixture(scope='module')
192+
def backend_usage(service, backend, application, backend_usage_params) -> BackendUsage:
193+
resource = service.backend_usages.create(params=backend_usage_params)
177194
yield resource
178195
cleanup(resource)
179196

@@ -422,6 +439,22 @@ def tenant_params():
422439
email="email@invalid.invalid",
423440
org_name="org")
424441

442+
443+
@pytest.fixture(scope='module')
444+
def active_docs_update_body():
445+
return """
446+
{"swagger":"2.0","info":{"version":"1.0.1","title":"Test"},"paths":{"/test":{"get":{"operationId":"Test",
447+
"parameters":[],"responses":{"400":{"description":"bad input parameters"}}}}},"definitions":{}}
448+
"""
449+
450+
451+
@pytest.fixture(scope='module')
452+
def active_docs_update_params(active_docs_update_body):
453+
suffix = get_suffix()
454+
name = f"updated-{suffix}"
455+
return dict(name=name, body=active_docs_update_body)
456+
457+
425458
@pytest.fixture(scope='module')
426459
def active_docs_body():
427460
return """
@@ -477,6 +510,13 @@ def webhook(api):
477510
return api.webhooks
478511

479512

513+
@pytest.fixture(scope='module')
514+
def account_plans_update_params():
515+
suffix = secrets.token_urlsafe(8)
516+
name = f"updated-{suffix}"
517+
return dict(name=name, description=name)
518+
519+
480520
@pytest.fixture(scope='module')
481521
def account_plans_params():
482522
suffix = get_suffix()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from tests.integration import asserts
2+
3+
4+
def test_account_plans_list(api, account_plan):
5+
account_plans = api.account_plans.list()
6+
assert len(account_plans) >= 1
7+
8+
9+
def test_account_plan_can_be_created(api, account_plan, account_plans_params):
10+
asserts.assert_resource(account_plan)
11+
asserts.assert_resource_params(account_plan, account_plans_params)
12+
13+
14+
def test_account_plan_update(account_plan, account_plans_update_params):
15+
updated_account_plan = account_plan.update(params=account_plans_update_params)
16+
asserts.assert_resource(updated_account_plan)
17+
asserts.assert_resource_params(updated_account_plan, account_plans_update_params)
18+
19+
20+
def test_account_plan_can_be_read(api, account_plan, account_plans_params):
21+
read = api.account_plans.read(account_plan.entity_id)
22+
asserts.assert_resource(read)
23+
asserts.assert_resource_params(read, account_plans_params)

tests/integration/test_integration_accounts.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ def test_account_can_be_created(api, account, account_params):
1111
asserts.assert_resource_params(account, account_params)
1212

1313

14+
def test_account_update(api,account,update_account_params):
15+
updated_account = account.update(params=update_account_params)
16+
asserts.assert_resource(updated_account)
17+
asserts.assert_resource_params(updated_account,update_account_params)
18+
19+
1420
def test_account_can_be_read(api, account, account_params):
1521
read = api.accounts.read(account.entity_id)
1622
asserts.assert_resource(read)
@@ -23,5 +29,6 @@ def test_account_can_be_read_by_name(api, account, account_params):
2329
asserts.assert_resource(read)
2430
asserts.assert_resource_params(read, account_params)
2531

32+
2633
def test_users_list(api, account):
2734
assert len(account.users.list()) >= 1
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
from tests.integration import asserts
2-
from .asserts import assert_resource, assert_resource_params
2+
3+
4+
def test_active_docs_can_be_created(active_doc, active_docs_params):
5+
asserts.assert_resource(active_doc)
6+
asserts.assert_resource_params(active_doc, active_docs_params)
7+
38

49
def test_active_docs_fetch(active_doc):
510
ac = active_doc.client.fetch(int(active_doc['id']))
611
assert ac
712
assert ac['id'] == active_doc['id']
13+
14+
15+
def test_active_docs_list(api, active_doc):
16+
active_docs = api.active_docs.list()
17+
assert len(active_docs) >= 1
18+
19+
20+
def test_active_docs_update(active_doc, active_docs_update_params):
21+
updated_active_doc = active_doc.update(params=active_docs_update_params)
22+
asserts.assert_resource(updated_active_doc)
23+
asserts.assert_resource_params(updated_active_doc, active_docs_update_params)

tests/integration/test_integration_application_plan.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ def test_application_plan_update(application_plan, update_params):
2424
updated_app_plan = application_plan.update(params=update_params)
2525
asserts.assert_resource(updated_app_plan)
2626
asserts.assert_resource_params(updated_app_plan, update_params)
27+
28+
29+
def test_application_plans_list_all(application_plans):
30+
app_plans = application_plans.list()
31+
assert len(app_plans) >= 1
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from tests.integration import asserts
2+
from tests.integration.conftest import backend
3+
4+
5+
def test_backend_usage_can_be_created(backend_usage, backend_usage_params):
6+
asserts.assert_resource(backend_usage)
7+
asserts.assert_resource_params(backend_usage, backend_usage_params)
8+
9+
10+
def test_backend_usages_list(api, backend_usage, backend):
11+
assert len(backend.usages()) >= 1
12+
13+
14+
def test_backend_usage_update(backend_usage, backend, backend_usage_update_params):
15+
updated_backend_usage = backend_usage.update(backend_usage_update_params)
16+
asserts.assert_resource(updated_backend_usage)
17+
asserts.assert_resource_params(updated_backend_usage, backend_usage_update_params)

threescale_api/client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ def __init__(self, url: str, token: str,
3737
self._access_tokens = \
3838
resources.AccessTokens(self, instance_klass=resources.AccessToken)
3939
self._active_docs = resources.ActiveDocs(self, instance_klass=resources.ActiveDoc)
40+
self._application_plans = \
41+
resources.ApplicationPlans(self, instance_klass=resources.ApplicationPlan)
4042
self._account_plans = resources.AccountPlans(self, instance_klass=resources.AccountPlan)
4143
self._settings = resources.SettingsClient(self)
4244
self._admin_portal_auth_providers = resources.AdminPortalAuthProviders(
@@ -142,6 +144,13 @@ def master_api_url(self) -> str:
142144
"""
143145
return self.url + "/master/api"
144146

147+
@property
148+
def application_plans(self) -> resources.ApplicationPlans:
149+
"""Get applications_plan client
150+
Returns(resources.ApplicationPlans): ApplicationPlans client
151+
"""
152+
return self._application_plans
153+
145154
@property
146155
def services(self) -> resources.Services:
147156
"""Gets services client

threescale_api/resources.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ def __init__(self, *args, entity_name='application_plan', entity_collection='pla
128128

129129
@property
130130
def url(self) -> str:
131-
return self.parent.url + '/application_plans'
131+
if type(self.parent) is Service:
132+
return self.parent.url + '/application_plans'
133+
return self.threescale_client.admin_api_url + '/application_plans'
132134

133135
@property
134136
def plans_url(self) -> str:

0 commit comments

Comments
 (0)