|
3 | 3 |
|
4 | 4 | import pytest |
5 | 5 | from django.core.files.uploadedfile import SimpleUploadedFile |
6 | | -from django.template.defaultfilters import date |
7 | | -from django.urls import reverse |
8 | 6 | from django.utils import timezone |
9 | 7 | from model_bakery import baker |
10 | 8 |
|
11 | 9 | from pythonpro.cohorts import facade |
12 | | -from pythonpro.cohorts.models import Cohort, LiveClass, Webinar |
| 10 | +from pythonpro.cohorts.models import LiveClass, Webinar |
13 | 11 | from pythonpro.cohorts.tests.conftest import img_path |
14 | | -from pythonpro.django_assertions import dj_assert_contains, dj_assert_not_contains |
15 | | - |
16 | | - |
17 | | -@pytest.fixture |
18 | | -def resp(client_with_member, cohort): |
19 | | - return client_with_member.get(reverse('cohorts:detail', kwargs={'slug': cohort.slug})) |
20 | | - |
21 | | - |
22 | | -@pytest.fixture |
23 | | -def resp_without_user(client, db): |
24 | | - image = SimpleUploadedFile(name='renzo-nuccitelli.jpeg', content=open(img_path, 'rb').read(), |
25 | | - content_type='image/png') |
26 | | - cohort = baker.make(Cohort, slug='guido-van-rossum', image=image) |
27 | | - resp = client.get(reverse('cohorts:detail', kwargs={'slug': cohort.slug})) |
28 | | - return resp |
29 | | - |
30 | | - |
31 | | -def test_no_access(resp_without_user): |
32 | | - """Assert only logged user can acess cohort pages""" |
33 | | - assert 302 == resp_without_user.status_code |
34 | | - |
35 | | - |
36 | | -def test_cohort_links_for_logged_user(client, django_user_model): |
37 | | - user = baker.make(django_user_model) |
38 | | - client.force_login(user) |
39 | | - image = SimpleUploadedFile(name='renzo-nuccitelli.jpeg', content=open(img_path, 'rb').read(), |
40 | | - content_type='image/png') |
41 | | - cohorts = baker.make(Cohort, 4, image=image) |
42 | | - resp = client.get(reverse('dashboard:home')) |
43 | | - for c in cohorts: |
44 | | - dj_assert_contains(resp, c.get_absolute_url()) |
45 | | - |
46 | | - |
47 | | -def test_status_code(resp): |
48 | | - assert 200 == resp.status_code |
49 | 12 |
|
50 | 13 |
|
51 | 14 | def test_str(cohort): |
52 | 15 | assert str(cohort) == f'Turma: {cohort.title}' |
53 | 16 |
|
54 | 17 |
|
55 | | -@pytest.mark.parametrize('property_name', 'title forum_post'.split()) |
56 | | -def test_cohort_properties(cohort, resp, property_name): |
57 | | - dj_assert_contains(resp, getattr(cohort, property_name)) |
58 | | - |
59 | | - |
60 | | -def test_cohort_img(cohort: Cohort, resp): |
61 | | - dj_assert_contains(resp, cohort.image.url) |
62 | | - |
63 | | - |
64 | | -def test_cohort_start(cohort: Cohort, resp): |
65 | | - dj_assert_contains(resp, date(cohort.start)) |
66 | | - |
67 | | - |
68 | | -def test_cohort_end(cohort: Cohort, resp): |
69 | | - dj_assert_contains(resp, date(cohort.end)) |
70 | | - |
71 | | - |
72 | 18 | @pytest.fixture |
73 | 19 | def recorded_live_classes(cohort, fake): |
74 | 20 | now = timezone.now() |
@@ -103,38 +49,12 @@ def future_live_classes(cohort, fake): |
103 | 49 | ] |
104 | 50 |
|
105 | 51 |
|
106 | | -@pytest.fixture |
107 | | -def resp_with_classes(recorded_live_classes, future_live_classes, cohort, client_with_member): |
108 | | - return client_with_member.get(reverse('cohorts:detail', kwargs={'slug': cohort.slug})) |
109 | | - |
110 | | - |
111 | 52 | def test_live_classes_are_sorted(recorded_live_classes, cohort): |
112 | 53 | recorded_live_classes.sort(key=operator.attrgetter('start')) |
113 | 54 | db_cohort = facade.find_cohort(slug=cohort.slug) |
114 | 55 | assert recorded_live_classes == db_cohort.classes |
115 | 56 |
|
116 | 57 |
|
117 | | -@pytest.mark.freeze_time('2019-01-01 18:00:00') |
118 | | -def test_live_classes_datetime(resp_with_classes, recorded_live_classes): |
119 | | - for live_class in recorded_live_classes: |
120 | | - dj_assert_contains(resp_with_classes, date(live_class.start)) |
121 | | - |
122 | | - |
123 | | -def test_live_classes_descriptions(resp_with_classes, recorded_live_classes): |
124 | | - for live_class in recorded_live_classes: |
125 | | - dj_assert_contains(resp_with_classes, live_class.description) |
126 | | - |
127 | | - |
128 | | -def test_recorded_live_classes_urls_are_present(resp_with_classes, recorded_live_classes): |
129 | | - for live_class in recorded_live_classes: |
130 | | - dj_assert_contains(resp_with_classes, live_class.get_absolute_url()) |
131 | | - |
132 | | - |
133 | | -def test_future_live_classes_urls_are_absent(resp_with_classes, future_live_classes): |
134 | | - for live_class in future_live_classes: |
135 | | - dj_assert_not_contains(resp_with_classes, live_class.get_absolute_url()) |
136 | | - |
137 | | - |
138 | 58 | @pytest.fixture |
139 | 59 | def recorded_webinars(cohort): |
140 | 60 | now = timezone.now() |
@@ -167,34 +87,7 @@ def test_future_webinars_in_cohort(recorded_webinars, future_webinars, cohort): |
167 | 87 | assert cohort.future_webinars == future_webinars |
168 | 88 |
|
169 | 89 |
|
170 | | -@pytest.fixture |
171 | | -def resp_with_webnars(recorded_webinars, future_webinars, cohort, client_with_member): |
172 | | - return client_with_member.get(reverse('cohorts:detail', kwargs={'slug': cohort.slug})) |
173 | | - |
174 | | - |
175 | 90 | def test_webnars_are_sorted(recorded_webinars: list, cohort): |
176 | 91 | recorded_webinars.sort(key=operator.attrgetter('start')) |
177 | 92 | db_cohort = facade.find_cohort(slug=cohort.slug) |
178 | 93 | assert recorded_webinars == db_cohort.webinars |
179 | | - |
180 | | - |
181 | | -@pytest.mark.freeze_time('2019-01-01 18:00:00') |
182 | | -def test_webnars_datetime(resp_with_webnars, recorded_webinars): |
183 | | - for webnar in recorded_webinars: |
184 | | - dj_assert_contains(resp_with_webnars, date(webnar.start)) |
185 | | - |
186 | | - |
187 | | -@pytest.mark.parametrize('property_name', 'speaker speaker_title title'.split()) |
188 | | -def test_webnars_vimeo(resp_with_webnars, recorded_webinars, property_name): |
189 | | - for webnar in recorded_webinars: |
190 | | - dj_assert_contains(resp_with_webnars, getattr(webnar, property_name)) |
191 | | - |
192 | | - |
193 | | -def test_recorded_webnars_url_are_present(resp_with_webnars, recorded_webinars): |
194 | | - for webnar in recorded_webinars: |
195 | | - dj_assert_contains(resp_with_webnars, webnar.get_absolute_url()) |
196 | | - |
197 | | - |
198 | | -def test_future_webnars_url_are_absent(resp_with_webnars, future_webinars): |
199 | | - for webnar in future_webinars: |
200 | | - dj_assert_not_contains(resp_with_webnars, webnar.get_absolute_url()) |
0 commit comments