Exemplo n.º 1
0
class ProgrammingLanguageFactory(factory.DjangoModelFactory):
    name = factory.LazyAttribute(lambda _: faker.word())
    test_format = factory.LazyAttribute(lambda _: faker.file_name())
    requirements_format = factory.LazyAttribute(lambda _: faker.file_name())

    class Meta:
        model = ProgrammingLanguage
Exemplo n.º 2
0
 def test_create_course_populates_teachers_with_superusers(self):
     start_date = faker.date_object()
     course = Course.objects.create(name=faker.word(),
                                    start_date=start_date,
                                    end_date=start_date +
                                    timezone.timedelta(days=faker.pyint()),
                                    slug_url=faker.slug())
     self.assertEqual(5, course.teachers.count())
Exemplo n.º 3
0
class ApplicationFactory(factory.DjangoModelFactory):
    application_info = factory.SubFactory(ApplicationInfoFactory)
    user = factory.SubFactory(BaseUserFactory)
    phone = factory.LazyAttribute(lambda _: faker.phone_number())
    skype = factory.LazyAttribute(lambda _: faker.word())

    class Meta:
        model = Application
Exemplo n.º 4
0
    def test_create_application_raises_validation_error_when_user_has_already_applied(
            self):
        ApplicationFactory(application_info=self.app_info, user=self.user)

        with self.assertRaises(ValidationError):
            create_application(application_info=self.app_info,
                               user=self.user,
                               skype=faker.word(),
                               full_name=faker.name())
Exemplo n.º 5
0
    def test_create_application_creates_application_when_application_is_active_and_user_has_not_applied(
            self):
        current_application_count = Application.objects.count()

        create_application(application_info=self.app_info,
                           user=self.user,
                           skype=faker.word(),
                           full_name=faker.name())

        self.assertEqual(current_application_count + 1,
                         Application.objects.count())
Exemplo n.º 6
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())
Exemplo n.º 7
0
    def test_interviews_are_generated_if_enough_free_slots(self):
        interview_count = Interview.objects.count()

        ApplicationFactory(application_info=self.application_info)
        InterviewerFreeTimeFactory(interviewer=self.interviewer)

        self.interviewer.profile.skype = faker.word()
        self.interviewer.profile.save()

        context = generate_interview_slots()
        self.assertIn(f"Generated interviews: {Interview.objects.count()}", context['log'])
        self.assertEqual(interview_count + 1, Interview.objects.count())
Exemplo n.º 8
0
    def test_no_interviews_are_generated_if_not_enough_free_slots(self):
        interview_count = Interview.objects.count()

        ApplicationFactory(application_info=self.application_info)

        self.interviewer.profile.skype = faker.word()
        self.interviewer.profile.save()

        context = generate_interview_slots()
        application_count = Application.objects.count()
        self.assertIn(f"Not enough free slots - {application_count}", context['log'])
        self.assertEqual(interview_count, Interview.objects.count())
Exemplo n.º 9
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())
Exemplo n.º 10
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())
Exemplo n.º 11
0
    def test_get_grader_ready_data_raises_validation_error_when_language_is_not_supported_and_test_is_not_source(self):
        language = ProgrammingLanguageFactory(name=faker.word())
        self.solution.code = None
        self.solution.file = SimpleUploadedFile('solution.jar', bytes(f'{faker.text()}'.encode('utf-8')))
        self.solution.save()
        BinaryFileTestFactory._create(
            IncludedTask,
            task=self.task,
            language=language
        )

        with self.assertRaises(ValidationError):
            get_grader_ready_data(
                solution_id=self.solution.id,
                solution_model=Solution,
            )
