forked from pythonprobr/pythonpro-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_view_profile.py
More file actions
78 lines (51 loc) · 1.98 KB
/
test_view_profile.py
File metadata and controls
78 lines (51 loc) · 1.98 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
import pytest
from django.test import Client
from django.urls import reverse
from model_bakery import baker
from pythonpro.django_assertions import dj_assert_contains
@pytest.fixture
def resp(client: Client):
return _resp(client)
def _resp(client):
"""Plain function to avoid _pytest.warning_types.RemovedInPytest4Warning: Fixture "resp" called directly."""
return client.get(reverse('core:profile'))
@pytest.fixture
def user(django_user_model):
usr = baker.make(django_user_model)
return usr
@pytest.fixture
def resp_with_user(user, client: Client):
client.force_login(user)
return _resp(client)
def test_profile_not_logged_user(resp):
assert 302 == resp.status_code
def test_profile_status_code(resp_with_user):
assert 200 == resp_with_user.status_code
def test_profile_first_name(user, resp_with_user):
dj_assert_contains(resp_with_user, user.first_name)
def test_profile_email(user, resp_with_user):
dj_assert_contains(resp_with_user, user.email)
def test_edit_name_link(resp_with_user):
dj_assert_contains(resp_with_user, reverse('core:profile_name'))
def test_edit_email_link(resp_with_user):
dj_assert_contains(resp_with_user, reverse('core:profile_email'))
def test_edit_password_link(resp_with_user):
dj_assert_contains(resp_with_user, reverse('core:profile_password'))
@pytest.fixture
def user_with_plain_password(django_user_model):
plain_password = 'senha'
u = baker.make(django_user_model)
u.set_password(plain_password)
u.plain_password = plain_password
u.save()
return u
def test_email_normalization(user_with_plain_password, client, django_user_model):
client.force_login(user_with_plain_password)
email = 'ALUNO@PYTHON.PRO.BR'
client.post(
reverse('core:profile_email'),
{'email': email, 'current_password': user_with_plain_password.plain_password},
secure=True
)
saved_user = django_user_model.objects.first()
assert saved_user.email == email.lower()