-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_app.py
103 lines (80 loc) · 2.86 KB
/
test_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import bottle
import pytest
from unittest.mock import patch, MagicMock
import showcase
import data
TEST_DATA = {
'LAB1': {
'name': None,
'url': None,
'prof': MagicMock(),
'projects': {
'proj1': {
'name': 'Project 1',
'date_added': MagicMock(),
'type': 'Library',
},
'proj2': None,
'type': 'Application',
},
},
'LAB2': {
'name': 'Project 2',
'url': None,
'prof': MagicMock(),
'projects': {
'proj2': None,
'type': 'Experiments',
}
},
}
def test_load_data():
data.load()
def test_consistent_data():
labs = data.load()
for p in [
p
for lab in labs.values()
if 'projects' in lab
for p in lab['projects'].values()
]:
# All projects in the incubator should have a C4DT contact (or a default exists)
if p.get('incubator'):
assert 'c4dt_contact' in p, f"'c4dt_contact' missing in {p['name']}"
# All projects with code have a type
if 'code' in p:
assert 'type' in p['code'], f"'type' missing from code section in {p['name']}"
if 'demo' in p:
# All demos have a title
assert 'title' in p['demo'], f"'title' missing from demo section in {p['name']}"
# If 'url' is provided, 'code' must also be
if 'url' in p['demo']:
assert 'code' in p['demo'], f"'code' missing from demo section in {p['name']}"
def test_showcase():
showcase.showcase()
def test_all_projects():
labs = data.load()
with patch.object(data, 'load', return_value=labs):
for lab_id, lab in labs.items():
if 'projects' not in lab: continue
for project_id in lab['projects']:
for tab in showcase.find_project_products(project_id):
showcase.product_tab(project_id, tab)
@patch.object(data, 'load', return_value=TEST_DATA)
def test_project_does_not_exist(data):
with pytest.raises(bottle.HTTPResponse) as exc:
showcase.product_tab('dummy', 'technical')
assert exc.value.status.startswith('404')
@patch.object(data, 'load', return_value=TEST_DATA)
def test_project(test_data):
showcase.product_tab('proj1', 'technical')
# Check proj1 fields were accessed
proj1 = test_data()['LAB1']['projects']['proj1']
proj1['date_added'].date.assert_called()
def test_index():
with pytest.raises(bottle.HTTPResponse) as exc:
showcase.index()
# Check that we are redirected to FACTORY_URL
resp = exc.value
assert resp.status.startswith('302')
assert resp.headers['Location'] == showcase.FACTORY_URL