Commit 08460713 by Muhammad Shoaib

revert the serializers method and added test for the endpoints

parent 4936f7a7
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
from rest_framework import serializers from rest_framework import serializers
from django.contrib.auth.models import User from django.contrib.auth.models import User
from edx_proctoring.models import ProctoredExam, ProctoredExamStudentAttempt, ProctoredExamStudentAllowance from edx_proctoring.models import ProctoredExam, ProctoredExamStudentAttempt, ProctoredExamStudentAllowance
from edx_proctoring.utils import humanized_time
DATETIME_FORMAT = "%b %d, %Y %I:%M %p" # "MMMM dd, yyyy HH:MM" DATETIME_FORMAT = "%b %d, %Y %I:%M %p" # "MMMM dd, yyyy HH:MM"
...@@ -71,18 +70,6 @@ class ProctoredExamStudentAttemptSerializer(serializers.ModelSerializer): ...@@ -71,18 +70,6 @@ class ProctoredExamStudentAttemptSerializer(serializers.ModelSerializer):
""" """
proctored_exam = ProctoredExamSerializer() proctored_exam = ProctoredExamSerializer()
user = UserSerializer() user = UserSerializer()
allowed_time_limit_mins = serializers.SerializerMethodField(method_name="get_allowed_time_limit_mins")
started_at = serializers.SerializerMethodField(method_name="get_started_at")
completed_at = serializers.SerializerMethodField(method_name="get_completed_at")
def get_allowed_time_limit_mins(self, obj):
return humanized_time(obj.allowed_time_limit_mins)
def get_started_at(self, obj):
return obj.started_at.strftime(DATETIME_FORMAT) if obj.started_at else "N/A"
def get_completed_at(self, obj):
return obj.completed_at.strftime(DATETIME_FORMAT) if obj.completed_at else "N/A"
class Meta: class Meta:
""" """
......
...@@ -99,11 +99,13 @@ ...@@ -99,11 +99,13 @@
<td> <%= proctored_exam_attempt.allowed_time_limit_mins %></td> <td> <%= proctored_exam_attempt.allowed_time_limit_mins %></td>
<td> <%= proctored_exam_attempt.started_at %></td> <td> <%= proctored_exam_attempt.started_at %></td>
<td> <%= proctored_exam_attempt.completed_at %></td> <td> <%= proctored_exam_attempt.completed_at %></td>
<td>
<% if (proctored_exam_attempt.status){ %> <% if (proctored_exam_attempt.status){ %>
<%= proctored_exam_attempt.status %> </td> <%= proctored_exam_attempt.status %>
<% } else { %> <% } else { %>
N/A N/A
<% } %> <% } %>
</td>
<td> <td>
<% if (proctored_exam_attempt.status){ %> <% if (proctored_exam_attempt.status){ %>
<a href="#" class="remove-attempt" data-attempt-id="<%= proctored_exam_attempt.id %>" >[x]</a> <a href="#" class="remove-attempt" data-attempt-id="<%= proctored_exam_attempt.id %>" >[x]</a>
......
...@@ -23,8 +23,8 @@ from edx_proctoring.api import ( ...@@ -23,8 +23,8 @@ from edx_proctoring.api import (
get_all_exams_for_course, get_all_exams_for_course,
get_exam_attempt_by_id, get_exam_attempt_by_id,
remove_exam_attempt_by_id, remove_exam_attempt_by_id,
get_all_exam_attempts get_all_exam_attempts,
) get_filtered_exam_attempts)
from edx_proctoring.exceptions import ( from edx_proctoring.exceptions import (
ProctoredExamAlreadyExists, ProctoredExamAlreadyExists,
ProctoredExamNotFoundException, ProctoredExamNotFoundException,
...@@ -386,6 +386,27 @@ class ProctoredExamApiTests(LoggedInTestCase): ...@@ -386,6 +386,27 @@ class ProctoredExamApiTests(LoggedInTestCase):
self.assertEqual(len(student_active_exams[0]['allowances']), 2) self.assertEqual(len(student_active_exams[0]['allowances']), 2)
self.assertEqual(len(student_active_exams[1]['allowances']), 0) self.assertEqual(len(student_active_exams[1]['allowances']), 0)
def test_get_filtered_exam_attempts(self):
"""
Test to get all the exams filtered by the course_id
and search type.
"""
exam_attempt = self._create_started_exam_attempt()
exam_id = create_exam(
course_id=self.course_id,
content_id='test_content_2',
exam_name='Final Test Exam',
time_limit_mins=self.default_time_limit
)
new_exam_attempt = create_exam_attempt(
exam_id=exam_id,
user_id=self.user_id
)
filtered_attempts = get_filtered_exam_attempts(self.course_id, self.user.username)
self.assertEqual(len(filtered_attempts), 2)
self.assertEqual(filtered_attempts[0]['id'], exam_attempt.id)
self.assertEqual(filtered_attempts[1]['id'], new_exam_attempt)
def test_get_all_exam_attempts(self): def test_get_all_exam_attempts(self):
""" """
Test to get all the exam attempts. Test to get all the exam attempts.
......
...@@ -385,7 +385,7 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase): ...@@ -385,7 +385,7 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase):
) )
attempt_data = { attempt_data = {
'exam_id': proctored_exam.id, 'exam_id': proctored_exam.id,
'external_id': proctored_exam.external_id, 'attempt_proctored': True,
'start_clock': True, 'start_clock': True,
} }
response = self.client.post( response = self.client.post(
...@@ -411,7 +411,7 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase): ...@@ -411,7 +411,7 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase):
) )
attempt_data = { attempt_data = {
'exam_id': proctored_exam.id, 'exam_id': proctored_exam.id,
'external_id': proctored_exam.external_id, 'attempt_proctored': True,
'start_clock': True, 'start_clock': True,
} }
response = self.client.post( response = self.client.post(
...@@ -455,7 +455,7 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase): ...@@ -455,7 +455,7 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase):
attempt_data = { attempt_data = {
'exam_id': proctored_exam.id, 'exam_id': proctored_exam.id,
'external_id': proctored_exam.external_id, 'attempt_proctored': True,
'start_clock': True, 'start_clock': True,
} }
response = self.client.post( response = self.client.post(
...@@ -488,7 +488,7 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase): ...@@ -488,7 +488,7 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase):
) )
attempt_data = { attempt_data = {
'exam_id': proctored_exam.id, 'exam_id': proctored_exam.id,
'external_id': proctored_exam.external_id, 'attempt_proctored': True,
'start_clock': True, 'start_clock': True,
} }
response = self.client.post( response = self.client.post(
...@@ -530,7 +530,8 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase): ...@@ -530,7 +530,8 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase):
) )
attempt_data = { attempt_data = {
'exam_id': proctored_exam.id, 'exam_id': proctored_exam.id,
'external_id': proctored_exam.external_id 'attempt_proctored': True,
'start_clock': False
} }
response = self.client.post( response = self.client.post(
reverse('edx_proctoring.proctored_exam.attempt.collection'), reverse('edx_proctoring.proctored_exam.attempt.collection'),
...@@ -566,8 +567,8 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase): ...@@ -566,8 +567,8 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase):
) )
attempt_data = { attempt_data = {
'exam_id': proctored_exam.id, 'exam_id': proctored_exam.id,
'user_id': self.student_taking_exam.id, 'attempt_proctored': True,
'external_id': proctored_exam.external_id 'start_clock': False
} }
response = self.client.post( response = self.client.post(
reverse('edx_proctoring.proctored_exam.attempt.collection'), reverse('edx_proctoring.proctored_exam.attempt.collection'),
...@@ -602,8 +603,8 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase): ...@@ -602,8 +603,8 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase):
) )
attempt_data = { attempt_data = {
'exam_id': proctored_exam.id, 'exam_id': proctored_exam.id,
'user_id': self.student_taking_exam.id, 'attempt_proctored': True,
'external_id': proctored_exam.external_id 'start_clock': False
} }
response = self.client.post( response = self.client.post(
reverse('edx_proctoring.proctored_exam.attempt.collection'), reverse('edx_proctoring.proctored_exam.attempt.collection'),
...@@ -618,6 +619,53 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase): ...@@ -618,6 +619,53 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase):
response_data = json.loads(response.content) response_data = json.loads(response.content)
self.assertEqual(len(response_data['proctored_exam_attempts']), 1) self.assertEqual(len(response_data['proctored_exam_attempts']), 1)
def test_get_filtered_exam_attempts(self):
"""
Test to get the exam attempts in a course.
"""
# Create an exam.
proctored_exam = ProctoredExam.objects.create(
course_id='a/b/c',
content_id='test_content',
exam_name='Test Exam',
external_id='123aXqe3',
time_limit_mins=90
)
attempt_data = {
'exam_id': proctored_exam.id,
'start_clock': False,
'attempt_proctored': True
}
# create a exam attempt
response = self.client.post(
reverse('edx_proctoring.proctored_exam.attempt.collection'),
attempt_data
)
self.assertEqual(response.status_code, 200)
self.client.login_user(self.second_user)
# create a new exam attempt for second student
response = self.client.post(
reverse('edx_proctoring.proctored_exam.attempt.collection'),
attempt_data
)
self.assertEqual(response.status_code, 200)
self.client.login_user(self.user)
response = self.client.get(
reverse(
'edx_proctoring.proctored_exam.attempt.search',
kwargs={
'course_id': proctored_exam.course_id,
'search_by': 'tester'
}
)
)
self.assertEqual(response.status_code, 200)
response_data = json.loads(response.content)
self.assertEqual(len(response_data['proctored_exam_attempts']), 2)
def test_stop_others_attempt(self): def test_stop_others_attempt(self):
""" """
Start an exam (create an exam attempt) Start an exam (create an exam attempt)
...@@ -632,8 +680,8 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase): ...@@ -632,8 +680,8 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase):
) )
attempt_data = { attempt_data = {
'exam_id': proctored_exam.id, 'exam_id': proctored_exam.id,
'user_id': self.student_taking_exam.id, 'attempt_proctored': True,
'external_id': proctored_exam.external_id 'start_clock': False
} }
response = self.client.post( response = self.client.post(
reverse('edx_proctoring.proctored_exam.attempt.collection'), reverse('edx_proctoring.proctored_exam.attempt.collection'),
...@@ -688,9 +736,8 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase): ...@@ -688,9 +736,8 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase):
attempt_data = { attempt_data = {
'exam_id': proctored_exam.id, 'exam_id': proctored_exam.id,
'user_id': self.user.id, 'start_clock': True,
'external_id': proctored_exam.external_id, 'attempts_proctored': True
'start_clock': True
} }
response = self.client.post( response = self.client.post(
reverse('edx_proctoring.proctored_exam.attempt.collection'), reverse('edx_proctoring.proctored_exam.attempt.collection'),
...@@ -722,9 +769,8 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase): ...@@ -722,9 +769,8 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase):
attempt_data = { attempt_data = {
'exam_id': proctored_exam.id, 'exam_id': proctored_exam.id,
'user_id': self.user.id, 'start_clock': True,
'external_id': proctored_exam.external_id, 'attempt_proctored': True
'start_clock': True
} }
response = self.client.post( response = self.client.post(
reverse('edx_proctoring.proctored_exam.attempt.collection'), reverse('edx_proctoring.proctored_exam.attempt.collection'),
...@@ -759,8 +805,8 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase): ...@@ -759,8 +805,8 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase):
attempt_data = { attempt_data = {
'exam_id': proctored_exam.id, 'exam_id': proctored_exam.id,
'user_id': self.student_taking_exam.id, 'attempt_proctored': True,
'external_id': proctored_exam.external_id 'start_clock': True
} }
response = self.client.post( response = self.client.post(
reverse('edx_proctoring.proctored_exam.attempt.collection'), reverse('edx_proctoring.proctored_exam.attempt.collection'),
...@@ -796,8 +842,8 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase): ...@@ -796,8 +842,8 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase):
# create an attempt but don't start it # create an attempt but don't start it
attempt_data = { attempt_data = {
'attempt_proctored': True,
'exam_id': proctored_exam.id, 'exam_id': proctored_exam.id,
'external_id': proctored_exam.external_id,
'start_clock': False, 'start_clock': False,
} }
response = self.client.post( response = self.client.post(
......
...@@ -5,7 +5,6 @@ Proctored Exams HTTP-based API endpoints ...@@ -5,7 +5,6 @@ Proctored Exams HTTP-based API endpoints
import logging import logging
import pytz import pytz
from datetime import datetime, timedelta from datetime import datetime, timedelta
from django.core.urlresolvers import reverse
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.conf import settings from django.conf import settings
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment