forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_send_password_reset_link.py
More file actions
109 lines (93 loc) · 2.83 KB
/
Copy pathtest_send_password_reset_link.py
File metadata and controls
109 lines (93 loc) · 2.83 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
import logging
import pytest
from pytest import fail
from app import app
from db import DB
from models.Users import Users
from tests.test_functions import json, run
@pytest.fixture()
def save():
s, cleanup, db_session = DB()
yield s
cleanup()
def test_successful_send_password_reset_link(save, mocker, caplog):
"""
Test successful sendPasswordResetLink mutation
"""
mocker.patch(
"schemas.send_password_reset_email.send_password_reset_link.send_password_reset_email",
autospec=True,
return_value=True,
)
user = Users(
display_name="testuserread",
user_name="testuserread@testemail.ca",
password="testpassword123",
preferred_lang="English",
tfa_validated=False,
)
save(user)
caplog.set_level(logging.INFO)
with app.test_request_context():
result = run(
mutation="""
mutation {
sendPasswordResetLink(
userName: "testuserread@testemail.ca"
) {
status
}
}
"""
)
if "errors" in result:
fail(
"Expected to send password reset email email, instead: {}".format(
json(result)
)
)
expected_result = {
"data": {
"sendPasswordResetLink": {
"status": "If an account with this username is found, a password reset link will be found in your inbox."
}
}
}
assert result == expected_result
assert f"User: {user.id}, successfully sent a password reset email." in caplog.text
def test_unsuccessful_send_password_reset_link_user_doesnt_exist(save, caplog):
"""
Test to see error message occurs if user does not exist
"""
caplog.set_level(logging.INFO)
request_headers = {"Origin": "https://testserver.com"}
with app.test_request_context(headers=request_headers):
result = run(
mutation="""
mutation {
sendPasswordResetLink(
userName: "testuserread@testemail.ca"
) {
status
}
}
"""
)
if "errors" in result:
fail(
"Expected to get and error that the user does not exist, instead: {}".format(
json(result)
)
)
expected_result = {
"data": {
"sendPasswordResetLink": {
"status": "If an account with this username is found, a password reset link will be found in your inbox."
}
}
}
assert result == expected_result
assert (
f"A user attempted to send a password reset email for testuserread@testemail.ca but this user name is not affiliated with any account."
in caplog.text
)