Merge pull request #7951 from edx/awais786/ECOM-1531-fake-page-ssecure
ECOM-1531 adding the fake-page for softwar secure.
This commit is contained in:
48
lms/djangoapps/verify_student/tests/fake_software_secure.py
Normal file
48
lms/djangoapps/verify_student/tests/fake_software_secure.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""
|
||||
Fake Software Secure page for use in acceptance tests.
|
||||
"""
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views.generic.base import View
|
||||
|
||||
from edxmako.shortcuts import render_to_response
|
||||
from verify_student.models import SoftwareSecurePhotoVerification
|
||||
|
||||
|
||||
class SoftwareSecureFakeView(View):
|
||||
"""
|
||||
Fake SoftwareSecure view for testing different photo verification statuses
|
||||
and email functionality.
|
||||
"""
|
||||
|
||||
@method_decorator(login_required)
|
||||
def get(self, request):
|
||||
"""
|
||||
Render a fake Software Secure page that will pick the most recent
|
||||
attempt for a given user and pass it to the html page.
|
||||
"""
|
||||
context_dict = self.response_post_params(request.user)
|
||||
return render_to_response("verify_student/test/fake_softwaresecure_response.html", context_dict)
|
||||
|
||||
@classmethod
|
||||
def response_post_params(cls, user):
|
||||
"""
|
||||
Calculate the POST params we want to send back to the client.
|
||||
"""
|
||||
access_key = settings.VERIFY_STUDENT["SOFTWARE_SECURE"]["API_ACCESS_KEY"]
|
||||
context = {
|
||||
'receipt_id': None,
|
||||
'authorization_code': 'SIS {}:0000'.format(access_key),
|
||||
'results_callback': reverse('verify_student_results_callback')
|
||||
}
|
||||
|
||||
try:
|
||||
most_recent = SoftwareSecurePhotoVerification.original_verification(user)
|
||||
context["receipt_id"] = most_recent.receipt_id
|
||||
except: # pylint: disable=bare-except
|
||||
pass
|
||||
|
||||
return context
|
||||
@@ -0,0 +1,76 @@
|
||||
"""
|
||||
Tests for the fake software secure response.
|
||||
"""
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from mock import patch
|
||||
from student.tests.factories import UserFactory
|
||||
from util.testing import UrlResetMixin
|
||||
from verify_student.models import SoftwareSecurePhotoVerification
|
||||
|
||||
|
||||
class SoftwareSecureFakeViewTest(UrlResetMixin, TestCase):
|
||||
"""
|
||||
Base class to test the fake software secure view.
|
||||
"""
|
||||
def setUp(self, **kwargs):
|
||||
enable_software_secure_fake = kwargs.get('enable_software_secure_fake', False)
|
||||
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_SOFTWARE_SECURE_FAKE': enable_software_secure_fake}):
|
||||
super(SoftwareSecureFakeViewTest, self).setUp('verify_student.urls')
|
||||
|
||||
self.user = UserFactory.create(username="test", password="test")
|
||||
self.attempt = SoftwareSecurePhotoVerification.objects.create(user=self.user)
|
||||
self.client.login(username="test", password="test")
|
||||
|
||||
|
||||
class SoftwareSecureFakeViewDisabledTest(SoftwareSecureFakeViewTest):
|
||||
"""
|
||||
Test the fake software secure response when feature flag
|
||||
'ENABLE_SOFTWARE_SECURE_FAKE' is not enabled.
|
||||
"""
|
||||
def setUp(self):
|
||||
super(SoftwareSecureFakeViewDisabledTest, self).setUp(enable_software_secure_fake=False)
|
||||
|
||||
def test_get_method_without_enable_feature_flag(self):
|
||||
"""
|
||||
Test that the user gets 404 response if the feature flag
|
||||
'ENABLE_SOFTWARE_SECURE_FAKE' is not enabled.
|
||||
"""
|
||||
response = self.client.get(
|
||||
'/verify_student/software-secure-fake-response'
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
|
||||
class SoftwareSecureFakeViewEnabledTest(SoftwareSecureFakeViewTest):
|
||||
"""
|
||||
Test the fake software secure response when feature flag
|
||||
'ENABLE_SOFTWARE_SECURE_FAKE' is enabled.
|
||||
"""
|
||||
def setUp(self):
|
||||
super(SoftwareSecureFakeViewEnabledTest, self).setUp(enable_software_secure_fake=True)
|
||||
|
||||
def test_get_method_without_logged_in_user(self):
|
||||
"""
|
||||
Test that the user gets 302 response if that user is not logged in.
|
||||
"""
|
||||
self.client.logout()
|
||||
response = self.client.get(
|
||||
'/verify_student/software-secure-fake-response'
|
||||
)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
def test_get_method(self):
|
||||
"""
|
||||
Test that GET method of fake software secure view uses the most recent
|
||||
attempt for the logged-in user.
|
||||
"""
|
||||
response = self.client.get(
|
||||
'/verify_student/software-secure-fake-response'
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn('EdX-ID', response.content)
|
||||
self.assertIn('results_callback', response.content)
|
||||
@@ -149,3 +149,11 @@ urlpatterns = patterns(
|
||||
name="verify_student_incourse_reverify"
|
||||
),
|
||||
)
|
||||
|
||||
# Fake response page for incourse reverification ( software secure )
|
||||
if settings.FEATURES.get('ENABLE_SOFTWARE_SECURE_FAKE'):
|
||||
from verify_student.tests.fake_software_secure import SoftwareSecureFakeView
|
||||
urlpatterns += patterns(
|
||||
'verify_student.tests.fake_software_secure',
|
||||
url(r'^software-secure-fake-response', SoftwareSecureFakeView.as_view()),
|
||||
)
|
||||
|
||||
@@ -383,6 +383,9 @@ FEATURES = {
|
||||
|
||||
# Course discovery feature
|
||||
'ENABLE_COURSE_DISCOVERY': False,
|
||||
|
||||
# Software secure fake page feature flag
|
||||
'ENABLE_SOFTWARE_SECURE_FAKE': False,
|
||||
}
|
||||
|
||||
# Ignore static asset files on import which match this pattern
|
||||
|
||||
@@ -146,3 +146,12 @@ SECRET_KEY = '85920908f28904ed733fe576320db18cabd7b6cd'
|
||||
FEATURES['ENABLE_COURSE_DISCOVERY'] = True
|
||||
FEATURES['COURSES_ARE_BROWSEABLE'] = True
|
||||
HOMEPAGE_COURSE_MAX = 9
|
||||
|
||||
# Software secure fake page feature flag
|
||||
FEATURES['ENABLE_SOFTWARE_SECURE_FAKE'] = True
|
||||
|
||||
# Setting for the testing of Software Secure Result Callback
|
||||
VERIFY_STUDENT["SOFTWARE_SECURE"] = {
|
||||
"API_ACCESS_KEY": "BBBBBBBBBBBBBBBBBBBB",
|
||||
"API_SECRET_KEY": "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC",
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
<%namespace name='static' file='/static_content.html'/>
|
||||
<html>
|
||||
<head><title>Fake Software Secure Form</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Fake Software Secure page</p>
|
||||
<p>It will pick the most recent software secure attempt for a logged-in user.</p>
|
||||
|
||||
<br>
|
||||
<div>
|
||||
<input type="button" value="PASS" id="btn_pass">
|
||||
<input type="button" value="FAIL" id="btn_denied" style="margin-left: 10px">
|
||||
<input type="button" value="SYSTEM FAIL" id="btn_error" style="margin-left: 10px">
|
||||
<input type="button" value="UNKNOWN ERROR" id="btn_unknown_error" style="margin-left: 10px">
|
||||
</div>
|
||||
|
||||
<div id="errors-info" style="padding-top: 20px;color: red"></div>
|
||||
<div id="success-info" style="padding-top: 20px;color: green"></div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
<script type="text/javascript" src="${static.url('js/vendor/jquery.min.js')}"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
$("#btn_pass").click(function(e){
|
||||
e.preventDefault();
|
||||
ajax_post($(this).val(),"");
|
||||
});
|
||||
$("#btn_denied").click(function(e){
|
||||
e.preventDefault();
|
||||
ajax_post($(this).val(),"failure");
|
||||
});
|
||||
$("#btn_error").click(function(e){
|
||||
e.preventDefault();
|
||||
ajax_post($(this).val(),"system error");
|
||||
});
|
||||
$("#btn_unknown_error").click(function(e){
|
||||
e.preventDefault();
|
||||
ajax_post($(this).val(),"unknown system error");
|
||||
});
|
||||
|
||||
|
||||
function ajax_post(status, reason){
|
||||
|
||||
var data = {
|
||||
"EdX-ID": '${receipt_id}',
|
||||
"Result": status,
|
||||
"Reason": reason,
|
||||
"MessageType": ""
|
||||
};
|
||||
|
||||
$('#errors-info').html('');
|
||||
$('#success-info').html('');
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: '${results_callback}',
|
||||
headers: {
|
||||
"Authorization": "${authorization_code}"
|
||||
},
|
||||
data: JSON.stringify(data),
|
||||
contentType: "application/json;",
|
||||
success: function () {
|
||||
$('#success-info').html('status updated.');
|
||||
},
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
$('#errors-info').html(jqXHR.responseText);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
Reference in New Issue
Block a user