Esempio n. 1
0
def create_self_test(solution, test, cw, initiator):
    """Receive data to create a student-specific test match. Pass in IDs for
    @solution, @test and a @cw, @initiator user instance. Return the newly created test."""
    solution = m.Submission.objects.get(id=solution,
                                        coursework=cw,
                                        type__in=[
                                            m.SubmissionType.ORACLE_EXECUTABLE,
                                            m.SubmissionType.SOLUTION
                                        ])
    test_case = m.Submission.objects.get(
        id=test,
        coursework=cw,
        type__in=[m.SubmissionType.TEST_CASE, m.SubmissionType.SIGNATURE_TEST])
    if solution.type == m.SubmissionType.ORACLE_EXECUTABLE and test_case.type == m.SubmissionType.SIGNATURE_TEST:
        raise Exception(
            "Either test, solution or both need to be a student upload")
    if solution.type != m.SubmissionType.ORACLE_EXECUTABLE:
        if solution.creator != initiator:
            raise Exception(
                "You need to do self testing with your own solution")
    if test_case.type != m.SubmissionType.SIGNATURE_TEST:
        if test_case.creator != initiator:
            raise Exception("You need to do self testing with your own test")
    new_tm = m.TestMatch(id=m.new_random_slug(m.TestMatch),
                         test=test_case,
                         test_version=test_case.latest_version,
                         solution=solution,
                         solution_version=solution.latest_version,
                         coursework=cw,
                         type=m.TestType.SELF)
    new_tm.save()
    return new_tm
Esempio n. 2
0
def create_peer_test(solution, test, cw, feedback_group, initiator):
    """Create a new test match with data specified by the IDs of @solution,
    @test, @feedback_group and the instance of @cw, @initiator"""
    group = fm.FeedbackGroup.objects.get(id=feedback_group)
    solution = m.Submission.objects.get(id=solution,
                                        coursework=cw,
                                        type__in=[
                                            m.SubmissionType.ORACLE_EXECUTABLE,
                                            m.SubmissionType.SOLUTION
                                        ])
    test_case = m.Submission.objects.get(
        id=test,
        coursework=cw,
        type__in=[m.SubmissionType.TEST_CASE, m.SubmissionType.SIGNATURE_TEST])
    if solution.type != m.SubmissionType.ORACLE_EXECUTABLE:
        if not fm.FeedbackMembership.objects.filter(
                group=group, user=solution.creator).exists():
            raise Exception(
                "That solution is not included in your feedback group")
    if test_case.type != m.SubmissionType.SIGNATURE_TEST:
        if test_case.creator != initiator:
            raise Exception("You need to do peer testing with your own test")
    if solution.type == m.SubmissionType.ORACLE_EXECUTABLE and test_case.type == m.SubmissionType.SIGNATURE_TEST:
        raise Exception(
            "Either test, solution or both need to be a student upload")
    new_tm = m.TestMatch(id=m.new_random_slug(m.TestMatch),
                         test=test_case,
                         test_version=test_case.latest_version,
                         solution=solution,
                         solution_version=solution.latest_version,
                         coursework=cw,
                         type=m.TestType.PEER)
    new_tm.save()
    fm.TestAccessControl(test=new_tm, group=group, initiator=initiator).save()
    return new_tm
Esempio n. 3
0
def do_gitlab_fetch(request, cw):
    """Given this @request to fetch files for @cw,
    fetch the files from gitlab.
    @return bool if anything was actually fetched"""
    file_type = request.POST['file_type']
    if not h.user_can_upload_of_type(request.user, cw, file_type):
        return HttpResponseForbidden(
            "You can't upload submissions of this type")
    with GitlabFetcher(request.user, str(cw.name)) as gf:
        try:
            latest_submission = m.Submission.objects.get(coursework=cw,
                                                         creator=request.user,
                                                         type=file_type)
            if gf.check_for_changes(latest_submission, cw, file_type):
                latest_submission.increment_version()
                latest_submission.save()
                gf.copy_gitlab_files_to_submission(latest_submission, cw,
                                                   file_type)
                return True
            return False
        except ObjectDoesNotExist as e:
            name = "Solution" if file_type == m.SubmissionType.SOLUTION else "Test Case"
            new_submission = m.Submission(id=m.new_random_slug(m.Submission),
                                          coursework=cw,
                                          creator=request.user,
                                          type=file_type,
                                          display_name=name)
            new_submission.save()
            gf.copy_gitlab_files_to_submission(new_submission, cw, file_type)
            return True
Esempio n. 4
0
def save_new_submission(cw, request, file_type, name):
    """Do the atomic database actions required to save the new files"""
    submission = m.Submission(id=m.new_random_slug(m.Submission),
                              coursework=cw,
                              creator=request.user,
                              type=file_type,
                              display_name=name)
    submission.save()
    for each in request.FILES.getlist('chosen_files'):
        submission.save_uploaded_file(each)
    return submission
Esempio n. 5
0
def create_teacher_test(solution, test, cw):
    """Create a new test match with data specified by the IDs of @solution,
    @test, and @cw instanceand create the teachers test"""
    solution = m.Submission.objects.get(id=solution,
                                        coursework=cw,
                                        type__in=[
                                            m.SubmissionType.ORACLE_EXECUTABLE,
                                            m.SubmissionType.SOLUTION
                                        ])
    test_case = m.Submission.objects.get(
        id=test,
        coursework=cw,
        type__in=[m.SubmissionType.TEST_CASE, m.SubmissionType.SIGNATURE_TEST])
    new_tm = m.TestMatch(id=m.new_random_slug(m.TestMatch),
                         test=test_case,
                         test_version=test_case.latest_version,
                         solution=solution,
                         solution_version=solution.latest_version,
                         coursework=cw,
                         type=m.TestType.TEACHER)
    new_tm.save()
    return new_tm