Exemplo n.º 12
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())
Exemplo n.º 13
0
class GradingHelperTests(TestCase):
    def setUp(self):
        self.task = IncludedTaskFactory()
        self.task.gradable = True
        self.task.save()
        self.solution = SolutionFactory(task=self.task)
        self.requirements = 'openpyxl==2.5.1\nFaker==0.8.12'

    def test_get_grader_ready_data_raises_validation_error_when_language_not_in_supported_and_test_is_source(self):
        language = ProgrammingLanguageFactory(name='c_sharp')
        SourceCodeTestFactory._create(
            IncludedTask,
            task=self.task,
            language=language
        )

        with self.assertRaises(ValidationError):
            get_grader_ready_data(
                solution_id=self.solution.id,
                solution_model=Solution,
            )

    @patch.dict('odin.grading.helper.TEST_TYPES', {'UNITTEST': faker.word()}, clear=True)
    def test_get_grader_ready_data_raises_validation_error_when_test_type_is_not_supported_and_test_is_source(self):

        language = ProgrammingLanguageFactory(name='python')
        SourceCodeTestFactory._create(
            IncludedTask,
            task=self.task,
            language=language
        )

        with self.assertRaises(ValidationError):
            get_grader_ready_data(
                solution_id=self.solution.id,
                solution_model=Solution,
            )

    @patch.dict('odin.grading.helper.FILE_TYPES', {'BINARY': faker.word()}, clear=True)
    def test_get_grader_ready_data_raises_validation_error_when_file_type_is_not_supported_and_test_is_source(self):

        language = ProgrammingLanguageFactory(name='ruby')
        SourceCodeTestFactory._create(
            IncludedTask,
            task=self.task,
            language=language
        )

        with self.assertRaises(ValidationError):
            get_grader_ready_data(
                solution_id=self.solution.id,
                solution_model=Solution,
            )

    def test_get_grader_ready_data_returns_problem_parameters_when_data_is_valid_and_test_is_source(self):
        language = ProgrammingLanguageFactory(name='java')
        SourceCodeTestFactory._create(
            IncludedTask,
            task=self.task,
            language=language
        )

        data = get_grader_ready_data(
            solution_id=self.solution.id,
            solution_model=Solution
        )

        self.assertIsInstance(data, dict)

    def test_get_grader_ready_data_raises_validation_error_when_language_is_not_supported_and_test_is_not_source(self):
        language = ProgrammingLanguageFactory(name=faker.word())
        self.solution.code = None
        self.solution.file = SimpleUploadedFile('solution.jar', bytes(f'{faker.text()}'.encode('utf-8')))
        self.solution.save()
        BinaryFileTestFactory._create(
            IncludedTask,
            task=self.task,
            language=language
        )

        with self.assertRaises(ValidationError):
            get_grader_ready_data(
                solution_id=self.solution.id,
                solution_model=Solution,
            )

    @patch.dict('odin.grading.helper.TEST_TYPES', {'OUTPUT_CHECKING': faker.word()})
    def test_get_grader_ready_data_raises_validation_error_when_test_type_is_not_supported_and_test_is_not_source(self):
        language = ProgrammingLanguageFactory(name='python')
        self.solution.code = None
        self.solution.file = SimpleUploadedFile('solution.jar', bytes(f'{faker.text()}'.encode('utf-8')))
        self.solution.save()
        BinaryFileTestFactory._create(
            IncludedTask,
            task=self.task,
            language=language
        )

        with self.assertRaises(ValidationError):
            get_grader_ready_data(
                solution_id=self.solution.id,
                solution_model=Solution,
            )

    @patch.dict('odin.grading.helper.FILE_TYPES', {'BINARY': faker.word()}, clear=True)
    def test_get_grader_ready_data_raises_validation_error_when_file_type_is_not_supported_and_test_is_not_source(self):
        language = ProgrammingLanguageFactory(name='ruby')
        self.solution.code = None
        self.solution.file = SimpleUploadedFile('solution.jar', bytes(f'{faker.text()}'.encode('utf-8')))
        self.solution.save()
        BinaryFileTestFactory._create(
            IncludedTask,
            task=self.task,
            language=language
        )

        with self.assertRaises(ValidationError):
            get_grader_ready_data(
                solution_id=self.solution.id,
                solution_model=Solution,
            )

    def test_get_grader_ready_data_return_problem_parameters_when_data_is_valid_and_test_is_not_source(self):
        language = ProgrammingLanguageFactory(name='java')
        self.solution.code = None
        self.solution.file = SimpleUploadedFile('solution.jar', bytes(f'{faker.text()}'.encode('utf-8')))
        self.solution.save()
        BinaryFileTestFactory._create(
            IncludedTask,
            task=self.task,
            language=language
        )

        data = get_grader_ready_data(
            solution_id=self.solution.id,
            solution_model=Solution
        )

        self.assertIsInstance(data, dict)

    def test_problem_contains_extra_options_when_has_requirements_when_data_is_valid_and_test_is_source(self):

        language = ProgrammingLanguageFactory(name='java')
        test = SourceCodeTestFactory._create(
            IncludedTask,
            task=self.task,
            language=language
        )
        test.requirements = self.requirements
        test.save()

        data = get_grader_ready_data(
            solution_id=self.solution.id,
            solution_model=Solution
        )

        self.assertIsInstance(data, dict)
        self.assertFalse(data['extra_options'] == {})