Repository navigation
Expand file tree
/
Copy pathtest_bootcamp_vip_landing_page.py
More file actions
101 lines (73 loc) · 3.24 KB
/
Copy pathtest_bootcamp_vip_landing_page.py
File metadata and controls
101 lines (73 loc) · 3.24 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from unittest import mock
import pytest
from django.urls import reverse
from pythonpro.django_assertions import dj_assert_contains
@pytest.fixture
def client(client, cohort):
return client
def test_should_return_200_when_load_invite_page(client):
resp = client.get(reverse('pages:bootcamp_vip_landing_page'))
assert resp.status_code == 200
def test_should_return_200_when_load_thank_you_page(client):
resp = client.get(reverse('pages:bootcamp_vip_thank_you_page'))
assert resp.status_code == 200
def test_should_load_name_and_email_when_it_comes_by_GET(client):
resp = client.get(reverse('pages:bootcamp_vip_landing_page'), data={
'name': 'Moacir', 'email': 'moacir@python.pro.br', 'phone': '(11) 99999-9999'
})
dj_assert_contains(resp, 'Moacir')
dj_assert_contains(resp, 'moacir@python.pro.br')
dj_assert_contains(resp, '(11) 99999-9999')
def test_should_load_name_and_email_when_user_is_logged(client_with_user, logged_user):
resp = client_with_user.get(reverse('pages:bootcamp_vip_landing_page'))
dj_assert_contains(resp, logged_user.first_name)
dj_assert_contains(resp, logged_user.email)
def test_should_load_name_and_email_from_GET_when_user_is_logged(client_with_user, logged_user):
resp = client_with_user.get(reverse('pages:bootcamp_vip_landing_page'), data={
'name': 'Moacir', 'email': 'moacir@python.pro.br', 'phone': '(11) 99999-9999'
})
dj_assert_contains(resp, 'Moacir')
dj_assert_contains(resp, 'moacir@python.pro.br')
dj_assert_contains(resp, '(11) 99999-9999')
@pytest.fixture
def subscribe_with_no_role(mocker):
return mocker.patch('pythonpro.pages.views.create_or_update_with_no_role.delay')
# TODO: move this phone tests do generic context
def test_should_call_update_when_with_correct_parameters(subscribe_with_no_role, client):
client.post(
reverse('pages:bootcamp_vip_landing_page'),
{'name': 'Moacir', 'email': 'moacir@python.pro.br', 'phone': '(11) 99999-9999'},
secure=True
)
subscribe_with_no_role.assert_called_with(
'Moacir', 'moacir@python.pro.br', mock.ANY, phone='+5511999999999'
)
# TODO: move this phone tests do generic context
def test_should_call_update_when_logged_with_correct_parameters(subscribe_with_no_role, client_with_user):
client_with_user.post(
reverse('pages:bootcamp_vip_landing_page'),
{'name': 'Moacir', 'email': 'moacir@python.pro.br', 'phone': '(11) 99999-9999'},
secure=True
)
subscribe_with_no_role.assert_called_with(
'Moacir',
'moacir@python.pro.br',
mock.ANY,
id=mock.ANY,
phone='+5511999999999'
)
def test_should_run_form_ok(subscribe_with_no_role, client, cohort):
resp = client.post(
reverse('pages:bootcamp_vip_landing_page'),
{'name': 'Moacir', 'email': 'moacir@python.pro.br', 'phone': '(11) 99999-9999'},
secure=True
)
assert resp.status_code == 302
def test_should_inform_form_error(subscribe_with_no_role, client, cohort):
resp = client.post(
reverse('pages:bootcamp_vip_landing_page'),
{'name': 'Moacir', 'email': 'moacir@python.pro.br'},
secure=True
)
assert resp.status_code == 200
dj_assert_contains(resp, 'is-invalid')