From 58b7e7fb3321129ee8bc7a075068553a1db0a0b8 Mon Sep 17 00:00:00 2001 From: Awais Date: Thu, 7 May 2015 00:34:00 +0500 Subject: [PATCH] ECOM-1531 adding the fake-page for softwar secure. --- .../tests/fake_software_secure.py | 48 ++++++++++++ .../tests/test_fake_software_secure.py | 76 +++++++++++++++++++ lms/djangoapps/verify_student/urls.py | 8 ++ lms/envs/common.py | 3 + lms/envs/devstack.py | 9 +++ .../test/fake_softwaresecure_response.html | 75 ++++++++++++++++++ 6 files changed, 219 insertions(+) create mode 100644 lms/djangoapps/verify_student/tests/fake_software_secure.py create mode 100644 lms/djangoapps/verify_student/tests/test_fake_software_secure.py create mode 100644 lms/templates/verify_student/test/fake_softwaresecure_response.html diff --git a/lms/djangoapps/verify_student/tests/fake_software_secure.py b/lms/djangoapps/verify_student/tests/fake_software_secure.py new file mode 100644 index 0000000000..5931287977 --- /dev/null +++ b/lms/djangoapps/verify_student/tests/fake_software_secure.py @@ -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 diff --git a/lms/djangoapps/verify_student/tests/test_fake_software_secure.py b/lms/djangoapps/verify_student/tests/test_fake_software_secure.py new file mode 100644 index 0000000000..3855ec31c6 --- /dev/null +++ b/lms/djangoapps/verify_student/tests/test_fake_software_secure.py @@ -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) diff --git a/lms/djangoapps/verify_student/urls.py b/lms/djangoapps/verify_student/urls.py index 701bd71ff5..c349de245b 100644 --- a/lms/djangoapps/verify_student/urls.py +++ b/lms/djangoapps/verify_student/urls.py @@ -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()), + ) diff --git a/lms/envs/common.py b/lms/envs/common.py index bb06799531..b536f82a16 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -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 diff --git a/lms/envs/devstack.py b/lms/envs/devstack.py index 4d799e49d1..577ab95b3b 100644 --- a/lms/envs/devstack.py +++ b/lms/envs/devstack.py @@ -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", +} diff --git a/lms/templates/verify_student/test/fake_softwaresecure_response.html b/lms/templates/verify_student/test/fake_softwaresecure_response.html new file mode 100644 index 0000000000..14a94e7622 --- /dev/null +++ b/lms/templates/verify_student/test/fake_softwaresecure_response.html @@ -0,0 +1,75 @@ +<%namespace name='static' file='/static_content.html'/> + +Fake Software Secure Form + + +

Fake Software Secure page

+

It will pick the most recent software secure attempt for a logged-in user.

+ +
+
+ + + + +
+ +
+
+ + + + +