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)
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)
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)
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()
def can_generate_certificates(self): now = get_now() return now.date() <= self.end_date + self.generate_certificates_delta
def has_finished(self): now = get_now() return self.end_date <= now.date()
def has_started(self): now = get_now() return self.start_date <= now.date()
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)
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)
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)
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)
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)