|
| 1 | +import operator |
| 2 | +from datetime import datetime, timedelta |
1 | 3 | from os import path |
2 | 4 |
|
3 | 5 | import pytest |
|
7 | 9 | from model_mommy import mommy |
8 | 10 |
|
9 | 11 | from pythonpro import settings |
10 | | -from pythonpro.cohorts.models import Cohort |
| 12 | +from pythonpro.cohorts import facade |
| 13 | +from pythonpro.cohorts.models import Cohort, LiveClass |
11 | 14 | from pythonpro.django_assertions import dj_assert_contains, dj_assert_not_contains |
12 | 15 |
|
13 | 16 | _img_path = path.join(settings.BASE_DIR, 'pythonpro', 'core', 'static', 'img', 'instructors', 'renzo-nuccitelli.png') |
@@ -82,3 +85,33 @@ def test_cohort_start(cohort: Cohort, resp): |
82 | 85 |
|
83 | 86 | def test_cohort_end(cohort: Cohort, resp): |
84 | 87 | dj_assert_contains(resp, date(cohort.end)) |
| 88 | + |
| 89 | + |
| 90 | +@pytest.fixture |
| 91 | +def live_classes(cohort): |
| 92 | + now = datetime.now() |
| 93 | + return [ |
| 94 | + mommy.make(LiveClass, cohort=cohort, vimeo_id=str(i), start=now + timedelta(days=i)) for i in range(100, 105) |
| 95 | + ] |
| 96 | + |
| 97 | + |
| 98 | +@pytest.fixture |
| 99 | +def resp_with_classes(live_classes, cohort, client): |
| 100 | + assert len(live_classes) > 0 |
| 101 | + return client.get(reverse('cohorts:detail', kwargs={'slug': cohort.slug}), secure=True) |
| 102 | + |
| 103 | + |
| 104 | +def test_live_classes_are_sorted(live_classes: list, cohort): |
| 105 | + live_classes.sort(key=operator.attrgetter('start')) |
| 106 | + db_cohort = facade.find_cohort(slug=cohort.slug) |
| 107 | + assert live_classes == db_cohort.classes |
| 108 | + |
| 109 | + |
| 110 | +def test_live_classes_datetime(resp_with_classes, live_classes): |
| 111 | + for live_class in live_classes: |
| 112 | + dj_assert_contains(resp_with_classes, date(live_class.start)) |
| 113 | + |
| 114 | + |
| 115 | +def test_live_classes_vimeo(resp_with_classes, live_classes): |
| 116 | + for live_class in live_classes: |
| 117 | + dj_assert_contains(resp_with_classes, live_class.vimeo_id) |
0 commit comments