Skip to content

Commit 71ff44d

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

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

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)