def createSubmission(self, user, assignment): sub = Submission(assignment=assignment, submitter=user.user, notes="This is a submission.", state=Submission.SUBMITTED) sub.save() return sub
def createValidatableSubmission(self, user): ''' Create a submission that can be validated by executor. ''' sf = self.createSubmissionFile() sub = Submission(assignment=self.validatedAssignment, submitter=user.user, notes="This is a validatable submission.", state=Submission.TEST_COMPILE_PENDING, file_upload=sf) sub.save() return sub
def createValidatedSubmission(self, user, test_host='127.0.0.1'): ''' Create a submission that already has test results in the database. ''' machine = self.createTestMachine(test_host) sf = self.createTestedSubmissionFile(machine) sub = Submission(assignment=self.validatedAssignment, submitter=user.user, notes="This is an already validated submission.", state=Submission.SUBMITTED_TESTED, file_upload=sf) sub.save() return sub
def createSingleFileValidatorSubmission(self, user): ''' Create a submission that can be validated by executor, where the validator is a single file and not an archive. ''' sf = self.createSubmissionFile() sub = Submission(assignment=self.singleFileValidatorAssignment, submitter=user.user, notes=uccrap + "This is a validatable submission.", state=Submission.TEST_COMPILE_PENDING, file_upload=sf) sub.save() return sub
def createSubmission(self, user, assignment, authors=[]): sub = Submission( assignment=assignment, submitter=user.user, notes="This is a submission.", ) sub.save() if authors: [sub.authors.add(author) for author in authors] sub.save() return sub
def createValidatableSubmission(self, user): ''' Create a submission that can be validated by executor. ''' sf = self.createSubmissionFile() sub = Submission( assignment=self.validatedAssignment, submitter=user.user, notes="This is a validatable submission.", state=Submission.TEST_COMPILE_PENDING, file_upload=sf ) sub.save() return sub
def createValidatableWithSupportFilesSubmission(self, user): ''' Create a submission that can be validated by executor, which as support files in the assignment. ''' sf = self.createSubmissionFile() sub = Submission( assignment=self.validatedWithSupportFilesAssignment, submitter=user.user, notes=uccrap + "This is a validatable submission for an assignment with support files.", state=Submission.TEST_COMPILE_PENDING, file_upload=sf) sub.save() return sub
def createValidatedSubmission(self, user, test_host='127.0.0.1'): ''' Create a submission that already has test results in the database. ''' machine = self.createTestMachine(test_host) sf = self.createTestedSubmissionFile(machine) sub = Submission( assignment=self.validatedAssignment, submitter=user.user, notes="This is an already validated submission.", state=Submission.SUBMITTED_TESTED, file_upload=sf ) sub.save() return sub
def createValidatableNoArchiveSubmission(self, user): ''' Create a submission that can be validated by executor. It is not an archive and cant be compiled. This tests special executor cases, e.g. PDF report submission. ''' sf = self.createNoArchiveSubmissionFile() sub = Submission( assignment=self.validatedAssignment, submitter=user.user, notes=uccrap + "This is a validatable submission with a non-archive.", state=Submission.TEST_VALIDITY_PENDING, file_upload=sf) sub.save() return sub
def queryset(self, request, qs): qs = qs.filter( assignment__course__in=list(request.user.profile.tutor_courses())) if self.value() == 'notwithdrawn': return Submission.qs_notwithdrawn(qs) elif self.value() == 'valid': return Submission.qs_valid(qs) elif self.value() == 'tobegraded': return Submission.qs_tobegraded(qs) elif self.value() == 'gradingunfinished': return qs.filter(state__in=[Submission.GRADING_IN_PROGRESS]) elif self.value() == 'graded': return qs.filter(state__in=[Submission.GRADED]) elif self.value() == 'closed': return Submission.qs_notified(qs) else: return qs
def createCompileBrokenSubmission(self, user): ''' Create a submission that cannot be compiled. ''' sf = self.createCompileBrokenSubmissionFile() sub = Submission(assignment=self.validatedAssignment, submitter=user.user, notes=uccrap + "This is a non-compilable submission.", state=Submission.TEST_COMPILE_PENDING, file_upload=sf) fname = "reverse_support_files.zip" shutil.copyfile(rootdir + '/opensubmit/tests/submfiles/' + fname, settings.MEDIA_ROOT + fname) sub.assignment.attachment_test_support = DjangoFile( open(settings.MEDIA_ROOT + fname)) sub.assignment.save() sub.save() return sub
def handle(self, *args, **options): # create demo users users = {} for name in ['demo_student', 'demo_tutor', 'demo_owner']: user = User.objects.filter(username=name).delete() user = User.objects.create_user(username=name, email='*****@*****.**', password=name) UserProfile(user=user).save() users[name] = user # create demo grading passGrade = Grading(title='passed', means_passed=True) passGrade.save() failGrade = Grading(title='failed', means_passed=False) failGrade.save() passFailGrading = GradingScheme( title='Pass/Fail Grading Scheme (Demo)') passFailGrading.save() passFailGrading.gradings.add(passGrade) passFailGrading.gradings.add(failGrade) passFailGrading.save() # create demo course course = Course( title='Demo Course', active=True, owner=users['demo_owner'], max_authors=3, ) course.save() course.tutors.add(users['demo_tutor']) course.participants.add(users['demo_student'].profile) # create demo assignment today = timezone.now() last_week = today - datetime.timedelta(weeks=1) tomorrow = today + datetime.timedelta(days=1) next_week = today + datetime.timedelta(weeks=1) ass = Assignment(title='Demo Assignment 1', course=course, download='http://example.org/assignments1.pdf', gradingScheme=passFailGrading, publish_at=last_week, soft_deadline=tomorrow, hard_deadline=next_week, has_attachment=False) ass.save() # create demo submission Submission(assignment=ass, submitter=users['demo_student'], notes="This is a demo submission.", state=Submission.SUBMITTED_TESTED).save()
def testAssignmentSpecificTestMachine(self): # Register two test machines T1 and T2 real_machine = self._registerExecutor() fake_machine = TestMachine(host="127.0.0.2") fake_machine.save() # Assign each of them to a different assignment self.openAssignment.test_machines.add(real_machine) self.validatedAssignment.test_machines.add(fake_machine) # Produce submission for the assignment linked to fake_machine sub1 = Submission(assignment=self.validatedAssignment, submitter=self.current_user.user, state=Submission.TEST_COMPILE_PENDING, file_upload=self.createSubmissionFile()) sub1.save() # Run real_machine executor, should not react on this submission old_sub1_state = sub1.state self.assertEquals(False, self._runExecutor()) # Make sure that submission object was not touched, whatever the executor says sub1 = Submission.objects.get(pk=sub1.pk) self.assertEquals(old_sub1_state, sub1.state)
def testAssignmentSpecificTestMachine(self): # Register two test machines T1 and T2 real_machine = self._registerExecutor() fake_machine = TestMachine(host="127.0.0.2") fake_machine.save() # Assign each of them to a different assignment self.openAssignment.test_machines.add(real_machine) self.validatedAssignment.test_machines.add(fake_machine) # Produce submission for the assignment linked to fake_machine sub1 = Submission( assignment=self.validatedAssignment, submitter=self.current_user.user, state=Submission.TEST_COMPILE_PENDING, file_upload=self.createSubmissionFile() ) sub1.save() # Run real_machine executor, should not react on this submission old_sub1_state = sub1.state self.assertEquals(False, self._runExecutor()) # Make sure that submission object was not touched, whatever the executor says sub1 = Submission.objects.get(pk=sub1.pk) self.assertEquals(old_sub1_state, sub1.state)
def prepareSubmission(self, fname1, fname2): ''' Prepare two submissions with the given file uploads. ''' f1 = self.createSubmissionFile(fname1); f2 = self.createSubmissionFile(fname2); sub1 = Submission( assignment=self.validatedAssignment, submitter=self.current_user.user, notes="This is a validatable submission.", state=Submission.TEST_COMPILE_PENDING, file_upload=f1 ) sub1.save() sub2 = Submission( assignment=self.validatedAssignment, submitter=self.current_user.user, notes="This is a validatable submission.", state=Submission.TEST_COMPILE_PENDING, file_upload=f2 ) sub2.save() return sub1, sub2
def handle(self, *args, **options): print("Adding demo data ...") # create demo users users = {} for name in ['demo_student', 'demo_cheater', 'demo_tutor', 'demo_owner']: user = User.objects.filter(username=name).delete() user = User.objects.create_user(username=name, email='*****@*****.**', password=name, first_name=name, last_name=name) users[name] = user # create demo grading Grading.objects.filter(title='passed (demo)').delete() passGrade = Grading(title='passed (demo)', means_passed=True) passGrade.save() Grading.objects.filter(title='failed (demo)').delete() failGrade = Grading(title='failed (demo)', means_passed=False) failGrade.save() GradingScheme.objects.filter( title='Pass/Fail Grading Scheme (Demo)').delete() passFailGrading = GradingScheme( title='Pass/Fail Grading Scheme (Demo)') passFailGrading.save() passFailGrading.gradings.add(passGrade) passFailGrading.gradings.add(failGrade) passFailGrading.save() # create demo course Course.objects.filter(title='Demo Course').delete() course = Course( title='Demo Course', active=True, owner=users['demo_owner'], homepage="http://www.open-submit.org" ) course.save() course.tutors.add(users['demo_tutor']) course.participants.add(users['demo_student'].profile) course.participants.add(users['demo_cheater'].profile) today = timezone.now() last_week = today - datetime.timedelta(weeks=1) tomorrow = today + datetime.timedelta(days=1) next_week = today + datetime.timedelta(weeks=1) # create demo assignment ass1 = Assignment( title='Demo A1: Graded group work with deadline', course=course, download='http://example.org/assignments1.pdf', gradingScheme=passFailGrading, publish_at=last_week, soft_deadline=tomorrow, hard_deadline=next_week, has_attachment=True, max_authors=3 ) ass1.save() # create demo assignment without grading ass2 = Assignment( title='Demo A2: Non-graded group work with deadline', course=course, download='http://example.org/assignments2.pdf', gradingScheme=None, publish_at=last_week, soft_deadline=tomorrow, hard_deadline=next_week, has_attachment=True, max_authors=3 ) ass2.save() # create demo assignment without deadlines ass3 = Assignment( title='Demo A3: Graded group work without deadline, only notes', course=course, download='http://example.org/assignments1.pdf', gradingScheme=passFailGrading, publish_at=last_week, soft_deadline=None, hard_deadline=None, has_attachment=False, max_authors=3 ) ass3.save() # create demo assignment without deadlines ass4 = Assignment( title='Demo A4: Graded group work with deadline being over', course=course, download='http://example.org/assignments1.pdf', gradingScheme=passFailGrading, publish_at=last_week, soft_deadline=last_week, hard_deadline=last_week, has_attachment=False, max_authors=3 ) ass4.save() # create demo submission Submission( assignment=ass1, submitter=users['demo_student'], notes="Demo submission for A1.", state=Submission.SUBMITTED_TESTED, file_upload=createSubmissionFile() ).save() # create cheater submission in course 1 Submission( assignment=ass1, submitter=users['demo_cheater'], notes="Demo duplicate submission for A1.", state=Submission.SUBMITTED_TESTED, file_upload=createSubmissionFile() ).save()