Commit a900e1f7 by Aamir

Merge pull request #7660 from edx/aamir-khan/ECOM-1396/checkoint-name-field

Aamir khan/ecom 1396/checkoint name field
parents 2f3ff43e d606ae97
...@@ -46,5 +46,12 @@ class ReverificationService(object): ...@@ -46,5 +46,12 @@ class ReverificationService(object):
""" """
course_key = CourseKey.from_string(course_id) course_key = CourseKey.from_string(course_id)
VerificationCheckpoint.objects.get_or_create(course_id=course_key, checkpoint_name=checkpoint_name) VerificationCheckpoint.objects.get_or_create(course_id=course_key, checkpoint_name=checkpoint_name)
re_verification_link = reverse("verify_student_incourse_reverify", args=(course_id, checkpoint_name, item_id)) re_verification_link = reverse(
'verify_student_incourse_reverify',
args=(
unicode(course_key),
unicode(checkpoint_name),
unicode(item_id)
)
)
return re_verification_link return re_verification_link
# encoding: utf-8
"""
Tests of reverify service.
"""
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 verify_student.services import ReverificationService
from verify_student.models import VerificationCheckpoint, VerificationStatus
@ddt.ddt
class TestReverifyService(ModuleStoreTestCase):
"""
Tests for the re-verification service
"""
def setUp(self):
super(TestReverifyService, self).setUp()
self.user = UserFactory.create(username="rusty", password="test")
course = CourseFactory.create(org='Robot', number='999', display_name='Test Course')
self.course_key = course.id
CourseModeFactory(
mode_slug="verified",
course_id=self.course_key,
min_price=100,
suggested_prices=''
)
self.item = ItemFactory.create(parent=course, category='chapter', display_name='Test Section')
@ddt.data("final_term", "mid_term")
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.
"""
rev = ReverificationService()
rev.start_verification(unicode(self.course_key), checkpoint_name, self.item.location)
expected_url = (
'/verify_student/reverify'
'/{course_key}'
'/{checkpoint_name}'
'/{usage_id}/'
).format(course_key=unicode(self.course_key), checkpoint_name=checkpoint_name, usage_id=self.item.location)
self.assertEqual(
expected_url, rev.start_verification(unicode(self.course_key), checkpoint_name, self.item.location)
)
def test_get_status(self):
""" Check if the user has any verification attempt for the checkpoint and course_id """
checkpoint_name = 'final_term'
rev = ReverificationService()
self.assertIsNone(rev.get_status(self.user.id, unicode(self.course_key), checkpoint_name))
checkpoint_obj = VerificationCheckpoint.objects.create(
course_id=unicode(self.course_key), checkpoint_name=checkpoint_name
)
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')
...@@ -1888,5 +1888,5 @@ class TestInCourseReverifyView(ModuleStoreTestCase): ...@@ -1888,5 +1888,5 @@ class TestInCourseReverifyView(ModuleStoreTestCase):
kwargs={ kwargs={
"course_id": unicode(course_key), "course_id": unicode(course_key),
"checkpoint_name": checkpoint, "checkpoint_name": checkpoint,
"location": unicode(self.reverification_location) "usage_id": unicode(self.reverification_location)
}) })
...@@ -143,8 +143,10 @@ urlpatterns = patterns( ...@@ -143,8 +143,10 @@ urlpatterns = patterns(
# Users are sent to this end-point from within courseware # Users are sent to this end-point from within courseware
# to re-verify their identities by re-submitting face photos. # to re-verify their identities by re-submitting face photos.
url( url(
r'^reverify/{course_id}/{checkpoint}/(?P<location>.*)/$'.format( r'^reverify/{course_id}/{checkpoint}/{usage_id}/$'.format(
course_id=settings.COURSE_ID_PATTERN, checkpoint=settings.CHECKPOINT_PATTERN course_id=settings.COURSE_ID_PATTERN,
checkpoint=settings.CHECKPOINT_PATTERN,
usage_id=settings.USAGE_ID_PATTERN
), ),
views.InCourseReverifyView.as_view(), views.InCourseReverifyView.as_view(),
name="verify_student_incourse_reverify" name="verify_student_incourse_reverify"
......
...@@ -1115,9 +1115,10 @@ class InCourseReverifyView(View): ...@@ -1115,9 +1115,10 @@ class InCourseReverifyView(View):
Does not need to worry about pricing Does not need to worry about pricing
""" """
@method_decorator(login_required) @method_decorator(login_required)
def get(self, request, course_id, checkpoint_name, location): def get(self, request, course_id, checkpoint_name, usage_id):
""" Display the view for face photo submission""" """ Display the view for face photo submission"""
# Check the in-course re-verification is enabled or not # Check the in-course re-verification is enabled or not
incourse_reverify_enabled = InCourseReverificationConfiguration.current().enabled incourse_reverify_enabled = InCourseReverificationConfiguration.current().enabled
if not incourse_reverify_enabled: if not incourse_reverify_enabled:
raise Http404 raise Http404
...@@ -1146,12 +1147,12 @@ class InCourseReverifyView(View): ...@@ -1146,12 +1147,12 @@ class InCourseReverifyView(View):
'course_name': course.display_name_with_default, 'course_name': course.display_name_with_default,
'checkpoint_name': checkpoint_name, 'checkpoint_name': checkpoint_name,
'platform_name': settings.PLATFORM_NAME, 'platform_name': settings.PLATFORM_NAME,
'location': location 'usage_id': usage_id
} }
return render_to_response("verify_student/incourse_reverify.html", context) return render_to_response("verify_student/incourse_reverify.html", context)
@method_decorator(login_required) @method_decorator(login_required)
def post(self, request, course_id, checkpoint_name, location): def post(self, request, course_id, checkpoint_name, usage_id):
"""Submits the re-verification attempt to SoftwareSecure """Submits the re-verification attempt to SoftwareSecure
Args: Args:
...@@ -1172,7 +1173,7 @@ class InCourseReverifyView(View): ...@@ -1172,7 +1173,7 @@ class InCourseReverifyView(View):
user = request.user user = request.user
try: try:
course_key = CourseKey.from_string(course_id) course_key = CourseKey.from_string(course_id)
usage_key = UsageKey.from_string(location).replace(course_key=course_key) usage_key = UsageKey.from_string(usage_id).replace(course_key=course_key)
except InvalidKeyError: except InvalidKeyError:
raise Http404(u"Invalid course_key or usage_key") raise Http404(u"Invalid course_key or usage_key")
course = modulestore().get_course(course_key) course = modulestore().get_course(course_key)
...@@ -1187,7 +1188,7 @@ class InCourseReverifyView(View): ...@@ -1187,7 +1188,7 @@ class InCourseReverifyView(View):
'error': True, 'error': True,
'errorMsg': _("No checkpoint found"), 'errorMsg': _("No checkpoint found"),
'platform_name': settings.PLATFORM_NAME, 'platform_name': settings.PLATFORM_NAME,
'location': location 'usage_id': usage_id
} }
return render_to_response("verify_student/incourse_reverify.html", context) return render_to_response("verify_student/incourse_reverify.html", context)
init_verification = SoftwareSecurePhotoVerification.get_initial_verification(user) init_verification = SoftwareSecurePhotoVerification.get_initial_verification(user)
......
...@@ -2252,7 +2252,7 @@ ECOMMERCE_API_SIGNING_KEY = None ...@@ -2252,7 +2252,7 @@ ECOMMERCE_API_SIGNING_KEY = None
ECOMMERCE_API_TIMEOUT = 5 ECOMMERCE_API_TIMEOUT = 5
# Reverification checkpoint name pattern # Reverification checkpoint name pattern
CHECKPOINT_PATTERN = r'(?P<checkpoint_name>\w+)' CHECKPOINT_PATTERN = r'(?P<checkpoint_name>[\w ]+)'
# For the fields override feature # For the fields override feature
# If using FEATURES['INDIVIDUAL_DUE_DATES'], you should add # If using FEATURES['INDIVIDUAL_DUE_DATES'], you should add
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
courseKey: el.data('course-key'), courseKey: el.data('course-key'),
checkpointName: el.data('checkpoint-name'), checkpointName: el.data('checkpoint-name'),
platformName: el.data('platform-name'), platformName: el.data('platform-name'),
location: el.data('location'), usageId: el.data('usage-id'),
errorModel: errorView.model errorModel: errorView.model
}).render(); }).render();
......
...@@ -18,7 +18,7 @@ var edx = edx || {}; ...@@ -18,7 +18,7 @@ var edx = edx || {};
courseKey: '', courseKey: '',
checkpointName: '', checkpointName: '',
faceImage: '', faceImage: '',
location: '' usageId: ''
}, },
sync: function( method ) { sync: function( method ) {
...@@ -28,10 +28,10 @@ var edx = edx || {}; ...@@ -28,10 +28,10 @@ var edx = edx || {};
face_image: model.get( 'faceImage' ) face_image: model.get( 'faceImage' )
}, },
url = _.str.sprintf( url = _.str.sprintf(
'/verify_student/reverify/%(courseKey)s/%(checkpointName)s/%(location)s/', { '/verify_student/reverify/%(courseKey)s/%(checkpointName)s/%(usageId)s/', {
courseKey: model.get('courseKey'), courseKey: model.get('courseKey'),
checkpointName: model.get('checkpointName'), checkpointName: model.get('checkpointName'),
location: model.get('location') usageId: model.get('usageId')
} }
); );
......
...@@ -28,13 +28,13 @@ ...@@ -28,13 +28,13 @@
this.courseKey = obj.courseKey || null; this.courseKey = obj.courseKey || null;
this.checkpointName = obj.checkpointName || null; this.checkpointName = obj.checkpointName || null;
this.platformName = obj.platformName || null; this.platformName = obj.platformName || null;
this.location = obj.location || null; this.usageId = obj.usageId || null;
this.model = new edx.verify_student.ReverificationModel({ this.model = new edx.verify_student.ReverificationModel({
courseKey: this.courseKey, courseKey: this.courseKey,
checkpointName: this.checkpointName, checkpointName: this.checkpointName,
location: this.location usageId: this.usageId
}); });
this.listenTo( this.model, 'sync', _.bind( this.handleSubmitPhotoSuccess, this )); this.listenTo( this.model, 'sync', _.bind( this.handleSubmitPhotoSuccess, this ));
......
...@@ -46,7 +46,7 @@ checkpoint_name=checkpoint_name)} ...@@ -46,7 +46,7 @@ checkpoint_name=checkpoint_name)}
data-course-key='${course_key}' data-course-key='${course_key}'
data-checkpoint-name='${checkpoint_name}' data-checkpoint-name='${checkpoint_name}'
data-platform-name='${platform_name}' data-platform-name='${platform_name}'
data-location='${location}' data-usage-id='${usage_id}'
></div> ></div>
</section> </section>
</div> </div>
......
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