Skip to content

Commit 5ed7cff

Browse files
committed
Update test
1 parent a3324b8 commit 5ed7cff

File tree

2 files changed

+57
-6
lines changed

2 files changed

+57
-6
lines changed

ckanext/activityinfo/tests/test_home.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from unittest import mock
12
from types import SimpleNamespace
23
import pytest
34
from ckantoolkit.tests import factories as ckan_factories
@@ -22,13 +23,29 @@ def test_regular_user(self, app, setup_data):
2223

2324
resp = app.get("/activity-info", headers=environ)
2425
assert resp.status_code == 200
25-
# CKAN users without a registered ActivityInfo token, will be asked to add one
26+
# This must be redirected to the /api-key URL
2627
assert "Add API key" in resp.body
2728

2829
def test_activityinfo_user(self, app, setup_data):
2930
environ = {"Authorization": setup_data.activityinfo_user["token"]}
30-
31-
resp = app.get("/activity-info", headers=environ)
32-
assert resp.status_code == 200
33-
# Activity info users will see the ActivityInfo UI
34-
assert "Update API key" in resp.body
31+
fake_databases = [
32+
{
33+
"databaseId": "0001",
34+
"label": "Database label 01",
35+
"description": "",
36+
"ownerId": "999999999",
37+
"billingAccountId": 8888888888888888,
38+
"suspended": False,
39+
"publishedTemplate": False,
40+
"languages": []
41+
},
42+
]
43+
44+
with mock.patch(
45+
"ckanext.activityinfo.data.base.ActivityInfoClient.get_databases",
46+
return_value=fake_databases,
47+
):
48+
resp = app.get("/activity-info", headers=environ)
49+
assert resp.status_code == 200
50+
# Activity info users will be redirected to see their databases
51+
assert "Activity Info databases" in resp.body
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from types import SimpleNamespace
2+
import pytest
3+
from ckantoolkit.tests import factories as ckan_factories
4+
from ckanext.activityinfo.tests import factories
5+
6+
7+
@pytest.fixture
8+
def setup_data():
9+
"""test setup data"""
10+
obj = SimpleNamespace()
11+
# Create CKAN users
12+
obj.activityinfo_user = factories.ActivityInfoUser()
13+
obj.regular_user = ckan_factories.UserWithToken()
14+
15+
return obj
16+
17+
18+
@pytest.mark.usefixtures("clean_db")
19+
class TestActivityInfoUIApiKey:
20+
def test_regular_user(self, app, setup_data):
21+
environ = {"Authorization": setup_data.regular_user["token"]}
22+
23+
resp = app.get("/activity-info/api-key", headers=environ)
24+
assert resp.status_code == 200
25+
# CKAN users without a registered ActivityInfo token, will be asked to add one
26+
assert "Add API key" in resp.body
27+
28+
def test_activityinfo_user(self, app, setup_data):
29+
environ = {"Authorization": setup_data.activityinfo_user["token"]}
30+
31+
resp = app.get("/activity-info/api-key", headers=environ)
32+
assert resp.status_code == 200
33+
# Activity info users will be redirected to see their databases
34+
assert "Update API key" in resp.body

0 commit comments

Comments
 (0)