Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-proctoring
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
edx-proctoring
Commits
7da5e1c3
Commit
7da5e1c3
authored
Jul 02, 2015
by
Afzal Wali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved coverage. Started using the ExamAttempt serializer.
parent
d168dd5f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
17 deletions
+66
-17
edx_proctoring/api.py
+2
-1
edx_proctoring/serializers.py
+3
-1
edx_proctoring/tests/test_api.py
+52
-14
edx_proctoring/tests/test_views.py
+8
-0
edx_proctoring/views.py
+1
-1
No files found.
edx_proctoring/api.py
View file @
7da5e1c3
...
@@ -149,7 +149,8 @@ def get_exam_attempt(exam_id, user_id):
...
@@ -149,7 +149,8 @@ def get_exam_attempt(exam_id, user_id):
Return an existing exam attempt for the given student
Return an existing exam attempt for the given student
"""
"""
exam_attempt_obj
=
ProctoredExamStudentAttempt
.
get_exam_attempt
(
exam_id
,
user_id
)
exam_attempt_obj
=
ProctoredExamStudentAttempt
.
get_exam_attempt
(
exam_id
,
user_id
)
return
exam_attempt_obj
.
__dict__
if
exam_attempt_obj
else
None
serialized_attempt_obj
=
ProctoredExamStudentAttemptSerializer
(
exam_attempt_obj
)
return
serialized_attempt_obj
.
data
if
exam_attempt_obj
else
None
def
create_exam_attempt
(
exam_id
,
user_id
,
external_id
):
def
create_exam_attempt
(
exam_id
,
user_id
,
external_id
):
...
...
edx_proctoring/serializers.py
View file @
7da5e1c3
...
@@ -46,14 +46,16 @@ class ProctoredExamStudentAttemptSerializer(serializers.ModelSerializer):
...
@@ -46,14 +46,16 @@ class ProctoredExamStudentAttemptSerializer(serializers.ModelSerializer):
"""
"""
Serializer for the ProctoredExamStudentAttempt Model.
Serializer for the ProctoredExamStudentAttempt Model.
"""
"""
proctored_exam_id
=
serializers
.
IntegerField
(
source
=
"proctored_exam_id"
)
class
Meta
:
class
Meta
:
"""
"""
Meta Class
Meta Class
"""
"""
model
=
ProctoredExamStudentAttempt
model
=
ProctoredExamStudentAttempt
fields
=
(
fields
=
(
"id"
,
"created"
,
"modified"
,
"user_id"
,
"started_at"
,
"completed_at"
,
"id"
,
"created"
,
"modified"
,
"user_id"
,
"started_at"
,
"completed_at"
,
"external_id"
,
"status"
"external_id"
,
"status"
,
"proctored_exam_id"
)
)
...
...
edx_proctoring/tests/test_api.py
View file @
7da5e1c3
...
@@ -14,14 +14,14 @@ from edx_proctoring.api import (
...
@@ -14,14 +14,14 @@ 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
,
StudentExamAttemptAlreadyExistsException
,
StudentExamAttemptAlreadyExistsException
,
StudentExamAttemptDoesNotExistsException
StudentExamAttemptDoesNotExistsException
,
)
StudentExamAttemptedAlreadyStarted
)
from
edx_proctoring.models
import
(
from
edx_proctoring.models
import
(
ProctoredExam
,
ProctoredExam
,
ProctoredExamStudentAllowance
,
ProctoredExamStudentAllowance
,
...
@@ -64,7 +64,17 @@ class ProctoredExamApiTests(LoggedInTestCase):
...
@@ -64,7 +64,17 @@ class ProctoredExamApiTests(LoggedInTestCase):
time_limit_mins
=
self
.
default_time_limit
time_limit_mins
=
self
.
default_time_limit
)
)
def
_create_student_exam_attempt
(
self
):
def
_create_unstarted_exam_attempt
(
self
):
"""
Creates the ProctoredExamStudentAttempt object.
"""
return
ProctoredExamStudentAttempt
.
objects
.
create
(
proctored_exam_id
=
self
.
proctored_exam_id
,
user_id
=
self
.
user_id
,
external_id
=
self
.
external_id
)
def
_create_started_exam_attempt
(
self
):
"""
"""
Creates the ProctoredExamStudentAttempt object.
Creates the ProctoredExamStudentAttempt object.
"""
"""
...
@@ -195,30 +205,54 @@ class ProctoredExamApiTests(LoggedInTestCase):
...
@@ -195,30 +205,54 @@ class ProctoredExamApiTests(LoggedInTestCase):
attempt_id
=
create_exam_attempt
(
self
.
proctored_exam_id
,
self
.
user_id
,
''
)
attempt_id
=
create_exam_attempt
(
self
.
proctored_exam_id
,
self
.
user_id
,
''
)
self
.
assertGreater
(
attempt_id
,
0
)
self
.
assertGreater
(
attempt_id
,
0
)
def
test_recreate_an_exam_attempt
(
self
):
"""
Start an exam attempt that has already been created.
Raises StudentExamAttemptAlreadyExistsException
"""
proctored_exam_student_attempt
=
self
.
_create_unstarted_exam_attempt
()
with
self
.
assertRaises
(
StudentExamAttemptAlreadyExistsException
):
create_exam_attempt
(
proctored_exam_student_attempt
.
proctored_exam
,
self
.
user_id
,
self
.
external_id
)
def
test_get_exam_attempt
(
self
):
def
test_get_exam_attempt
(
self
):
"""
"""
Test to get the already made exam attempt.
Test to get the already made exam attempt.
"""
"""
self
.
_create_
student
_exam_attempt
()
self
.
_create_
unstarted
_exam_attempt
()
exam_attempt
=
get_exam_attempt
(
self
.
proctored_exam_id
,
self
.
user_id
)
exam_attempt
=
get_exam_attempt
(
self
.
proctored_exam_id
,
self
.
user_id
)
self
.
assertEqual
(
exam_attempt
[
'proctored_exam_id'
],
self
.
proctored_exam_id
)
self
.
assertEqual
(
exam_attempt
[
'proctored_exam_id'
],
self
.
proctored_exam_id
)
self
.
assertEqual
(
exam_attempt
[
'user_id'
],
self
.
user_id
)
self
.
assertEqual
(
exam_attempt
[
'user_id'
],
self
.
user_id
)
def
test_
restart_exam
_attempt
(
self
):
def
test_
start_uncreated
_attempt
(
self
):
"""
"""
Start an exam attempt that has already been started
.
Test to attempt starting an attempt which has not been created yet
.
Raises StudentExamAttemptAlreadyExistsException
should raise an exception.
"""
"""
proctored_exam_student_attempt
=
self
.
_create_student_exam_attempt
()
with
self
.
assertRaises
(
StudentExamAttemptDoesNotExistsException
):
with
self
.
assertRaises
(
StudentExamAttemptAlreadyExistsException
):
start_exam_attempt
(
self
.
proctored_exam_id
,
self
.
user_id
)
create_exam_attempt
(
proctored_exam_student_attempt
.
proctored_exam
,
self
.
user_id
,
self
.
external_id
)
def
test_start_a_created_attempt
(
self
):
"""
Test to attempt starting an attempt which has been created but not started.
"""
self
.
_create_unstarted_exam_attempt
()
start_exam_attempt
(
self
.
proctored_exam_id
,
self
.
user_id
)
def
test_restart_a_started_attempt
(
self
):
"""
Test to attempt starting an attempt which has been created but not started.
"""
self
.
_create_unstarted_exam_attempt
()
start_exam_attempt
(
self
.
proctored_exam_id
,
self
.
user_id
)
with
self
.
assertRaises
(
StudentExamAttemptedAlreadyStarted
):
start_exam_attempt
(
self
.
proctored_exam_id
,
self
.
user_id
)
def
test_stop_exam_attempt
(
self
):
def
test_stop_exam_attempt
(
self
):
"""
"""
Stop an exam attempt.
Stop an exam attempt.
"""
"""
proctored_exam_student_attempt
=
self
.
_create_
student
_exam_attempt
()
proctored_exam_student_attempt
=
self
.
_create_
unstarted
_exam_attempt
()
self
.
assertIsNone
(
proctored_exam_student_attempt
.
completed_at
)
self
.
assertIsNone
(
proctored_exam_student_attempt
.
completed_at
)
proctored_exam_attempt_id
=
stop_exam_attempt
(
proctored_exam_attempt_id
=
stop_exam_attempt
(
proctored_exam_student_attempt
.
proctored_exam
,
self
.
user_id
proctored_exam_student_attempt
.
proctored_exam
,
self
.
user_id
...
@@ -237,7 +271,7 @@ class ProctoredExamApiTests(LoggedInTestCase):
...
@@ -237,7 +271,7 @@ class ProctoredExamApiTests(LoggedInTestCase):
Test to get the all the active
Test to get the all the active
exams for the user.
exams for the user.
"""
"""
active_exam_attempt
=
self
.
_create_st
udent
_exam_attempt
()
active_exam_attempt
=
self
.
_create_st
arted
_exam_attempt
()
self
.
assertEqual
(
active_exam_attempt
.
is_active
,
True
)
self
.
assertEqual
(
active_exam_attempt
.
is_active
,
True
)
exam_id
=
create_exam
(
exam_id
=
create_exam
(
course_id
=
self
.
course_id
,
course_id
=
self
.
course_id
,
...
@@ -260,3 +294,7 @@ class ProctoredExamApiTests(LoggedInTestCase):
...
@@ -260,3 +294,7 @@ 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
):
context
=
{
'default_time_limit_mins'
:
90
}
get_student_view
(
self
.
user_id
,
self
.
course_id
,
self
.
content_id
,
context
)
edx_proctoring/tests/test_views.py
View file @
7da5e1c3
...
@@ -486,6 +486,14 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase):
...
@@ -486,6 +486,14 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase):
)
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
ProctoredExamStudentAttempt
.
objects
.
filter
(
proctored_exam_id
=
proctored_exam
.
id
,
user_id
=
self
.
user
.
id
,
external_id
=
proctored_exam
.
external_id
,
)
.
update
(
started_at
=
datetime
.
now
(
pytz
.
UTC
)
)
response
=
self
.
client
.
get
(
response
=
self
.
client
.
get
(
reverse
(
'edx_proctoring.proctored_exam.attempt'
)
reverse
(
'edx_proctoring.proctored_exam.attempt'
)
)
)
...
...
edx_proctoring/views.py
View file @
7da5e1c3
...
@@ -239,7 +239,7 @@ class StudentProctoredExamAttempt(AuthenticatedAPIView):
...
@@ -239,7 +239,7 @@ class StudentProctoredExamAttempt(AuthenticatedAPIView):
def
post
(
self
,
request
):
def
post
(
self
,
request
):
"""
"""
HTTP POST handler. To create an exam.
HTTP POST handler. To create an exam
attempt
.
"""
"""
start_immediately
=
request
.
DATA
.
get
(
'start_clock'
,
'false'
)
.
lower
()
==
'true'
start_immediately
=
request
.
DATA
.
get
(
'start_clock'
,
'false'
)
.
lower
()
==
'true'
exam_id
=
request
.
DATA
.
get
(
'exam_id'
,
None
)
exam_id
=
request
.
DATA
.
get
(
'exam_id'
,
None
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment