Skip to content

Commit eb7fc0a

Browse files
committed
Draft: adding test_developer_portal.py
1 parent 3ce316b commit eb7fc0a

2 files changed

Lines changed: 157 additions & 0 deletions

File tree

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
"""
2+
Test for Developer Portal API scope
3+
"""
4+
5+
import pytest
6+
7+
from testsuite.ui.views.admin.settings.tokens import Scopes, TokenNewView
8+
from testsuite.utils import blame
9+
10+
@pytest.fixture(scope="module")
11+
def token(custom_admin_login, navigator, request, threescale, permission):
12+
"""
13+
Create token with scope set to 'Developer Portal'
14+
"""
15+
custom_admin_login()
16+
new = navigator.navigate(TokenNewView)
17+
name = blame(request, "token")
18+
token = new.create(name, [Scopes.DEVELOPER_PORTAL.value], permission[0])
19+
20+
def _delete():
21+
token = list(filter(lambda x: x["name"] == name, threescale.access_tokens.list()))[0]
22+
threescale.access_tokens.delete(token.entity_id)
23+
24+
request.addfinalizer(_delete)
25+
return token
26+
27+
28+
def test_read_service(token, api_client):
29+
"""
30+
Request to get list of services should have status code 403
31+
"""
32+
33+
response = api_client("GET", "/admin/api/services", token)
34+
assert response.status_code == 403
35+
36+
37+
def test_create_account_user(account, token, api_client, request):
38+
"""
39+
Request to create user should have status code 403
40+
"""
41+
42+
name = blame(request, "acc")
43+
params = {
44+
"account_id": account.entity_id,
45+
"username": name,
46+
"email": f"{name}@anything.invalid",
47+
"password": "123456",
48+
}
49+
response = api_client("POST", f"/admin/api/accounts/{account.entity_id}/users", token, params)
50+
assert response.status_code == 403
51+
52+
53+
def test_get_service_top_applications(service, token, api_client):
54+
"""
55+
Request to get top applications should have status code 403
56+
"""
57+
58+
params = {"service_id": service.entity_id, "since": "2012-02-22 00:00:00", "period": "year", "metric_name": "hits"}
59+
response = api_client("GET", f"/stats/services/{service.entity_id}/top_applications", token, params)
60+
assert response.status_code == 403
61+
62+
63+
def test_get_invoice_list(account, token, api_client):
64+
"""
65+
Request to get list of invoices should have status code 403
66+
"""
67+
68+
params = {"account_id": account.entity_id}
69+
response = api_client("GET", f"/api/accounts/{account.entity_id}/invoices", token, params)
70+
assert response.status_code == 403
71+
72+
73+
def test_create_invoice_line_item(invoice, token, api_client, request, permission):
74+
"""
75+
Request to create line item should have status code 403
76+
"""
77+
78+
name = blame(request, "item")
79+
params = {"invoice_id": invoice.entity_id, "name": name, "description": "description", "quantity": "1", "cost": 1}
80+
response = api_client("POST", f"/api/invoices/{invoice.entity_id}/line_items", token, json=params)
81+
assert response.status_code == 403
82+
83+
84+
def test_get_registry_policies_list(token, api_client):
85+
"""
86+
Request to get list of registry policies should have status code 403
87+
"""
88+
89+
response = api_client("GET", "/admin/api/registry/policies", token)
90+
assert response.status_code == 403
91+
92+
93+
def test_create_registry_policy(token, api_client, schema):
94+
"""
95+
Request to create policy registry should have status code 403
96+
"""
97+
params = {"name": "policy_registry", "version": "0.1", "schema": schema}
98+
response = api_client("POST", "/admin/api/registry/policies", token, json=params)
99+
assert response.status_code == 403
100+
101+
102+
def test_create_provider_account(request, token, api_client):
103+
"""
104+
Request to create provider account should have status code 403
105+
"""
106+
username = blame(request, "username")
107+
params = {"username": username, "email": f"{username}@example.com", "password": "account_password"}
108+
response = api_client("POST", "/admin/api/users", token, params)
109+
assert response.status_code == 403
110+
111+
112+
def test_create_app_key(token, api_client, account, application):
113+
"""
114+
Request to create application key should have status code 403
115+
"""
116+
account_id = account.entity_id
117+
application_id = application.entity_id
118+
params = {"account_id": account_id, "application_id": application_id, "key": "test_key"}
119+
response = api_client("POST", f"/admin/api/accounts/{account_id}/applications/{application_id}/keys", token, params)
120+
assert response.status_code == 403
121+
122+
123+
def test_get_cms_templates(token, api_client):
124+
"""
125+
Request to get CMS templates. Should have status code 200.
126+
"""
127+
128+
response = api_client("GET", "/admin/api/cms/templates", token)
129+
assert response.status_code == 200
130+
131+
132+
def test_get_cms_sections(token, api_client):
133+
"""
134+
Request to get CMS sections. Should have status code 200.
135+
"""
136+
137+
response = api_client("GET", "/admin/api/cms/sections", token)
138+
assert response.status_code == 200
139+
140+
141+
def test_get_cms_files(token, api_client):
142+
"""
143+
Request to get CMS files. Should have status code 200.
144+
"""
145+
146+
response = api_client("GET", "/admin/api/cms/files", token)
147+
assert response.status_code == 200
148+
149+
150+
def test_create_cms_section(token, api_client, request, permission):
151+
"""POST CMS section - 201 (write) or 403 (read-only)"""
152+
title = blame(request, "section")
153+
params = {"title": title, "public": True, "partial_path": f"/{title}"}
154+
response = api_client("POST", "/admin/api/cms/sections", token, json=params)
155+
assert response.status_code == permission[1]
156+

testsuite/ui/views/admin/settings/tokens.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class Scopes(enum.Enum):
4141
MANAGEMENT = "access_token_scopes_account_management"
4242
ANALYTICS = "access_token_scopes_stats"
4343
POLICY = "access_token_scopes_policy_registry"
44+
DEVELOPER_PORTAL = "access_token_scopes_cms"
4445

4546

4647
class TokenNewView(BaseSettingsView):

0 commit comments

Comments
 (0)