1
|
|
|
import pytest |
|
|
|
|
2
|
|
|
|
3
|
|
|
from djoser import pipelines |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
def test_valid_activation_email_without_request(test_user, mailoutbox): |
|
|
|
|
7
|
|
|
context = {'request': None, 'user': test_user} |
8
|
|
|
assert test_user.is_active is True |
9
|
|
|
|
10
|
|
|
pipelines.email.activation_email(**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 = {'request': None, 'user': test_user} |
21
|
|
|
pipelines.email.activation_email(**context) |
22
|
|
|
assert len(mailoutbox) == 0 |
|
|
|
|
23
|
|
|
|
24
|
|
|
|
25
|
|
|
def test_failed_activation_email_context_missing_user(): |
|
|
|
|
26
|
|
|
context = {'request': None} |
27
|
|
|
with pytest.raises(TypeError): |
28
|
|
|
pipelines.email.activation_email(**context) |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
def test_failed_activation_email_context_missing_request(): |
|
|
|
|
32
|
|
|
context = {'user': None} |
33
|
|
|
with pytest.raises(TypeError): |
34
|
|
|
pipelines.email.activation_email(**context) |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
def test_valid_confirmation_email_without_request(test_user, mailoutbox): |
|
|
|
|
38
|
|
|
context = {'request': None, 'user': test_user} |
39
|
|
|
assert test_user.is_active is True |
40
|
|
|
|
41
|
|
|
pipelines.email.confirmation_email(**context) |
42
|
|
|
test_user.refresh_from_db() |
43
|
|
|
|
44
|
|
|
assert len(mailoutbox) == 1 |
45
|
|
|
assert mailoutbox[0].to == [test_user.email] |
46
|
|
|
assert test_user.is_active is True |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
def test_failed_confirmation_email_user_without_email(test_user, mailoutbox): |
|
|
|
|
50
|
|
|
test_user.email = '' |
51
|
|
|
context = {'request': None, 'user': test_user} |
52
|
|
|
pipelines.email.confirmation_email(**context) |
53
|
|
|
assert len(mailoutbox) == 0 |
|
|
|
|
54
|
|
|
|
55
|
|
|
|
56
|
|
|
def test_failed_confirmation_email_context_missing_user(): |
|
|
|
|
57
|
|
|
context = {'request': None} |
58
|
|
|
with pytest.raises(TypeError): |
59
|
|
|
pipelines.email.confirmation_email(**context) |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
def test_failed_confirmation_email_context_missing_request(): |
|
|
|
|
63
|
|
|
context = {'user': None} |
64
|
|
|
with pytest.raises(TypeError): |
65
|
|
|
pipelines.email.confirmation_email(**context) |
66
|
|
|
|
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.