1
|
|
|
import re |
2
|
|
|
from .. import factories as f |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
def test_forgot_password_flow(base_url, browser, outbox): |
6
|
|
|
f.create_usertype(slug='tutor', display_name='tutor') |
7
|
|
|
user = f.UserFactory() |
8
|
|
|
|
9
|
|
|
# Forgot password link must be present on login page |
10
|
|
|
url = base_url + '/accounts/login/' |
11
|
|
|
browser.visit(url) |
12
|
|
|
forgot_pass_link = browser.find_by_text('Forgot Password?')[0] |
13
|
|
|
assert forgot_pass_link |
14
|
|
|
|
15
|
|
|
# When clicking on the link it should open a page and prompt for email |
16
|
|
|
forgot_pass_link.click() |
17
|
|
|
assert 'Password Reset' in browser.title |
18
|
|
|
browser.fill('email', '[email protected]') |
19
|
|
|
browser.find_by_css('[type=submit]')[0].click() |
20
|
|
|
assert browser.is_text_present( |
21
|
|
|
'The e-mail address is not assigned to any user account') |
22
|
|
|
assert len(outbox) == 0 |
23
|
|
|
|
24
|
|
|
# Now, enter a valid email |
25
|
|
|
browser.fill('email', user.email) |
26
|
|
|
browser.find_by_css('button[type=submit]')[0].click() |
27
|
|
|
assert browser.is_text_present('We have sent you an e-mail.') |
28
|
|
|
assert len(outbox) == 1 |
29
|
|
|
mail = outbox[0] |
30
|
|
|
reset_link = re.findall(r'http.*/reset/.*/', mail.body) |
31
|
|
|
assert reset_link |
32
|
|
|
|
33
|
|
|
browser.visit(reset_link[0]) |
34
|
|
|
assert "Change Password" in browser.title |
35
|
|
|
assert browser.is_text_present('Change Password') |
36
|
|
|
browser.fill('password1', 'mynewpassword') |
37
|
|
|
browser.fill('password2', 'mynewpassword_wrong') |
38
|
|
|
browser.find_by_css('[type=submit]')[0].click() |
39
|
|
|
assert browser.is_text_present( |
40
|
|
|
'You must type the same password each time.') |
41
|
|
|
browser.fill('password1', 'mynewpassword') |
42
|
|
|
browser.fill('password2', 'mynewpassword') |
43
|
|
|
browser.find_by_css('[type=submit]')[0].click() |
44
|
|
|
assert browser.is_text_present('Your password is now changed.') |
45
|
|
|
|