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
class MaterialFactory(factory.DjangoModelFactory): identifier = factory.Sequence(lambda n: f'{n}{faker.word()}') url = factory.Sequence(lambda n: f'{faker.url()}{n}') content = factory.LazyAttribute(lambda _: faker.text()) class Meta: model = Material
class TaskFactory(factory.DjangoModelFactory): name = factory.Sequence(lambda n: f'{n}{faker.word()}') description = factory.LazyAttribute(lambda _: faker.text()) gradable = factory.LazyAttribute(lambda _: faker.boolean()) class Meta: model = Task
def test_create_test_for_task_raises_validation_error_when_provided_task_is_not_gradable( self): with self.assertRaises(ValidationError): self.included_task.gradable = False self.included_task.save() create_test_for_task(task=self.included_task, language=self.language, code=faker.text())
def test_create_gradable_solution_raises_validation_error_when_both_resources_are_provided( self): with self.assertRaises(ValidationError): create_gradable_solution( user=self.user, task=self.task, code=faker.text(), file=SimpleUploadedFile( 'text.bin', bytes(f'{faker.text()}'.encode('utf-8'))))
def test_create_test_for_task_raises_validation_error_when_both_resources_are_provided( self): with self.assertRaises(ValidationError): create_test_for_task(task=self.included_task, language=self.language, code=faker.text(), file=SimpleUploadedFile( 'text.bin', bytes(f'{faker.text()}'.encode('utf-8'))))
class InterviewFactory(factory.DjangoModelFactory): interviewer = factory.SubFactory(InterviewerFactory) application = factory.SubFactory(ApplicationFactory) date = factory.LazyAttribute(lambda _: faker.date_object()) start_time = factory.LazyAttribute(lambda _: faker.time_object()) end_time = factory.LazyAttribute(lambda _: faker.time_object()) interviewer_time_slot = factory.SubFactory(InterviewerFreeTimeFactory) uuid = factory.LazyAttribute(lambda _: faker.uuid4()) interviewer_comment = factory.LazyAttribute(lambda _: faker.text()) class Meta: model = Interview
def test_create_gradable_solution_creates_solution_with_code_when_code_is_provided( self): current_solution_count = Solution.objects.count() solution = create_gradable_solution(task=self.task, user=self.user, code=faker.text()) self.assertEqual(current_solution_count + 1, Solution.objects.count()) self.assertIsNotNone(solution.code) self.assertIsNone(solution.file.name) self.assertIsNone(solution.url)
def test_create_included_task_creates_task_and_included_task_when_no_existing_is_provided( self): current_task_count = Task.objects.count() current_included_task_count = IncludedTask.objects.count() create_included_task(name=faker.name(), description=faker.text(), gradable=faker.boolean(), week=self.week, course=self.course) self.assertEqual(current_task_count + 1, Task.objects.count()) self.assertEqual(current_included_task_count + 1, IncludedTask.objects.count())
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())
def test_create_test_for_task_creates_source_code_test_when_code_is_provided( self): filters = {'code__isnull': False, 'file': ''} current_source_code_test_count = IncludedTest.objects.filter( **filters).count() create_test_for_task(task=self.included_task, language=self.language, code=faker.text()) self.assertEqual(current_source_code_test_count + 1, IncludedTest.objects.filter(**filters).count())
class ApplicationInfoFactory(factory.DjangoModelFactory): start_date = factory.LazyAttribute(lambda _: timezone.now().date() + timezone.timedelta(days=faker.pyint())) end_date = factory.LazyAttribute(lambda _: timezone.now().date() + timezone .timedelta(days=faker.pyint())) course = factory.SubFactory(CourseFactory) start_interview_date = factory.LazyAttribute(lambda _: timezone.now().date( ) + timezone.timedelta(days=faker.pyint())) end_interview_date = factory.LazyAttribute(lambda _: timezone.now().date( ) + timezone.timedelta(days=faker.pyint())) description = factory.LazyAttribute(lambda _: faker.text()) class Meta: model = ApplicationInfo
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())
def _create(cls, model_class, *args, **kwargs): kwargs['file'] = SimpleUploadedFile('file.jar', bytes(faker.text().encode('utf-8'))) return create_test_for_task(*args, **kwargs)
class ProfileFactory(factory.DjangoModelFactory): full_name = factory.LazyAttribute(lambda _: faker.name()) description = factory.LazyAttribute(lambda _: faker.text()) class Meta: model = Profile
def setUp(self): self.course = CourseFactory() self.week = WeekFactory(course=self.course) self.task = Task.objects.create(name="Test task", description=faker.text(), gradable=faker.boolean())
def _create(cls, model_class, *args, **kwargs): kwargs['code'] = faker.text() return create_test_for_task(*args, **kwargs)