forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_email_verify_account.py
More file actions
113 lines (93 loc) · 2.65 KB
/
Copy pathtest_email_verify_account.py
File metadata and controls
113 lines (93 loc) · 2.65 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
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
import logging
import pytest
from pytest import fail
from db import DB
from json_web_token import tokenize
from models import Users
from tests.test_functions import json, run
@pytest.fixture
def save():
s, cleanup, session = DB()
yield s
cleanup()
def test_successful_account_verification(save, caplog):
"""
Test that an account can be successfully verified
"""
user = Users(
display_name="testuser",
user_name="testuser@testemail.ca",
password="testpassword123",
)
save(user)
token = tokenize(parameters={"user_id": user.id}, exp_period=24)
caplog.set_level(logging.INFO)
result = run(
mutation=f"""
mutation {{
emailVerifyAccount(
input: {{
tokenString: "{token}"
}}
) {{
status
}}
}}
""",
as_user=user,
)
if "errors" in result:
fail("expected account to be verified. Instead:" "{}".format(json(result)))
expected_result = {"data": {"emailVerifyAccount": {"status": True}}}
assert result == expected_result
assert f"User: {user.id} successfully verified their account." in caplog.text
result = run(
query="""
{
user {
emailValidated
}
}
""",
as_user=user,
)
if "errors" in result:
fail("expected account to be verified. Instead:" "{}".format(json(result)))
expected_result = {"data": {"user": [{"emailValidated": True}]}}
assert result == expected_result
assert (
f"User {user.id} successfully retrieved their own information." in caplog.text
)
def test_email_account_verification_where_account_doesnt_exist(save, caplog):
"""
Test that log, and error occurs when user doesn't exist
"""
token = tokenize(parameters={"user_id": 5}, exp_period=24)
caplog.set_level(logging.WARNING)
result = run(
mutation=f"""
mutation {{
emailVerifyAccount(
input: {{
tokenString: "{token}"
}}
) {{
status
}}
}}
""",
)
if "errors" not in result:
fail(
"expected emailVerifyAccount to fail when user does not exist. Instead: {}".format(
json(result)
)
)
errors, data = result.values()
[first] = errors
message, _, _ = first.values()
assert message == "Error, unable to verify account."
assert (
f"User: {5} attempted to verify their account but it does not exist."
in caplog.text
)