forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_users.py
More file actions
78 lines (57 loc) · 1.99 KB
/
test_users.py
File metadata and controls
78 lines (57 loc) · 1.99 KB
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
import pytest
from models import Users, User_affiliations, Organizations
from db import DB
@pytest.fixture
def save():
s, cleanup, session = DB()
yield s
cleanup()
def test_find_by_user_name_returns_none():
assert Users.find_by_user_name("bob") is None
def test_find_by_user_name_returns_a_user(save):
test_user = Users(user_name="foo@example.com")
save(test_user)
retrieved_user = Users.find_by_user_name("foo@example.com")
assert retrieved_user.user_name == test_user.user_name
def test_short_passwords_raise_an_error():
with pytest.raises(ValueError):
Users(user_name="foo@example.com", password="1")
def test_user_model_encrypts_the_user_password():
acceptable_password = "twelvechars!"
user = Users(
user_name="foo",
display_name="Foo",
preferred_lang="English",
password=acceptable_password,
)
assert len(user.password) is 60
def test_user_is_admin_on_their_default_org():
acceptable_password = "twelvechars!"
user = Users(
user_name="foo",
display_name="Foo",
preferred_lang="English",
password=acceptable_password,
)
for affiliation in user.user_affiliation:
assert affiliation.permission is "admin"
assert affiliation.user_organization.acronym == "FOO"
def test_users_roles_can_be_accessed_by_a_roles_method(save):
acceptable_password = "twelvechars!"
user = Users(
user_name="foo",
display_name="Foo",
preferred_lang="English",
password=acceptable_password,
)
user.user_affiliation.append(
User_affiliations(
permission="user_write",
user_organization=Organizations(
acronym="ORG1", org_tags={"description": "Organization 1"}
),
)
)
# Before save org_id and user_id are None
role = [r for r in user.roles if r["permission"] == "user_write"]
assert role == [{"org_id": None, "permission": "user_write", "user_id": None}]