Beispiel #1
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)
Beispiel #2
0
 def test_course_is_created_successfully_with_valid_data(self):
     start_date = parser.parse(faker.date())
     count = Course.objects.count()
     data = {
         'name': faker.word(),
         'start_date': start_date,
         'end_date': start_date + timedelta(days=faker.pyint()),
         'repository': faker.url(),
         'video_channel': faker.url(),
         'facebook_group': faker.url(),
         'slug_url': faker.slug(),
     }
     create_course(**data)
     self.assertEqual(count + 1, Course.objects.count())
Beispiel #3
0
 def test_create_course_creates_weeks_for_course_successfully(self):
     start_date = parser.parse(faker.date())
     count = Course.objects.count()
     data = {
         'name': faker.word(),
         'start_date': start_date,
         'end_date': start_date + timedelta(days=faker.pyint()),
         'repository': faker.url(),
         'video_channel': faker.url(),
         'facebook_group': faker.url(),
         'slug_url': faker.slug(),
     }
     course = create_course(**data)
     weeks = course.duration_in_weeks
     self.assertEqual(count + 1, Course.objects.count())
     self.assertEqual(weeks, Week.objects.count())
Beispiel #4
0
 def test_create_course_raises_error_on_duplicate_name(self):
     start_date = parser.parse(faker.date())
     course = CourseFactory()
     count = Course.objects.count()
     data = {
         'name': course.name,
         'start_date': start_date,
         'end_date': start_date + timedelta(days=faker.pyint()),
         'repository': faker.url(),
         'video_channel': faker.url(),
         'facebook_group': faker.url(),
         'slug_url': faker.slug(),
     }
     with self.assertRaises(ValidationError):
         create_course(**data)
     self.assertEqual(count, Course.objects.count())
Beispiel #5
0
 def test_create_course_starts_week_from_monday(self):
     start_date = parser.parse(faker.date())
     data = {
         'name': faker.word(),
         'start_date': start_date,
         'end_date': start_date + timedelta(days=faker.pyint()),
         'repository': faker.url(),
         'video_channel': faker.url(),
         'facebook_group': faker.url(),
         'slug_url': faker.slug(),
     }
     course = create_course(**data)
     weeks = course.duration_in_weeks
     self.assertEqual(1, Course.objects.count())
     self.assertEqual(weeks, Week.objects.count())
     week_one = Week.objects.first()
     self.assertEqual(0, week_one.start_date.weekday())
Beispiel #6
0
class SolutionFactory(factory.DjangoModelFactory):
    task = factory.SubFactory(IncludedTaskFactory)
    user = factory.SubFactory(BaseUserFactory)
    url = factory.LazyAttribute(lambda _: faker.url())
    code = factory.LazyAttribute(lambda _: faker.text())
    build_id = factory.LazyAttribute(lambda _: faker.pyint())
    test_output = factory.LazyAttribute(lambda _: faker.text())

    class Meta:
        model = Solution
Beispiel #7
0
    def test_create_non_gradable_solution_creates_non_gradable_solution_with_url_when_url_is_provided(
            self):
        current_solution_count = Solution.objects.count()

        solution = create_non_gradable_solution(task=self.task,
                                                user=self.user,
                                                url=faker.url())

        self.assertEqual(current_solution_count + 1, Solution.objects.count())
        self.assertIsNotNone(solution.url)
        self.assertIsNone(solution.file.name)
        self.assertIsNone(solution.code)
Beispiel #8
0
 def test_create_included_material_creates_material_and_included_material_when_no_existing_is_provided(
         self):
     current_material_count = Material.objects.count()
     current_included_material_count = IncludedMaterial.objects.count()
     create_included_material(identifier=faker.word(),
                              url=faker.url(),
                              content=faker.text(),
                              week=self.week,
                              course=self.course)
     self.assertEqual(current_material_count + 1, Material.objects.count())
     self.assertEqual(current_included_material_count + 1,
                      IncludedMaterial.objects.count())
Beispiel #9
0
 def setUp(self):
     self.course = CourseFactory()
     self.week = WeekFactory(course=self.course)
     self.material = Material.objects.create(identifier="TestMaterial",
                                             url=faker.url(),
                                             content=faker.text())