-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtest_user.py
139 lines (110 loc) · 4.52 KB
/
test_user.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
from flask import g, url_for
from flask_login import current_user
from openatlas import app
from tests.base import TestBaseCase, insert
class UserTests(TestBaseCase):
def test_user(self) -> None:
c = self.client
data = {
'active': '',
'username': 'Ripley',
'email': '[email protected]',
'password': 'you_never_guess_this',
'password2': 'you_never_guess_this',
'group': 'admin',
'name': 'Ripley Weaver',
'real_name': '',
'description': ''}
rv = c.post(url_for('user_insert'), data=data)
user_id = rv.location.split('/')[-1]
data['password'] = 'too short'
rv = c.post(url_for('user_insert'), data=data)
assert b'match' in rv.data
rv = c.post(
url_for('user_insert'),
data={
'active': '',
'username': 'Newt',
'email': '[email protected]',
'password': 'you_never_guess_this',
'password2': 'you_never_guess_this',
'group': 'admin',
'name': 'Newt',
'continue_': 'yes',
'real_name': '',
'description': ''},
follow_redirects=True)
assert b'Newt' not in rv.data
rv = c.get(url_for('user_view', id_=666))
assert b'404' in rv.data
rv = c.get(url_for('user_update', id_=self.alice_id))
assert b'Alice' in rv.data
data['description'] = 'The warrant officer'
rv = c.post(
url_for('user_update', id_=user_id),
data=data,
follow_redirects=True)
assert b'The warrant officer' in rv.data
rv = c.post(url_for('user_update', id_=1234), data=data)
assert b'404' in rv.data
rv = c.get(url_for('user_delete', id_=user_id), follow_redirects=True)
assert b'User deleted' in rv.data
rv = c.post(
url_for('insert', class_='bibliography'),
data={'name': 'test', 'description': 'test'},
follow_redirects=True)
assert b'An entry has been created' in rv.data
rv = c.post(
url_for('user_activity', user_id=user_id),
data={'limit': 100, 'user': 0, 'action': 'all'})
assert b'activity' in rv.data
rv = c.get(url_for('user_delete', id_=self.alice_id))
assert b'403 - Forbidden' in rv.data
with app.test_request_context():
app.preprocess_request()
person = insert('person', 'Hugo')
insert('activity', 'Event Horizon').link('P11', person)
rv = c.post(url_for('ajax_bookmark'), data={'entity_id': person.id})
assert b'Remove bookmark' in rv.data
with app.test_request_context():
current_user.bookmarks = [person.id]
rv = c.get('/')
assert b'Hugo' in rv.data
rv = c.post(url_for('ajax_bookmark'), data={'entity_id': person.id})
assert b'Bookmark' in rv.data
c.get(url_for('logout'))
rv = c.get(url_for('user_insert'), follow_redirects=True)
assert b'Forgot your password?' not in rv.data
c.post(
url_for('login'),
data={'username': 'Editor', 'password': 'test'})
rv = c.get(url_for('user_insert'))
assert b'403 - Forbidden' in rv.data
rv = c.post(url_for('insert', class_='reference_system'))
assert b'403 - Forbidden' in rv.data
rv = c.get(url_for('delete', id_=g.wikidata.id))
assert b'403 - Forbidden' in rv.data
c.get(url_for('logout'))
c.post(
url_for('login'),
data={'username': 'Manager', 'password': 'test'})
rv = c.get(url_for('settings', category='mail'))
assert b'403 - Forbidden' in rv.data
rv = c.get(url_for('user_update', id_=self.alice_id))
assert b'403 - Forbidden' in rv.data
c.get(url_for('logout'))
c.post(
url_for('login'),
data={'username': 'Contributor', 'password': 'test'})
rv = c.get(url_for('delete', id_=person.id))
assert b'403 - Forbidden' in rv.data
rv = c.get(url_for('update', id_=person.id))
assert b'Hugo' in rv.data
rv = c.get(url_for('view', id_=person.id))
assert b'Hugo' in rv.data
c.get(url_for('logout'))
c.post(
url_for('login'),
data={'username': 'Readonly', 'password': 'test'})
rv = c.get(url_for('view', id_=person.id))
assert b'Hugo' in rv.data