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
7f1a0a5d
Commit
7f1a0a5d
authored
Jun 30, 2015
by
Afzal Wali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added humanized time.
parent
4437e5e4
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
122 additions
and
22 deletions
+122
-22
edx_proctoring/api.py
+2
-1
edx_proctoring/templates/proctoring/seq_timed_exam_entrance.html
+1
-1
edx_proctoring/tests/test_utils.py
+44
-0
edx_proctoring/tests/test_views.py
+33
-20
edx_proctoring/utils.py
+42
-0
No files found.
edx_proctoring/api.py
View file @
7f1a0a5d
...
@@ -19,6 +19,7 @@ from edx_proctoring.models import (
...
@@ -19,6 +19,7 @@ from edx_proctoring.models import (
)
)
from
edx_proctoring.serializers
import
ProctoredExamSerializer
,
ProctoredExamStudentAttemptSerializer
,
\
from
edx_proctoring.serializers
import
ProctoredExamSerializer
,
ProctoredExamStudentAttemptSerializer
,
\
ProctoredExamStudentAllowanceSerializer
ProctoredExamStudentAllowanceSerializer
from
edx_proctoring.utils
import
humanized_time
def
create_exam
(
course_id
,
content_id
,
exam_name
,
time_limit_mins
,
def
create_exam
(
course_id
,
content_id
,
exam_name
,
time_limit_mins
,
...
@@ -252,7 +253,7 @@ def get_student_view(user_id, course_id, content_id, context):
...
@@ -252,7 +253,7 @@ def get_student_view(user_id, course_id, content_id, context):
if
student_view_template
:
if
student_view_template
:
template
=
loader
.
get_template
(
student_view_template
)
template
=
loader
.
get_template
(
student_view_template
)
django_context
=
Context
(
context
)
django_context
=
Context
(
context
)
total_time
=
str
(
timedelta
(
seconds
=
60
*
context
[
'default_time_limit_mins'
])
)
total_time
=
humanized_time
(
context
[
'default_time_limit_mins'
]
)
django_context
.
update
({
django_context
.
update
({
'total_time'
:
total_time
,
'total_time'
:
total_time
,
'exam_id'
:
exam_id
,
'exam_id'
:
exam_id
,
...
...
edx_proctoring/templates/proctoring/seq_timed_exam_entrance.html
View file @
7f1a0a5d
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
<div
class=
"sequence"
data-exam-id=
"{{exam_id}}"
>
<div
class=
"sequence"
data-exam-id=
"{{exam_id}}"
>
<h3>
<h3>
{% blocktrans %}
{% blocktrans %}
{{ display_name }} is a Timed Exam (
{{total_time}}
)
{{ display_name }} is a Timed Exam (
{{total_time}}
)
{% endblocktrans %}
{% endblocktrans %}
</h3>
</h3>
<p>
<p>
...
...
edx_proctoring/tests/test_utils.py
0 → 100644
View file @
7f1a0a5d
"""
File that contains tests for the util methods.
"""
import
unittest
from
edx_proctoring.utils
import
humanized_time
class
TestHumanizedTime
(
unittest
.
TestCase
):
"""
Class to test the humanized_time utility function
"""
def
test_humanized_time
(
self
):
"""
tests the humanized_time utility function against different values.
"""
human_time
=
humanized_time
(
0
)
self
.
assertEqual
(
human_time
,
"0 Minutes"
)
human_time
=
humanized_time
(
1
)
self
.
assertEqual
(
human_time
,
"1 Minute"
)
human_time
=
humanized_time
(
10
)
self
.
assertEqual
(
human_time
,
"10 Minutes"
)
human_time
=
humanized_time
(
60
)
self
.
assertEqual
(
human_time
,
"1 Hour"
)
human_time
=
humanized_time
(
61
)
self
.
assertEqual
(
human_time
,
"1 Hour and 1 Minute"
)
human_time
=
humanized_time
(
62
)
self
.
assertEqual
(
human_time
,
"1 Hour and 2 Minutes"
)
human_time
=
humanized_time
(
120
)
self
.
assertEqual
(
human_time
,
"2 Hours"
)
human_time
=
humanized_time
(
121
)
self
.
assertEqual
(
human_time
,
"2 Hours and 1 Minute"
)
human_time
=
humanized_time
(
150
)
self
.
assertEqual
(
human_time
,
"2 Hours and 30 Minutes"
)
human_time
=
humanized_time
(
180
)
self
.
assertEqual
(
human_time
,
"3 Hours"
)
edx_proctoring/tests/test_views.py
View file @
7f1a0a5d
...
@@ -49,26 +49,6 @@ class ProctoredExamsApiTests(LoggedInTestCase):
...
@@ -49,26 +49,6 @@ class ProctoredExamsApiTests(LoggedInTestCase):
self
.
assertEqual
(
response
.
status_code
,
403
)
self
.
assertEqual
(
response
.
status_code
,
403
)
class
StudentProctoredExamAttempt
(
LoggedInTestCase
):
"""
Tests for StudentProctoredExamAttempt
"""
def
setUp
(
self
):
super
(
StudentProctoredExamAttempt
,
self
)
.
setUp
()
self
.
user
.
is_staff
=
True
self
.
user
.
save
()
self
.
client
.
login_user
(
self
.
user
)
def
test_get_exam_attempt
(
self
):
"""
Test Case for retrieving student proctored exam attempt status.
"""
response
=
self
.
client
.
get
(
reverse
(
'edx_proctoring.proctored_exam.attempt'
)
)
self
.
assertEqual
(
response
.
status_code
,
200
)
class
ProctoredExamViewTests
(
LoggedInTestCase
):
class
ProctoredExamViewTests
(
LoggedInTestCase
):
"""
"""
Tests for the ProctoredExamView
Tests for the ProctoredExamView
...
@@ -476,6 +456,39 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase):
...
@@ -476,6 +456,39 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase):
response_data
=
json
.
loads
(
response
.
content
)
response_data
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
response_data
[
'detail'
],
'Error. Trying to stop an exam that is not in progress.'
)
self
.
assertEqual
(
response_data
[
'detail'
],
'Error. Trying to stop an exam that is not in progress.'
)
def
test_get_exam_attempt
(
self
):
"""
Test Case for retrieving student proctored exam attempt status.
"""
# 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
)
response
=
self
.
client
.
get
(
reverse
(
'edx_proctoring.proctored_exam.attempt'
)
)
self
.
assertEqual
(
response
.
status_code
,
200
)
attempt_data
=
{
'exam_id'
:
proctored_exam
.
id
,
'user_id'
:
self
.
student_taking_exam
.
id
,
'external_id'
:
proctored_exam
.
external_id
}
response
=
self
.
client
.
post
(
reverse
(
'edx_proctoring.proctored_exam.attempt'
),
attempt_data
)
self
.
assertEqual
(
response
.
status_code
,
200
)
response
=
self
.
client
.
get
(
reverse
(
'edx_proctoring.proctored_exam.attempt'
)
)
self
.
assertEqual
(
response
.
status_code
,
200
)
class
TestExamAllowanceView
(
LoggedInTestCase
):
class
TestExamAllowanceView
(
LoggedInTestCase
):
"""
"""
...
...
edx_proctoring/utils.py
View file @
7f1a0a5d
...
@@ -13,3 +13,45 @@ class AuthenticatedAPIView(APIView):
...
@@ -13,3 +13,45 @@ class AuthenticatedAPIView(APIView):
"""
"""
authentication_classes
=
(
SessionAuthentication
,)
authentication_classes
=
(
SessionAuthentication
,)
permission_classes
=
(
IsAuthenticated
,)
permission_classes
=
(
IsAuthenticated
,)
def
humanized_time
(
time_in_minutes
):
"""
Converts the given value in minutes to a more human readable format
1 -> 1 Minute
2 -> 2 Minutes
60 -> 1 hour
90 -> 1 hour and 30 Minutes
120 -> 2 hours
"""
hours
=
int
(
time_in_minutes
/
60
)
minutes
=
time_in_minutes
%
60
template
=
""
hours_present
=
False
if
hours
==
0
:
hours_present
=
False
elif
hours
==
1
:
template
=
"{num_of_hours} Hour"
hours_present
=
True
elif
hours
>=
2
:
template
=
"{num_of_hours} Hours"
hours_present
=
True
if
minutes
==
0
:
if
not
hours_present
:
template
=
"{num_of_minutes} Minutes"
elif
minutes
==
1
:
if
hours_present
:
template
+=
" and {num_of_minutes} Minute"
else
:
template
+=
"{num_of_minutes} Minute"
elif
minutes
>=
2
:
if
hours_present
:
template
+=
" and {num_of_minutes} Minutes"
else
:
template
+=
"{num_of_minutes} Minutes"
human_time
=
template
.
format
(
num_of_hours
=
hours
,
num_of_minutes
=
minutes
)
return
human_time
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