Commit beef0da2 by Afzal Wali

improved coverage.

parent 4333ba90
...@@ -14,8 +14,8 @@ from edx_proctoring.api import ( ...@@ -14,8 +14,8 @@ from edx_proctoring.api import (
stop_exam_attempt, stop_exam_attempt,
get_active_exams_for_user, get_active_exams_for_user,
get_exam_attempt, get_exam_attempt,
create_exam_attempt create_exam_attempt,
) get_student_view)
from edx_proctoring.exceptions import ( from edx_proctoring.exceptions import (
ProctoredExamAlreadyExists, ProctoredExamAlreadyExists,
ProctoredExamNotFoundException, ProctoredExamNotFoundException,
...@@ -75,7 +75,7 @@ class ProctoredExamApiTests(LoggedInTestCase): ...@@ -75,7 +75,7 @@ class ProctoredExamApiTests(LoggedInTestCase):
external_id=self.external_id external_id=self.external_id
) )
def _create_started_exam_attempt(self): def _create_started_exam_attempt(self, started_at=None):
""" """
Creates the ProctoredExamStudentAttempt object. Creates the ProctoredExamStudentAttempt object.
""" """
...@@ -83,7 +83,7 @@ class ProctoredExamApiTests(LoggedInTestCase): ...@@ -83,7 +83,7 @@ class ProctoredExamApiTests(LoggedInTestCase):
proctored_exam_id=self.proctored_exam_id, proctored_exam_id=self.proctored_exam_id,
user_id=self.user_id, user_id=self.user_id,
external_id=self.external_id, external_id=self.external_id,
started_at=datetime.now(pytz.UTC) started_at=started_at if started_at else datetime.now(pytz.UTC)
) )
def _add_allowance_for_user(self): def _add_allowance_for_user(self):
...@@ -295,3 +295,96 @@ class ProctoredExamApiTests(LoggedInTestCase): ...@@ -295,3 +295,96 @@ class ProctoredExamApiTests(LoggedInTestCase):
self.assertEqual(len(student_active_exams), 2) self.assertEqual(len(student_active_exams), 2)
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_student_view(self):
"""
Test for get_student_view
"""
rendered_response = get_student_view(
user_id=self.user_id,
course_id=self.course_id,
content_id=self.content_id,
context={
'is_proctored': True,
'display_name': self.exam_name,
'default_time_limit_mins': 90
}
)
self.assertIn('data-exam-id="%d"' % self.proctored_exam_id, rendered_response)
self.assertIn('Would you Like to take %s as Proctored Exam?' % self.exam_name, rendered_response)
def test_getstudentview_timedexam(self):
"""
Test for get_student_view Timed exam which is not proctored.
"""
rendered_response = get_student_view(
user_id=self.user_id,
course_id="abc",
content_id=self.content_id,
context={
'is_proctored': False,
'display_name': self.exam_name,
'default_time_limit_mins': 90
}
)
self.assertNotIn('data-exam-id="%d"' % self.proctored_exam_id, rendered_response)
self.assertIn('%s is a Timed Exam' % self.exam_name, rendered_response)
self.assertNotIn('Would you Like to take %s as Proctored Exam?' % self.exam_name, rendered_response)
def test_getstudentview_unstartedxm(self):
"""
Test for get_student_view proctored exam which has not started yet.
"""
self._create_unstarted_exam_attempt()
rendered_response = get_student_view(
user_id=self.user_id,
course_id=self.course_id,
content_id=self.content_id,
context={
'is_proctored': True,
'display_name': self.exam_name,
'default_time_limit_mins': 90
}
)
self.assertIn('you have chosen to take %s as a proctored exam' % self.exam_name, rendered_response)
def test_getstudentview_startedxam(self):
"""
Test for get_student_view proctored exam which has started.
"""
self._create_started_exam_attempt()
get_student_view(
user_id=self.user_id,
course_id=self.course_id,
content_id=self.content_id,
context={
'is_proctored': True,
'display_name': self.exam_name,
'default_time_limit_mins': 90
}
)
# TODO Not getting anything in this case. Will have to implement the testcase later.
# TODO No condition set for finished exam in the student view. Will have to test later.
def test_getstudentview_expiredxam(self):
"""
Test for get_student_view proctored exam which has started.
"""
self._create_started_exam_attempt(started_at=datetime.now(pytz.UTC).replace(year=2010))
rendered_response = get_student_view(
user_id=self.user_id,
course_id=self.course_id,
content_id=self.content_id,
context={
'is_proctored': True,
'display_name': self.exam_name,
'default_time_limit_mins': 90
}
)
self.assertIn('you did not submit your exam before the time allotted expired', rendered_response)
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