-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathtest_cpl1.py
More file actions
63 lines (40 loc) · 1.85 KB
/
test_cpl1.py
File metadata and controls
63 lines (40 loc) · 1.85 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
import pytest
from django.urls import reverse
from pythonpro.domain.user_domain import find_user_interactions
from pythonpro.launch.facade import LAUNCH_STATUS_CPL1, LAUNCH_STATUS_OPEN_CART, LAUNCH_STATUS_PPL
@pytest.fixture
def tag_as_mock(mocker):
return mocker.patch('pythonpro.domain.user_domain._email_marketing_facade.tag_as.delay')
@pytest.fixture
def launch_status_as_mock(mocker):
return mocker.patch(
'pythonpro.launch.views.get_launch_status', return_value=LAUNCH_STATUS_CPL1
)
@pytest.fixture
def resp(client, tag_as_mock, launch_status_as_mock):
return client.get(reverse('launch:cpl1'))
def test_status_code(resp):
assert 200 == resp.status_code
@pytest.fixture
def resp_with_user(client_with_user, tag_as_mock):
return client_with_user.get(reverse('launch:cpl1'))
def test_user_interaction(resp_with_user, logged_user):
assert 'CPL1' in [i.category for i in find_user_interactions(logged_user)]
def test_email_marketing_tag(resp_with_user, logged_user, tag_as_mock):
tag_as_mock.assert_called_once_with(logged_user.email, logged_user.id, 'cpl1')
@pytest.fixture
def resp_with_user_with_launch_status_open_cart(
client_with_user, tag_as_mock, launch_status_as_mock
):
launch_status_as_mock.return_value = LAUNCH_STATUS_OPEN_CART
return client_with_user.get(reverse('launch:cpl1'))
def test_should_redirect_to_subscribe(resp_with_user_with_launch_status_open_cart, resp_with_user):
assert resp_with_user.status_code == 302
@pytest.fixture
def resp_with_user_with_launch_status_ppl(
client_with_user, tag_as_mock, launch_status_as_mock
):
launch_status_as_mock.return_value = LAUNCH_STATUS_PPL
return client_with_user.get(reverse('launch:cpl1'))
def test_should_redirect_to_ppl(resp_with_user_with_launch_status_ppl, resp_with_user):
assert resp_with_user.status_code == 302