-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtest_type.py
162 lines (126 loc) · 5.38 KB
/
test_type.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
from flask import g, url_for
from openatlas import app
from tests.base import TestBaseCase, get_hierarchy, insert
class TypeTest(TestBaseCase):
def test_type(self) -> None:
c = self.client
with app.test_request_context():
app.preprocess_request()
actor_type = get_hierarchy('Actor relation')
dimension_type = get_hierarchy('Dimensions')
historical_type = get_hierarchy('Historical place')
place = insert('place', 'Home')
place.link('P2', g.types[dimension_type.subs[0]], '46')
location = place.get_linked_entity_safe('P53')
location.link('P89', g.types[historical_type.subs[0]])
rv = c.get(url_for('view', id_=historical_type.subs[0]))
assert b'Historical place' in rv.data
rv = c.get(url_for('insert', class_='type', origin_id=actor_type.id))
assert b'Actor relation' in rv.data
data = {
'name': 'My secret type',
'name_inverse': 'Do I look inverse?',
'description': 'Very important!',
actor_type.id: actor_type.subs[0]}
rv = c.post(
url_for('insert', class_='type', origin_id=actor_type.id),
data=data)
type_id = rv.location.split('/')[-1]
rv = c.get(url_for('update', id_=type_id))
assert b'My secret type' in rv.data
assert b'super' in rv.data
rv = c.get(url_for('update', id_=dimension_type.subs[0]))
assert b'unit' in rv.data
rv = c.post(
url_for('update', id_=type_id),
data=data,
follow_redirects=True)
assert b'Changes have been saved' in rv.data
data['continue_'] = 'yes'
rv = c.post(
url_for('insert', class_='type', origin_id=actor_type.id),
data=data,
follow_redirects=True)
assert b'An entry has been created' in rv.data
rv = c.post(
url_for('ajax_add_type'),
data={
'name': 'New dynamic',
'description': 'Hello',
'superType': actor_type.id})
assert rv.data.isdigit()
rv = c.get(url_for('ajax_get_type_tree', root_id=actor_type.id))
assert b'New dynamic' in rv.data
rv = c.post(url_for('update', id_=actor_type.id), data=data)
assert b'Forbidden' in rv.data
admin_unit = get_hierarchy('Administrative unit')
rv = c.post(
url_for(
'insert',
class_='administrative_unit',
origin_id=admin_unit.subs[0]),
data={'name': 'admin unit'},
follow_redirects=True)
assert b'An entry has been created' in rv.data
rv = c.get(url_for('update', id_=admin_unit.subs[0]))
assert b'admin unit' in rv.data
rv = c.get(url_for('view', id_=dimension_type.subs[0]))
assert b'Unit' in rv.data
sex = get_hierarchy('Sex')
sex_sub = g.types[sex.subs[0]]
rv = c.get(
url_for('type_unset_selectable', id_=sex_sub.id),
follow_redirects=True)
assert b'set selectable' in rv.data
rv = c.get(url_for('insert', class_='person'))
assert b'sex' in rv.data
rv = c.get(url_for('type_index'))
assert b'sex' in rv.data
rv = c.get(
url_for('type_set_selectable', id_=sex_sub.id),
follow_redirects=True)
assert b'set unselectable' in rv.data
with app.test_request_context():
app.preprocess_request()
actor = insert('person', 'Connor MacLeod')
actor.link('P2', sex_sub)
rv = c.get(url_for('show_untyped_entities', id_=sex.id))
assert b'no entries' in rv.data
rv = c.get(url_for('show_untyped_entities', id_=admin_unit.id))
assert b'Home' in rv.data
rv = c.get(
url_for('type_delete', id_=actor_type.id),
follow_redirects=True)
assert b'Forbidden' in rv.data
with app.test_request_context():
app.preprocess_request()
actor.link('P2', g.types[sex.subs[1]])
rv = c.get(url_for('update', id_=actor.id))
assert b'422' in rv.data
rv = c.post(url_for('type_move_entities', id_=dimension_type.subs[0]))
assert b'403' in rv.data
rv = c.get(url_for('show_multiple_linked_entities', id_=sex.id))
assert b'Connor' in rv.data
c.post(
url_for('hierarchy_update', id_=sex.id),
data={'multiple': True})
rv = c.get(url_for('hierarchy_update', id_=sex.id))
assert b'disabled="disabled" id="multiple"' in rv.data
rv = c.get(
url_for('hierarchy_delete', id_=sex.id),
follow_redirects=True)
assert b'Warning' in rv.data
with app.test_request_context():
app.preprocess_request()
actor.link('P74', location, type_id=actor_type.subs[0])
rv = c.get(url_for('type_delete_recursive', id_=actor_type.subs[0]))
assert b'Warning' in rv.data
rv = c.post(
url_for('type_delete_recursive', id_=sex.id),
data={'confirm_delete': True},
follow_redirects=True)
assert b'Types deleted' in rv.data
rv = c.post(
url_for('type_delete_recursive', id_=actor_type.id),
data={'confirm_delete': True})
assert b'403 - Forbidden' in rv.data