コード例 #1
0
    def test_get_submission_unauthenticated(self):
        view = SubmissionsDetail.as_view()

        request = self.factory.get(self.getApiUrl() +
                                   str(self.submission1.id) + '/')
        response = view(request, pk=self.submission1.id)

        self.assertEqual(response.status_code, 401)
コード例 #2
0
    def test_get_submission_student(self):
        view = SubmissionsDetail.as_view()

        request = self.factory.get(self.getApiUrl() +
                                   str(self.submission1.id) + '/')
        self.loginStudent(request)
        response = view(request, pk=self.submission1.id)

        self.assertEqual(response.status_code, 200)
コード例 #3
0
    def test_delete_submission_unauthenticated(self):
        view = SubmissionsDetail.as_view()

        request = self.factory.delete(self.getApiUrl() +
                                      str(self.submission1.id) + '/')
        response = view(request, pk=self.submission1.id)

        self.assertEqual(len(Submission.objects.all()), 2)
        self.assertEqual(response.status_code, 401)
コード例 #4
0
    def test_delete_submission(self):
        view = SubmissionsDetail.as_view()

        request = self.factory.delete(self.getApiUrl() +
                                      str(self.submission1.id) + '/')
        self.loginProfessor(request)
        response = view(request, pk=self.submission1.id)

        self.assertEqual(len(Submission.objects.all()), 1)
        self.assertEqual(response.status_code, 204)
コード例 #5
0
    def test_update_submission_unauthenticated(self):
        view = SubmissionsDetail.as_view()

        data = {'marks': 10}

        request = self.factory.patch(
            self.getApiUrl() + str(self.submission1.id) + '/', data)
        response = view(request, pk=self.submission1.id)

        self.assertEqual(response.status_code, 401)
コード例 #6
0
    def test_get_submission(self):
        view = SubmissionsDetail.as_view()

        request = self.factory.get(self.getApiUrl() +
                                   str(self.submission1.id) + '/')
        force_authenticate(request,
                           user=self.professor,
                           token=self.professor.auth_token)
        response = view(request, pk=self.submission1.id)

        self.assertEqual(response.status_code, 200)
コード例 #7
0
    def test_update_submission(self):
        view = SubmissionsDetail.as_view()

        data = {'marks': 10}

        request = self.factory.patch(
            self.getApiUrl() + str(self.submission1.id) + '/', data)
        force_authenticate(request,
                           user=self.professor,
                           token=self.professor.auth_token)
        response = view(request, pk=self.submission1.id)

        submission = Submission.objects.get(pk=self.submission1.id)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(submission.marks, 10)