|
1 | 1 | import pytest |
2 | 2 | from django.core.files.uploadedfile import SimpleUploadedFile |
3 | 3 | from django.urls import reverse |
| 4 | +from django.utils import timezone |
4 | 5 | from model_bakery import baker |
5 | 6 |
|
6 | 7 | from pythonpro.cohorts.models import Webinar |
7 | 8 | from pythonpro.cohorts.tests.conftest import img_path |
8 | | -from pythonpro.django_assertions import dj_assert_contains, dj_assert_not_contains |
| 9 | +from pythonpro.memberkit.models import Subscription |
9 | 10 |
|
10 | 11 |
|
11 | 12 | @pytest.fixture |
12 | 13 | def webinar(cohort) -> Webinar: |
13 | 14 | image = SimpleUploadedFile(name='renzo-nuccitelli.jpeg', content=open(img_path, 'rb').read(), |
14 | 15 | content_type='image/png') |
15 | | - return baker.make(Webinar, cohort=cohort, image=image, vimeo_id='1') |
| 16 | + return baker.make(Webinar, cohort=cohort, image=image, vimeo_id='1', memberkit_url='https://plataforma.dev.pro.br') |
16 | 17 |
|
17 | 18 |
|
18 | 19 | @pytest.fixture |
19 | | -def resp(client_with_level_three_roles, webinar: Webinar): |
20 | | - return client_with_level_three_roles.get(reverse('cohorts:webinar', kwargs={'slug': webinar.slug})) |
| 20 | +def resp(client_with_user, webinar: Webinar): |
| 21 | + return client_with_user.get(reverse('cohorts:webinar', kwargs={'slug': webinar.slug})) |
21 | 22 |
|
22 | 23 |
|
23 | | -def test_logged_user(resp): |
24 | | - assert resp.status_code == 200 |
| 24 | +def test_logged_user(resp, webinar): |
| 25 | + assert resp.status_code == 302 |
| 26 | + assert resp.url == reverse('checkout:bootcamp_lp') |
25 | 27 |
|
26 | 28 |
|
27 | 29 | def test_link_unavailable_for_non_users(client): |
28 | 30 | resp = client.get(reverse('cohorts:webinar', kwargs={'slug': 'foo'})) |
29 | 31 | assert resp.status_code == 302 |
30 | 32 |
|
31 | 33 |
|
32 | | -@pytest.mark.parametrize('property_name', 'speaker speaker_title title description vimeo_id discourse_topic_id'.split()) |
33 | | -def test_basic_contents(resp, webinar, property_name): |
34 | | - dj_assert_contains(resp, getattr(webinar, property_name)) |
35 | | - |
36 | | - |
37 | | -@pytest.fixture |
38 | | -def resp_video_not_recorded(client_with_level_three_roles, webinar: Webinar): |
39 | | - webinar.vimeo_id = '' |
40 | | - webinar.save() |
41 | | - return client_with_level_three_roles.get(reverse('cohorts:webinar', kwargs={'slug': webinar.slug})) |
42 | | - |
43 | | - |
44 | | -def test_pending_webinar_msg(resp_video_not_recorded): |
45 | | - dj_assert_contains( |
46 | | - resp_video_not_recorded, |
47 | | - 'Ainda não temos máquina do tempo, esse webinário ainda não foi gravado' |
| 34 | +def test_redirect_user_not_migrated_to_memberkit(client_with_user, webinar, logged_user): |
| 35 | + baker.make( |
| 36 | + Subscription, |
| 37 | + subscriber=logged_user, |
| 38 | + activated_at=None, |
| 39 | + memberkit_user_id=None |
48 | 40 | ) |
49 | | - |
50 | | - |
51 | | -def test_vimeo_player_not_present(resp_video_not_recorded): |
52 | | - dj_assert_not_contains( |
53 | | - resp_video_not_recorded, |
54 | | - 'src="https://player.vimeo.com/video/"' |
| 41 | + resp = client_with_user.get(reverse('cohorts:webinar', kwargs={'slug': webinar.slug})) |
| 42 | + assert resp.status_code == 301 |
| 43 | + assert resp.url == reverse('migrate_to_memberkit') |
| 44 | + |
| 45 | + |
| 46 | +def test_python_birds_migrated_user(client_with_user, webinar, logged_user): |
| 47 | + baker.make( |
| 48 | + Subscription, |
| 49 | + status=Subscription.Status.ACTIVE, |
| 50 | + subscriber=logged_user, |
| 51 | + activated_at=timezone.now(), |
| 52 | + memberkit_user_id=1 |
55 | 53 | ) |
56 | | - |
57 | | - |
58 | | -@pytest.fixture |
59 | | -def resp_not_level_three(client_with_not_level_three_roles, webinar: Webinar, logged_user): |
60 | | - return client_with_not_level_three_roles.get(reverse('cohorts:webinar', kwargs={'slug': webinar.slug})) |
61 | | - |
62 | | - |
63 | | -def test_webinar_landing_for_client(cohort, resp_not_level_three): |
64 | | - assert resp_not_level_three.status_code == 302 |
65 | | - assert resp_not_level_three.url == reverse('checkout:bootcamp_lp') |
| 54 | + resp = client_with_user.get(reverse('cohorts:webinar', kwargs={'slug': webinar.slug})) |
| 55 | + assert resp.status_code == 301 |
| 56 | + assert resp.url == webinar.memberkit_url |
0 commit comments