-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtest_hierarchy.py
100 lines (78 loc) · 3.51 KB
/
test_hierarchy.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
from flask import g, url_for
from tests.base import TestBaseCase, get_hierarchy
class HierarchyTest(TestBaseCase):
def test_hierarchy(self) -> None:
c = self.client
data = {
'name': 'Geronimo',
'classes': ['file', 'group', 'move', 'person', 'place', 'source'],
'multiple': True,
'description': 'Very important!'}
rv = c.post(
url_for('hierarchy_insert', category='custom'),
data=data,
follow_redirects=True)
assert b'An entry has been created' in rv.data
rv = c.post(
url_for('hierarchy_insert', category='custom'),
data=data,
follow_redirects=True)
assert b'The name is already in use' in rv.data
hierarchy = get_hierarchy('Geronimo')
data[f'reference_system_id_{g.wikidata.id}'] \
= ['Q123', self.precision_type.subs[0]]
data['classes'] = ['acquisition']
data['entity_id'] = hierarchy.id
rv = c.post(
url_for('hierarchy_update', id_=hierarchy.id),
data=data,
follow_redirects=True)
assert b'Changes have been saved' in rv.data
rv = c.get(url_for('hierarchy_update', id_=hierarchy.id))
assert b'checked class="" id="multiple"' in rv.data
rv = c.get(url_for('hierarchy_insert', category='custom'))
assert b'+ Custom' in rv.data
sex = get_hierarchy('Sex')
rv = c.get(url_for('required_risk', id_=sex.id))
assert b'Be careful with making types required' in rv.data
rv = c.get(url_for('required_add', id_=sex.id), follow_redirects=True)
assert b'Changes have been saved' in rv.data
rv = c.get(url_for('insert', class_='person'))
assert b'Sex *' in rv.data
rv = c.get(
url_for('required_remove', id_=sex.id),
follow_redirects=True)
assert b'Changes have been saved' in rv.data
rv = c.post(
url_for('insert', class_='type', origin_id=hierarchy.id),
data={'name': 'Secret type', 'description': 'Very important!'})
type_id = rv.location.split('/')[-1]
rv = c.get(
url_for('remove_class', id_=hierarchy.id, name='person'),
follow_redirects=True)
assert b'Changes have been saved' in rv.data
rv = c.get(url_for('type_delete', id_=type_id), follow_redirects=True)
assert b'deleted' in rv.data
rv = c.post(
url_for('hierarchy_update', id_=hierarchy.id),
data={'name': 'Actor relation', 'entity_id': hierarchy.id},
follow_redirects=True)
assert b'The name is already in use' in rv.data
rv = c.post(
url_for('hierarchy_delete', id_=hierarchy.id),
follow_redirects=True)
assert b'deleted' in rv.data
rv = c.get(url_for('hierarchy_insert', category='value'))
assert b'+ Value' in rv.data
rv = c.post(
url_for('hierarchy_insert', category='value'),
data={'name': 'Valued', 'classes': ['file']},
follow_redirects=True,)
assert b'An entry has been created' in rv.data
rv = c.get(url_for('hierarchy_update', id_=get_hierarchy('Valued').id))
assert b'Valued' in rv.data
type_ = get_hierarchy('Actor relation')
rv = c.get(url_for('hierarchy_update', id_=type_.id))
assert b'Forbidden' in rv.data
rv = c.get(url_for('hierarchy_delete', id_=type_.id))
assert b'Forbidden' in rv.data