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
edx
edx-proctoring
Commits
4510a7ca
Commit
4510a7ca
authored
Sep 18, 2015
by
Muhammad Shoaib
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated the code and test cases
parent
37334953
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
34 deletions
+26
-34
edx_proctoring/tests/test_views.py
+6
-6
edx_proctoring/views.py
+20
-28
No files found.
edx_proctoring/tests/test_views.py
View file @
4510a7ca
...
@@ -758,7 +758,7 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase):
...
@@ -758,7 +758,7 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase):
attempt_id
=
response_data
[
'exam_attempt_id'
]
attempt_id
=
response_data
[
'exam_attempt_id'
]
self
.
assertGreater
(
attempt_id
,
0
)
self
.
assertGreater
(
attempt_id
,
0
)
# now set the user is_staff t
0 f
alse
# now set the user is_staff t
o F
alse
# and also user is not a course staff
# and also user is not a course staff
self
.
user
.
is_staff
=
False
self
.
user
.
is_staff
=
False
self
.
user
.
save
()
self
.
user
.
save
()
...
@@ -770,7 +770,7 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase):
...
@@ -770,7 +770,7 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase):
self
.
assertEqual
(
response
.
status_code
,
403
)
self
.
assertEqual
(
response
.
status_code
,
403
)
response_data
=
json
.
loads
(
response
.
content
)
response_data
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
response_data
[
'detail'
],
'Must be a
instructor of the course
to Perform this request.'
)
self
.
assertEqual
(
response_data
[
'detail'
],
'Must be a
Staff User
to Perform this request.'
)
def
test_read_others_attempt
(
self
):
def
test_read_others_attempt
(
self
):
"""
"""
...
@@ -1788,7 +1788,7 @@ class TestExamAllowanceView(LoggedInTestCase):
...
@@ -1788,7 +1788,7 @@ class TestExamAllowanceView(LoggedInTestCase):
self
.
user
.
save
()
self
.
user
.
save
()
set_runtime_service
(
'instructor'
,
MockInstructorService
(
is_user_course_staff
=
False
))
set_runtime_service
(
'instructor'
,
MockInstructorService
(
is_user_course_staff
=
False
))
# Create an exam.
# Create an exam.
proctor
ed_exam
=
ProctoredExam
.
objects
.
create
(
tim
ed_exam
=
ProctoredExam
.
objects
.
create
(
course_id
=
'a/b/c'
,
course_id
=
'a/b/c'
,
content_id
=
'test_content'
,
content_id
=
'test_content'
,
exam_name
=
'Test Exam'
,
exam_name
=
'Test Exam'
,
...
@@ -1797,7 +1797,7 @@ class TestExamAllowanceView(LoggedInTestCase):
...
@@ -1797,7 +1797,7 @@ class TestExamAllowanceView(LoggedInTestCase):
is_proctored
=
False
is_proctored
=
False
)
)
allowance_data
=
{
allowance_data
=
{
'exam_id'
:
proctor
ed_exam
.
id
,
'exam_id'
:
tim
ed_exam
.
id
,
'user_info'
:
self
.
student_taking_exam
.
username
,
'user_info'
:
self
.
student_taking_exam
.
username
,
'key'
:
'a_key'
,
'key'
:
'a_key'
,
'value'
:
'30'
'value'
:
'30'
...
@@ -1808,7 +1808,7 @@ class TestExamAllowanceView(LoggedInTestCase):
...
@@ -1808,7 +1808,7 @@ class TestExamAllowanceView(LoggedInTestCase):
)
)
self
.
assertEqual
(
response
.
status_code
,
403
)
self
.
assertEqual
(
response
.
status_code
,
403
)
response_data
=
json
.
loads
(
response
.
content
)
response_data
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
response_data
[
'detail'
],
'Must be a
instructor of the course
to Perform this request.'
)
self
.
assertEqual
(
response_data
[
'detail'
],
'Must be a
Staff User
to Perform this request.'
)
def
test_get_allowances_for_course
(
self
):
def
test_get_allowances_for_course
(
self
):
"""
"""
...
@@ -1881,7 +1881,7 @@ class TestExamAllowanceView(LoggedInTestCase):
...
@@ -1881,7 +1881,7 @@ class TestExamAllowanceView(LoggedInTestCase):
self
.
assertEqual
(
response
.
status_code
,
403
)
self
.
assertEqual
(
response
.
status_code
,
403
)
response_data
=
json
.
loads
(
response
.
content
)
response_data
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
response_data
[
'detail'
],
'Must be a
instructor of the course
to Perform this request.'
)
self
.
assertEqual
(
response_data
[
'detail'
],
'Must be a
Staff User
to Perform this request.'
)
def
test_get_timed_exam_allowances_for_course
(
self
):
# pylint: disable=invalid-name
def
test_get_timed_exam_allowances_for_course
(
self
):
# pylint: disable=invalid-name
"""
"""
...
...
edx_proctoring/views.py
View file @
4510a7ca
...
@@ -71,38 +71,30 @@ def require_course_or_global_staff(func):
...
@@ -71,38 +71,30 @@ def require_course_or_global_staff(func):
course_id
=
kwargs
[
'course_id'
]
if
'course_id'
in
kwargs
else
None
course_id
=
kwargs
[
'course_id'
]
if
'course_id'
in
kwargs
else
None
exam_id
=
request
.
DATA
.
get
(
'exam_id'
,
None
)
exam_id
=
request
.
DATA
.
get
(
'exam_id'
,
None
)
attempt_id
=
kwargs
[
'attempt_id'
]
if
'attempt_id'
in
kwargs
else
None
attempt_id
=
kwargs
[
'attempt_id'
]
if
'attempt_id'
in
kwargs
else
None
response_message
=
_
(
"Must be a instructor of the course to Perform this request."
)
if
request
.
user
.
is_staff
:
if
request
.
user
.
is_staff
:
is_request_allowed
=
True
return
func
(
request
,
*
args
,
**
kwargs
)
elif
course_id
is
not
None
:
else
:
if
course_id
is
None
:
if
exam_id
is
not
None
:
exam
=
ProctoredExam
.
get_exam_by_id
(
exam_id
)
course_id
=
exam
.
course_id
elif
attempt_id
is
not
None
:
exam_attempt
=
ProctoredExamStudentAttempt
.
objects
.
get_exam_attempt_by_id
(
attempt_id
)
course_id
=
exam_attempt
.
proctored_exam
.
course_id
else
:
response_message
=
_
(
"could not determine the course_id"
)
return
Response
(
status
=
status
.
HTTP_403_FORBIDDEN
,
data
=
{
"detail"
:
response_message
}
)
if
instructor_service
.
is_course_staff
(
request
.
user
,
course_id
):
if
instructor_service
.
is_course_staff
(
request
.
user
,
course_id
):
is_request_allowed
=
True
return
func
(
request
,
*
args
,
**
kwargs
)
else
:
else
:
is_request_allowed
=
False
return
Response
(
elif
exam_id
is
not
None
:
status
=
status
.
HTTP_403_FORBIDDEN
,
# get the course_id from the exam
data
=
{
"detail"
:
_
(
"Must be a Staff User to Perform this request."
)}
exam
=
ProctoredExam
.
get_exam_by_id
(
exam_id
)
)
if
instructor_service
.
is_course_staff
(
request
.
user
,
exam
.
course_id
):
is_request_allowed
=
True
else
:
is_request_allowed
=
False
elif
attempt_id
is
not
None
:
exam_attempt
=
ProctoredExamStudentAttempt
.
objects
.
get_exam_attempt_by_id
(
attempt_id
)
if
instructor_service
.
is_course_staff
(
request
.
user
,
exam_attempt
.
proctored_exam
.
course_id
):
is_request_allowed
=
True
else
:
is_request_allowed
=
False
else
:
is_request_allowed
=
False
response_message
=
_
(
"Must be a Staff User to Perform this request."
)
if
is_request_allowed
:
return
func
(
request
,
*
args
,
**
kwargs
)
else
:
return
Response
(
status
=
status
.
HTTP_403_FORBIDDEN
,
data
=
{
"detail"
:
response_message
}
)
return
wrapped
return
wrapped
...
...
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