1
|
|
|
import pytest |
|
|
|
|
2
|
|
|
|
3
|
|
|
from djoser import pipelines |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
def test_valid_activation_email_without_request(test_user, mailoutbox): |
|
|
|
|
7
|
|
|
context = {'user': test_user} |
8
|
|
|
assert test_user.is_active is True |
9
|
|
|
|
10
|
|
|
pipelines.email.activation_email(request=None, context=context) |
11
|
|
|
test_user.refresh_from_db() |
12
|
|
|
|
13
|
|
|
assert len(mailoutbox) == 1 |
14
|
|
|
assert mailoutbox[0].to == [test_user.email] |
15
|
|
|
assert test_user.is_active is False |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
def test_failed_activation_email_user_without_email(test_user, mailoutbox): |
|
|
|
|
19
|
|
|
test_user.email = '' |
20
|
|
|
context = {'user': test_user} |
21
|
|
|
pipelines.email.activation_email(request=None, context=context) |
22
|
|
|
assert len(mailoutbox) == 0 |
|
|
|
|
23
|
|
|
|
24
|
|
|
|
25
|
|
|
def test_failed_activation_email_user_empty_context(): |
|
|
|
|
26
|
|
|
context = {} |
27
|
|
|
with pytest.raises(AssertionError): |
28
|
|
|
pipelines.email.activation_email(request=None, context=context) |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
def test_valid_confirmation_email_without_request(test_user, mailoutbox): |
|
|
|
|
32
|
|
|
context = {'user': test_user} |
33
|
|
|
assert test_user.is_active is True |
34
|
|
|
|
35
|
|
|
pipelines.email.confirmation_email(request=None, context=context) |
36
|
|
|
test_user.refresh_from_db() |
37
|
|
|
|
38
|
|
|
assert len(mailoutbox) == 1 |
39
|
|
|
assert mailoutbox[0].to == [test_user.email] |
40
|
|
|
assert test_user.is_active is True |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
def test_failed_confirmation_email_user_without_email(test_user, mailoutbox): |
|
|
|
|
44
|
|
|
test_user.email = '' |
45
|
|
|
context = {'user': test_user} |
46
|
|
|
pipelines.email.confirmation_email(request=None, context=context) |
47
|
|
|
assert len(mailoutbox) == 0 |
|
|
|
|
48
|
|
|
|
49
|
|
|
|
50
|
|
|
def test_failed_confirmation_email_user_empty_context(): |
|
|
|
|
51
|
|
|
context = {} |
52
|
|
|
with pytest.raises(AssertionError): |
53
|
|
|
pipelines.email.confirmation_email(request=None, context=context) |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
def test_valid_password_reset_email_without_request(test_user, mailoutbox): |
|
|
|
|
57
|
|
|
context = {'user': test_user} |
58
|
|
|
assert test_user.is_active is True |
59
|
|
|
|
60
|
|
|
pipelines.email.password_reset_email(request=None, context=context) |
61
|
|
|
test_user.refresh_from_db() |
62
|
|
|
|
63
|
|
|
assert len(mailoutbox) == 1 |
64
|
|
|
assert mailoutbox[0].to == [test_user.email] |
65
|
|
|
assert test_user.is_active is True |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
def test_failed_password_reset_email_user_without_email(test_user, mailoutbox): |
|
|
|
|
69
|
|
|
test_user.email = '' |
70
|
|
|
context = {'user': test_user} |
71
|
|
|
pipelines.email.password_reset_email(request=None, context=context) |
72
|
|
|
assert len(mailoutbox) == 0 |
|
|
|
|
73
|
|
|
|
74
|
|
|
|
75
|
|
|
def test_failed_password_reset_email_user_empty_context(): |
|
|
|
|
76
|
|
|
context = {} |
77
|
|
|
with pytest.raises(AssertionError): |
78
|
|
|
pipelines.email.password_reset_email(request=None, context=context) |
79
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.