Example #1
0
    def test_course_has_not_started_if_start_date_is_in_the_future(self):
        start_date = (get_now() + timedelta(days=1)).date()
        end_date = (get_now() + timedelta(days=2)).date()

        course = CourseFactory(start_date=start_date, end_date=end_date)

        self.assertFalse(course.has_started)
Example #2
0
    def test_course_has_started_if_start_date_is_today(self):
        start_date = get_now().date()
        end_date = (get_now() + timedelta(days=1)).date()

        course = CourseFactory(start_date=start_date, end_date=end_date)

        self.assertTrue(course.has_started)
Example #3
0
class CourseFactory(factory.DjangoModelFactory):
    name = factory.Sequence(lambda n: f'{n}{faker.word()}')
    start_date = factory.LazyAttribute(
        lambda _: get_now()
    )
    end_date = factory.LazyAttribute(
        lambda _: get_now() + timedelta(days=30)
    )

    slug_url = factory.Sequence(lambda n: f'{n}{faker.slug()}')

    repository = factory.LazyAttribute(lambda _: faker.url())
    video_channel = factory.LazyAttribute(lambda _: faker.url())
    facebook_group = factory.LazyAttribute(lambda _: faker.url())

    class Meta:
        model = Course

    @classmethod
    def _build(cls, model_class, *args, **kwargs):
        return kwargs

    @classmethod
    def _create(cls, model_class, *args, **kwargs):
        return create_course(**kwargs)
Example #4
0
    def test_course_end_date_cannot_be_before_start_date(self):
        start_date = get_now()
        end_date = get_now() - timedelta(days=1)

        course_data = CourseFactory.build()
        course_data['start_date'] = start_date
        course_data['end_date'] = end_date

        course = Course(**course_data)

        with self.assertRaises(ValidationError):
            course.full_clean()
Example #5
0
    def can_generate_certificates(self):
        now = get_now()

        return now.date() <= self.end_date + self.generate_certificates_delta
Example #6
0
    def has_finished(self):
        now = get_now()

        return self.end_date <= now.date()
Example #7
0
    def has_started(self):
        now = get_now()

        return self.start_date <= now.date()
Example #8
0
    def test_duration_in_weeks_should_return_three(self):
        start_date = get_now().date()
        end_date = (get_now() + timedelta(days=14)).date()
        course2 = CourseFactory(start_date=start_date, end_date=end_date)

        self.assertEqual(3, course2.duration_in_weeks)
Example #9
0
    def test_can_generate_certificates_with_end_date_outside_time_gap(self):
        start_date = (get_now() - timedelta(days=30)).date()
        end_date = (get_now() - timedelta(days=16)).date()
        course = CourseFactory(start_date=start_date, end_date=end_date)

        self.assertFalse(course.can_generate_certificates)
Example #10
0
    def test_can_generate_certificates_with_end_date_in_time_gap(self):
        start_date = (get_now() + timedelta(days=1)).date()
        end_date = (get_now() + timedelta(days=2)).date()
        course = CourseFactory(start_date=start_date, end_date=end_date)

        self.assertTrue(course.can_generate_certificates)
Example #11
0
    def test_course_has_finished_with_end_date_bigger_than_today(self):
        start_date = (get_now() + timedelta(days=1)).date()
        end_date = (get_now() + timedelta(days=2)).date()
        course = CourseFactory(start_date=start_date, end_date=end_date)

        self.assertFalse(course.has_finished)
Example #12
0
    def test_course_has_finished_with_end_date_today(self):
        start_date = (get_now() - timedelta(days=1)).date()
        end_date = get_now().date()
        course = CourseFactory(start_date=start_date, end_date=end_date)

        self.assertTrue(course.has_finished)