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) as e: |
|
|
|
|
28
|
|
|
pipelines.email.activation_email(**context) |
29
|
|
|
|
30
|
|
|
assert "missing 1 required positional argument: 'user'" in str(e.value) |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
def test_failed_activation_email_context_missing_request(): |
|
|
|
|
34
|
|
|
context = {'user': None} |
35
|
|
|
with pytest.raises(TypeError) as e: |
|
|
|
|
36
|
|
|
pipelines.email.activation_email(**context) |
37
|
|
|
|
38
|
|
|
assert "missing 1 required positional argument: 'request'" in str(e.value) |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
def test_valid_confirmation_email_without_request(test_user, mailoutbox): |
|
|
|
|
42
|
|
|
context = {'request': None, 'user': test_user} |
43
|
|
|
assert test_user.is_active is True |
44
|
|
|
|
45
|
|
|
pipelines.email.confirmation_email(**context) |
46
|
|
|
test_user.refresh_from_db() |
47
|
|
|
|
48
|
|
|
assert len(mailoutbox) == 1 |
49
|
|
|
assert mailoutbox[0].to == [test_user.email] |
50
|
|
|
assert test_user.is_active is True |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
def test_failed_confirmation_email_user_without_email(test_user, mailoutbox): |
|
|
|
|
54
|
|
|
test_user.email = '' |
55
|
|
|
context = {'request': None, 'user': test_user} |
56
|
|
|
pipelines.email.confirmation_email(**context) |
57
|
|
|
assert len(mailoutbox) == 0 |
|
|
|
|
58
|
|
|
|
59
|
|
|
|
60
|
|
|
def test_failed_confirmation_email_context_missing_user(): |
|
|
|
|
61
|
|
|
context = {'request': None} |
62
|
|
|
with pytest.raises(TypeError) as e: |
|
|
|
|
63
|
|
|
pipelines.email.confirmation_email(**context) |
64
|
|
|
|
65
|
|
|
assert "missing 1 required positional argument: 'user'" in str(e.value) |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
def test_failed_confirmation_email_context_missing_request(): |
|
|
|
|
69
|
|
|
context = {'user': None} |
70
|
|
|
with pytest.raises(TypeError) as e: |
|
|
|
|
71
|
|
|
pipelines.email.confirmation_email(**context) |
72
|
|
|
|
73
|
|
|
assert "missing 1 required positional argument: 'request'" in str(e.value) |
|
|
|
|
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.