Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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-platform
Commits
96d4a895
Commit
96d4a895
authored
Apr 30, 2015
by
zubair-arbi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add 'get_attempts' method for 'ReverificationService'
parent
4d9781aa
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
129 additions
and
44 deletions
+129
-44
lms/djangoapps/verify_student/models.py
+26
-2
lms/djangoapps/verify_student/services.py
+36
-12
lms/djangoapps/verify_student/tests/test_services.py
+67
-30
No files found.
lms/djangoapps/verify_student/models.py
View file @
96d4a895
...
@@ -1028,7 +1028,7 @@ class VerificationStatus(models.Model):
...
@@ -1028,7 +1028,7 @@ class VerificationStatus(models.Model):
get_latest_by
=
"timestamp"
get_latest_by
=
"timestamp"
@classmethod
@classmethod
def
add_verification_status
(
cls
,
checkpoint
,
user
,
status
,
location_id
=
''
):
def
add_verification_status
(
cls
,
checkpoint
,
user
,
status
,
location_id
=
None
):
""" Create new verification status object
""" Create new verification status object
Arguments:
Arguments:
...
@@ -1058,10 +1058,34 @@ class VerificationStatus(models.Model):
...
@@ -1058,10 +1058,34 @@ class VerificationStatus(models.Model):
try
:
try
:
location_id
=
cls
.
objects
.
filter
(
checkpoint
=
checkpoint
)
.
latest
()
.
location_id
location_id
=
cls
.
objects
.
filter
(
checkpoint
=
checkpoint
)
.
latest
()
.
location_id
except
cls
.
DoesNotExist
:
except
cls
.
DoesNotExist
:
location_id
=
''
location_id
=
None
cls
.
objects
.
create
(
checkpoint
=
checkpoint
,
user
=
user
,
status
=
status
,
location_id
=
location_id
)
cls
.
objects
.
create
(
checkpoint
=
checkpoint
,
user
=
user
,
status
=
status
,
location_id
=
location_id
)
@classmethod
def
get_user_attempts
(
cls
,
user_id
,
course_key
,
related_assessment
,
location_id
):
"""
Get re-verification attempts against a user for a given 'checkpoint'
and 'course_id'.
Arguments:
user_id(str): User Id string
course_key(str): A CourseKey of a course
related_assessment(str): Verification checkpoint name
location_id(str): Location of Reverification XBlock in courseware
Returns:
count of re-verification attempts
"""
return
cls
.
objects
.
filter
(
user_id
=
user_id
,
checkpoint__course_id
=
course_key
,
checkpoint__checkpoint_name
=
related_assessment
,
location_id
=
location_id
,
status
=
"submitted"
)
.
count
()
class
InCourseReverificationConfiguration
(
ConfigurationModel
):
class
InCourseReverificationConfiguration
(
ConfigurationModel
):
"""Configure in-course re-verification.
"""Configure in-course re-verification.
...
...
lms/djangoapps/verify_student/services.py
View file @
96d4a895
"""
"""
Implement
the Reverification XBlock "reverification" server
Implement
ation of "reverification" service to communicate with Reverification XBlock
"""
"""
import
logging
import
logging
from
opaque_keys.edx.keys
import
CourseKey
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
from
verify_student.models
import
VerificationCheckpoint
,
VerificationStatus
,
SkippedReverification
from
django.db
import
IntegrityError
from
django.db
import
IntegrityError
from
opaque_keys.edx.keys
import
CourseKey
from
verify_student.models
import
VerificationCheckpoint
,
VerificationStatus
,
SkippedReverification
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
class
ReverificationService
(
object
):
class
ReverificationService
(
object
):
"""
Service to implement the Reverification XBlock "reverification" service
"""
Reverification XBlock service
"""
"""
def
get_status
(
self
,
user_id
,
course_id
,
related_assessment
):
def
get_status
(
self
,
user_id
,
course_id
,
related_assessment
):
""" Check if the user has any verification attempt or has skipped the verification
"""
Get verification attempt status against a user for a given 'checkpoint'
and 'course_id'.
Args:
Args:
user_id(str): User Id string
user_id(str): User Id string
course_id(str): A string of course
_
id
course_id(str): A string of course
id
related_assessment(str): Verification checkpoint name
related_assessment(str): Verification checkpoint name
Returns:
Returns:
...
@@ -44,10 +49,11 @@ class ReverificationService(object):
...
@@ -44,10 +49,11 @@ class ReverificationService(object):
return
None
return
None
def
start_verification
(
self
,
course_id
,
related_assessment
,
item_id
):
def
start_verification
(
self
,
course_id
,
related_assessment
,
item_id
):
""" Get or create the verification checkpoint and return the re-verification link
"""
Create re-verification link against a verification checkpoint.
Args:
Args:
course_id(str): A string of course
_
id
course_id(str): A string of course
id
related_assessment(str): Verification checkpoint name
related_assessment(str): Verification checkpoint name
Returns:
Returns:
...
@@ -66,12 +72,13 @@ class ReverificationService(object):
...
@@ -66,12 +72,13 @@ class ReverificationService(object):
return
re_verification_link
return
re_verification_link
def
skip_verification
(
self
,
checkpoint_name
,
user_id
,
course_id
):
def
skip_verification
(
self
,
checkpoint_name
,
user_id
,
course_id
):
"""Create the add verification attempt
"""
Add skipped verification attempt entry against a given 'checkpoint'
Args:
Args:
course_id(str): A string of course_id
user_id(str): User Id string
checkpoint_name(str): Verification checkpoint name
checkpoint_name(str): Verification checkpoint name
user_id(str): User Id string
course_id(str): A string of course_id
Returns:
Returns:
None
None
...
@@ -84,3 +91,20 @@ class ReverificationService(object):
...
@@ -84,3 +91,20 @@ class ReverificationService(object):
SkippedReverification
.
add_skipped_reverification_attempt
(
checkpoint
,
user_id
,
course_key
)
SkippedReverification
.
add_skipped_reverification_attempt
(
checkpoint
,
user_id
,
course_key
)
except
IntegrityError
:
except
IntegrityError
:
log
.
exception
(
"Skipped attempt already exists for user
%
s: with course
%
s:"
,
user_id
,
unicode
(
course_id
))
log
.
exception
(
"Skipped attempt already exists for user
%
s: with course
%
s:"
,
user_id
,
unicode
(
course_id
))
def
get_attempts
(
self
,
user_id
,
course_id
,
related_assessment
,
location_id
):
"""
Get re-verification attempts against a user for a given 'checkpoint'
and 'course_id'.
Args:
user_id(str): User Id string
course_id(str): A string of course id
related_assessment(str): Verification checkpoint name
location_id(str): Location of Reverification XBlock in courseware
Returns:
Number of re-verification attempts of a user
"""
course_key
=
CourseKey
.
from_string
(
course_id
)
return
VerificationStatus
.
get_user_attempts
(
user_id
,
course_key
,
related_assessment
,
location_id
)
lms/djangoapps/verify_student/tests/test_services.py
View file @
96d4a895
# encoding: utf-8
"""
"""
Tests of re
verify
service.
Tests of re
-verification
service.
"""
"""
import
ddt
import
ddt
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
from
xmodule.modulestore.tests.factories
import
CourseFactory
,
ItemFactory
from
student.tests.factories
import
UserFactory
from
course_modes.tests.factories
import
CourseModeFactory
from
course_modes.tests.factories
import
CourseModeFactory
from
verify_student.services
import
ReverificationService
from
student.tests.factories
import
UserFactory
from
verify_student.models
import
VerificationCheckpoint
,
VerificationStatus
,
SkippedReverification
from
verify_student.models
import
VerificationCheckpoint
,
VerificationStatus
,
SkippedReverification
from
verify_student.services
import
ReverificationService
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
from
xmodule.modulestore.tests.factories
import
CourseFactory
,
ItemFactory
@ddt.ddt
@ddt.ddt
class
TestReverif
y
Service
(
ModuleStoreTestCase
):
class
TestReverif
ication
Service
(
ModuleStoreTestCase
):
"""
"""
Tests for the re-verification service
Tests for the re-verification service
.
"""
"""
def
setUp
(
self
):
def
setUp
(
self
):
super
(
TestReverif
y
Service
,
self
)
.
setUp
()
super
(
TestReverif
ication
Service
,
self
)
.
setUp
()
self
.
user
=
UserFactory
.
create
(
username
=
"rusty"
,
password
=
"test"
)
self
.
user
=
UserFactory
.
create
(
username
=
"rusty"
,
password
=
"test"
)
course
=
CourseFactory
.
create
(
org
=
'Robot'
,
number
=
'999'
,
display_name
=
'Test Course'
)
course
=
CourseFactory
.
create
(
org
=
'Robot'
,
number
=
'999'
,
display_name
=
'Test Course'
)
...
@@ -27,18 +29,18 @@ class TestReverifyService(ModuleStoreTestCase):
...
@@ -27,18 +29,18 @@ class TestReverifyService(ModuleStoreTestCase):
mode_slug
=
"verified"
,
mode_slug
=
"verified"
,
course_id
=
self
.
course_key
,
course_id
=
self
.
course_key
,
min_price
=
100
,
min_price
=
100
,
suggested_prices
=
''
)
)
self
.
item
=
ItemFactory
.
create
(
parent
=
course
,
category
=
'chapter'
,
display_name
=
'Test Section'
)
self
.
item
=
ItemFactory
.
create
(
parent
=
course
,
category
=
'chapter'
,
display_name
=
'Test Section'
)
@ddt.data
(
"final_term"
,
"mid_term"
)
@ddt.data
(
"final_term"
,
"mid_term"
)
def
test_start_verification
(
self
,
checkpoint_name
):
def
test_start_verification
(
self
,
checkpoint_name
):
"""Testing start verification service. If checkpoint exists for specific course then returns the checkpoint
otherwise created that checkpoint.
"""
"""
Test the 'start_verification' service method. If checkpoint exists for
rev
=
ReverificationService
()
a specific course then return the checkpoint otherwise create that
rev
.
start_verification
(
unicode
(
self
.
course_key
),
checkpoint_name
,
self
.
item
.
location
)
checkpoint.
"""
reverification_service
=
ReverificationService
()
reverification_service
.
start_verification
(
unicode
(
self
.
course_key
),
checkpoint_name
,
self
.
item
.
location
)
expected_url
=
(
expected_url
=
(
'/verify_student/reverify'
'/verify_student/reverify'
'/{course_key}'
'/{course_key}'
...
@@ -47,36 +49,71 @@ class TestReverifyService(ModuleStoreTestCase):
...
@@ -47,36 +49,71 @@ class TestReverifyService(ModuleStoreTestCase):
)
.
format
(
course_key
=
unicode
(
self
.
course_key
),
checkpoint_name
=
checkpoint_name
,
usage_id
=
self
.
item
.
location
)
)
.
format
(
course_key
=
unicode
(
self
.
course_key
),
checkpoint_name
=
checkpoint_name
,
usage_id
=
self
.
item
.
location
)
self
.
assertEqual
(
self
.
assertEqual
(
expected_url
,
rev
.
start_verification
(
unicode
(
self
.
course_key
),
checkpoint_name
,
self
.
item
.
location
)
expected_url
,
reverification_service
.
start_verification
(
unicode
(
self
.
course_key
),
checkpoint_name
,
self
.
item
.
location
)
)
)
def
test_get_status
(
self
):
def
test_get_status
(
self
):
""" Check if the user has any verification attempt for the checkpoint and course_id """
"""
Test the verification statuses of a user for a given 'checkpoint' and
'course_id'.
"""
checkpoint_name
=
'final_term'
checkpoint_name
=
'final_term'
rev
=
ReverificationService
()
reverification_service
=
ReverificationService
()
self
.
assertIsNone
(
rev
.
get_status
(
self
.
user
.
id
,
unicode
(
self
.
course_key
),
checkpoint_name
))
self
.
assertIsNone
(
reverification_service
.
get_status
(
self
.
user
.
id
,
unicode
(
self
.
course_key
),
checkpoint_name
))
checkpoint_obj
=
VerificationCheckpoint
.
objects
.
create
(
checkpoint_obj
=
VerificationCheckpoint
.
objects
.
create
(
course_id
=
unicode
(
self
.
course_key
),
checkpoint_name
=
checkpoint_name
course_id
=
unicode
(
self
.
course_key
),
checkpoint_name
=
checkpoint_name
)
)
VerificationStatus
.
objects
.
create
(
checkpoint
=
checkpoint_obj
,
user
=
self
.
user
,
status
=
'submitted'
)
VerificationStatus
.
objects
.
create
(
checkpoint
=
checkpoint_obj
,
user
=
self
.
user
,
status
=
'submitted'
)
self
.
assertEqual
(
rev
.
get_status
(
self
.
user
.
id
,
unicode
(
self
.
course_key
),
checkpoint_name
),
'submitted'
)
self
.
assertEqual
(
reverification_service
.
get_status
(
self
.
user
.
id
,
unicode
(
self
.
course_key
),
checkpoint_name
),
'submitted'
)
def
test_skip_verification
(
self
):
VerificationStatus
.
objects
.
create
(
checkpoint
=
checkpoint_obj
,
user
=
self
.
user
,
status
=
'submitted'
)
""" Adding the test skip verification attempt for the user """
self
.
assertEqual
(
reverification_service
.
get_status
(
self
.
user
.
id
,
unicode
(
self
.
course_key
),
checkpoint_name
),
'submitted'
)
def
test_skip_verification
(
self
):
"""
Adding the test skip verification attempt for the user
"""
checkpoint_name
=
'final_term'
checkpoint_name
=
'final_term'
rev
=
ReverificationService
()
reverification_service
=
ReverificationService
()
VerificationCheckpoint
.
objects
.
create
(
VerificationCheckpoint
.
objects
.
create
(
course_id
=
unicode
(
self
.
course_key
),
checkpoint_name
=
checkpoint_name
course_id
=
unicode
(
self
.
course_key
),
checkpoint_name
=
checkpoint_name
)
)
rev
.
skip_verification
(
checkpoint_name
,
self
.
user
.
id
,
unicode
(
self
.
course_key
))
reverification_service
.
skip_verification
(
checkpoint_name
,
self
.
user
.
id
,
unicode
(
self
.
course_key
))
self
.
assertEqual
(
1
,
SkippedReverification
.
objects
.
filter
(
user
=
self
.
user
,
course_id
=
self
.
course_key
)
.
count
())
reverification_service
.
skip_verification
(
checkpoint_name
,
self
.
user
.
id
,
unicode
(
self
.
course_key
))
self
.
assertEqual
(
1
,
SkippedReverification
.
objects
.
filter
(
user
=
self
.
user
,
course_id
=
self
.
course_key
)
.
count
())
self
.
assertEqual
(
1
,
SkippedReverification
.
objects
.
filter
(
user
=
self
.
user
,
course_id
=
self
.
course_key
)
.
count
())
rev
.
skip_verification
(
checkpoint_name
,
self
.
user
.
id
,
unicode
(
self
.
course_key
))
def
test_get_attempts
(
self
):
"""
Check verification attempts count against a user for a given
'checkpoint' and 'course_id'.
"""
checkpoint_name
=
'final_term'
reverification_service
=
ReverificationService
()
course_id
=
unicode
(
self
.
course_key
)
self
.
assertEqual
(
reverification_service
.
get_attempts
(
self
.
user
.
id
,
course_id
,
checkpoint_name
,
location_id
=
None
),
0
)
self
.
assertEqual
(
1
,
SkippedReverification
.
objects
.
filter
(
user
=
self
.
user
,
course_id
=
self
.
course_key
)
.
count
())
# now create a checkpoint and add user's entry against it then test
# that the 'get_attempts' service method returns count accordingly
checkpoint_obj
=
VerificationCheckpoint
.
objects
.
create
(
course_id
=
course_id
,
checkpoint_name
=
checkpoint_name
)
VerificationStatus
.
objects
.
create
(
checkpoint
=
checkpoint_obj
,
user
=
self
.
user
,
status
=
'submitted'
)
self
.
assertEqual
(
reverification_service
.
get_attempts
(
self
.
user
.
id
,
course_id
,
checkpoint_name
,
location_id
=
None
),
1
)
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