Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Waqas/lms2516 typo softwaresecure resultcallback #3512

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 165 additions & 0 deletions lms/djangoapps/verify_student/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
---> To Payment

"""
import json
import mock
import urllib
from mock import patch, Mock
import pytz
from datetime import timedelta, datetime

from django.test.client import Client
from django.test import TestCase
from django.test.utils import override_settings
from django.conf import settings
Expand All @@ -31,6 +34,13 @@
from verify_student.models import SoftwareSecurePhotoVerification
from reverification.tests.factories import MidcourseReverificationWindowFactory

FAKE_SETTINGS = {
"SOFTWARE_SECURE":
{
"API_ACCESS_KEY": "BBBBBBBBBBBBBBBBBBBB",
"API_SECRET_KEY": "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC",
}
}

def mock_render_to_response(*args, **kwargs):
return render_to_response(*args, **kwargs)
Expand Down Expand Up @@ -123,6 +133,161 @@ def test_reverify_post_success(self):
self.assertTrue(context['error'])


@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE)
@patch.dict(settings.VERIFY_STUDENT, FAKE_SETTINGS)
class TestPhotoVerificationResultsCallback(TestCase):
""" Tests for Photo Verification Result Callback """
def setUp(self):
self.course_id = 'Robot/999/Test_Course'
CourseFactory.create(org='Robot', number='999', display_name='Test Course')
self.user = UserFactory.create()
self.attempt = SoftwareSecurePhotoVerification(
status="submitted",
user=self.user
)
self.attempt.save()
self.receipt_id = self.attempt.receipt_id
self.client = Client()

def mocked_has_valid_signature(method, headers_dict, body_dict, access_key, secret_key):
return True

def test_invalid_json(self):
"""
test for invalid json being posted by software secure
"""
data = {"testing invalid"}
response = self.client.post(reverse('verify_student_results_callback'), data=data,
content_type='application/json', HTTP_AUTHORIZATION='test BBBBBBBBBBBBBBBBBBBB: testing', HTTP_DATE='testdate')
self.assertIn('Invalid JSON', response.content)
self.assertEqual(response.status_code, 400)

def test_invalid_dict(self):
"""
test for invalid dictionary being posted by software secure
"""
data = '"\\"test\\testing"'
response = self.client.post(reverse('verify_student_results_callback'), data=data,
content_type='application/json', HTTP_AUTHORIZATION='test BBBBBBBBBBBBBBBBBBBB:testing', HTTP_DATE='testdate')
self.assertIn('JSON should be dict', response.content)
self.assertEqual(response.status_code, 400)

@mock.patch('verify_student.ssencrypt.has_valid_signature', mock.Mock(side_effect=mocked_has_valid_signature))
def test_invalid_access_key(self):
"""
test for invalid access key
"""
data = {"EdX-ID": self.receipt_id,
"Result": "testing",
"Reason": "testing",
"MessageType": "testing"}
json_data = json.dumps(data)
response = self.client.post(reverse('verify_student_results_callback'), data=json_data,
content_type='application/json', HTTP_AUTHORIZATION='test testing:testing', HTTP_DATE='testdate')
self.assertIn('Access key invalid', response.content)
self.assertEqual(response.status_code, 400)

@mock.patch('verify_student.ssencrypt.has_valid_signature', mock.Mock(side_effect=mocked_has_valid_signature))
def test_wrong_edx_id(self):
"""
test for wrong id of Software secure verification attempt
"""
data = {"EdX-ID": "testing",
"Result": "testing",
"Reason": "testing",
"MessageType": "testing"}
json_data = json.dumps(data)
response = self.client.post(reverse('verify_student_results_callback'), data=json_data,
content_type='application/json', HTTP_AUTHORIZATION='test BBBBBBBBBBBBBBBBBBBB:testing', HTTP_DATE='testdate')
self.assertIn('edX ID testing not found', response.content)
self.assertEqual(response.status_code, 400)

@mock.patch('verify_student.ssencrypt.has_valid_signature', mock.Mock(side_effect=mocked_has_valid_signature))
def test_pass_result(self):
"""
test for verification passed
"""
data = {"EdX-ID": self.receipt_id,
"Result": "PASS",
"Reason": "Testing",
"MessageType": "you have been verified"}
json_data = json.dumps(data)
response = self.client.post(reverse('verify_student_results_callback'), data=json_data,
content_type='application/json', HTTP_AUTHORIZATION='test BBBBBBBBBBBBBBBBBBBB:testing', HTTP_DATE='testdate')
attempt = SoftwareSecurePhotoVerification.objects.get(receipt_id=self.receipt_id)
self.assertEqual(attempt.status, u'approved')
self.assertEquals(response.content, 'OK!')

@mock.patch('verify_student.ssencrypt.has_valid_signature', mock.Mock(side_effect=mocked_has_valid_signature))
def test_fail_result(self):
"""
test for verification failed
"""
data = {"EdX-ID": self.receipt_id,
"Result": 'FAIL',
"Reason": 'Invalid Photo',
"MessageType": 'Your photo doesn\'t meet standards'}
json_data = json.dumps(data)
response = self.client.post(reverse('verify_student_results_callback'), data=json_data,
content_type='application/json', HTTP_AUTHORIZATION='test BBBBBBBBBBBBBBBBBBBB:testing', HTTP_DATE='testdate')
attempt = SoftwareSecurePhotoVerification.objects.get(receipt_id=self.receipt_id)
self.assertEqual(attempt.status, u'denied')
self.assertEqual(attempt.error_code, u'Your photo doesn\'t meet standards')
self.assertEqual(attempt.error_msg, u'"Invalid Photo"')
self.assertEquals(response.content, 'OK!')

@mock.patch('verify_student.ssencrypt.has_valid_signature', mock.Mock(side_effect=mocked_has_valid_signature))
def test_system_fail_result(self):
"""
test for software secure result system failure
"""
data = {"EdX-ID": self.receipt_id,
"Result": 'SYSTEM FAIL',
"Reason": 'Memory overflow',
"MessageType": 'you must retry the verification'}
json_data = json.dumps(data)
response = self.client.post(reverse('verify_student_results_callback'), data=json_data,
content_type='application/json', HTTP_AUTHORIZATION='test BBBBBBBBBBBBBBBBBBBB:testing', HTTP_DATE='testdate')
attempt = SoftwareSecurePhotoVerification.objects.get(receipt_id=self.receipt_id)
self.assertEqual(attempt.status, u'must_retry')
self.assertEqual(attempt.error_code, u'you must retry the verification')
self.assertEqual(attempt.error_msg, u'"Memory overflow"')
self.assertEquals(response.content, 'OK!')

@mock.patch('verify_student.ssencrypt.has_valid_signature', mock.Mock(side_effect=mocked_has_valid_signature))
def test_unknown_result(self):
"""
test for unknown software secure result
"""
data = {"EdX-ID": self.receipt_id,
"Result": 'unknown',
"Reason": 'unknown reason',
"MessageType": 'unknown message'}
json_data = json.dumps(data)
response = self.client.post(reverse('verify_student_results_callback'), data=json_data,
content_type='application/json', HTTP_AUTHORIZATION='test BBBBBBBBBBBBBBBBBBBB:testing', HTTP_DATE='testdate')
self.assertIn('Result unknown not understood', response.content)

@mock.patch('verify_student.ssencrypt.has_valid_signature', mock.Mock(side_effect=mocked_has_valid_signature))
def test_reverification(self):
"""
Test software secure result for reverification window
"""
data = {"EdX-ID": self.receipt_id,
"Result": "PASS",
"Reason": "Testing",
"MessageType": "you have been verified"}
window = MidcourseReverificationWindowFactory(course_id=self.course_id)
self.attempt.window = window
self.attempt.save()
json_data = json.dumps(data)
self.assertEqual(CourseEnrollment.objects.filter(course_id=self.course_id).count(), 0)
response = self.client.post(reverse('verify_student_results_callback'), data=json_data,
content_type='application/json', HTTP_AUTHORIZATION='test BBBBBBBBBBBBBBBBBBBB:testing', HTTP_DATE='testdate')
self.assertEquals(response.content, 'OK!')
self.assertIsNotNone(CourseEnrollment.objects.get(course_id=self.course_id))


@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE)
class TestMidCourseReverifyView(TestCase):
""" Tests for the midcourse reverification views """
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/verify_student/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def results_callback(request):

# If this is a reverification, log an event
if attempt.window:
course_id = window.course_id
course_id = attempt.window.course_id
course = course_from_id(course_id)
course_enrollment = CourseEnrollment.get_or_create_enrollment(attempt.user, course_id)
course_enrollment.emit_event(EVENT_NAME_USER_REVERIFICATION_REVIEWED_BY_SOFTWARESECURE)
Expand Down
2 changes: 1 addition & 1 deletion lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@

# Enable instructor dash beta version link
'ENABLE_INSTRUCTOR_BETA_DASHBOARD': True,

'VERIFIED_CERTIFICATES' : True,
# Allow use of the hint managment instructor view.
'ENABLE_HINTER_INSTRUCTOR_VIEW': False,

Expand Down
11 changes: 10 additions & 1 deletion lms/static/sass/base/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,15 @@ $verified-color-lvl3: $m-green-l2;
$verified-color-lvl4: $m-green-l3;
$verified-color-lvl5: $m-green-l4;

// STATE: honor code
$honorcode-color-lvl1: rgb(50, 165, 217);
$honorcode-color-lvl2: tint($honorcode-color-lvl1, 33%);

// STATE: audit
$audit-color-lvl1: $light-gray;
$audit-color-lvl2: tint($audit-color-lvl1, 33%);


// ====================

// ACTIONS: general
Expand Down Expand Up @@ -248,6 +257,7 @@ $dashboard-profile-header-image: linear-gradient(-90deg, rgb(255,255,255), rgb(2
$dashboard-profile-header-color: transparent;
$dashboard-profile-color: rgb(252,252,252);
$dot-color: $light-gray;
$dashboard-course-cover-border: $light-gray;

// MISC: course assets
$content-wrapper-bg: $white;
Expand Down Expand Up @@ -321,4 +331,3 @@ $f-monospace: 'Bitstream Vera Sans Mono', Consolas, Courier, monospace;
// SPLINT: colors

$msg-bg: $action-primary-bg;

2 changes: 1 addition & 1 deletion lms/static/sass/elements/_typography.scss
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@
}

%copy-badge {
@extend %t-title8;
@extend %t-title9;
@extend %t-weight3;
border-radius: ($baseline/5);
padding: ($baseline/2) $baseline;
Expand Down
85 changes: 67 additions & 18 deletions lms/static/sass/multicourse/_dashboard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,19 @@

.cover {
@include box-sizing(border-box);
@include transition(all 0.15s linear 0s);
overflow: hidden;
position: relative;
float: left;
height: 100%;
max-height: 100%;
margin: 0px;
overflow: hidden;
position: relative;
@include transition(all 0.15s linear 0s);
width: 200px;
height: 120px;
margin: 0px;
border-radius: ($baseline/10);
border: 1px solid $dashboard-course-cover-border;
border-bottom: 4px solid $dashboard-course-cover-border;
padding: ($baseline/10);

img {
width: 100%;
Expand Down Expand Up @@ -474,28 +478,43 @@
}
}

// "enrolled as" status
.sts-enrollment {
position: absolute;
top: 105px;
left: 0;
display: inline-block;
text-align: center;
width: 200px;

.label {
@extend %text-sr;
}

.sts-enrollment-value {
@extend %ui-depth1;
@extend %copy-badge;
border-radius: 0;
padding: ($baseline/4) ($baseline/2) ($baseline/4) ($baseline/2);
}
}

// ====================

// STATE: course mode - verified
// CASE: "enrolled as" status - verified
&.verified {
@extend %ui-depth2;
position: relative;

// changes to cover
.cover {
border-radius: ($baseline/10);
border: 1px solid $verified-color-lvl3;
border-bottom: 4px solid $verified-color-lvl3;
border-color: $verified-color-lvl3;
padding: ($baseline/10);
}

// course enrollment status message
.sts-enrollment {
display: inline-block;
position: absolute;
top: 105px;
left: 55px;
bottom: ($baseline/2);
text-align: center;
width: auto;

.label {
@extend %text-sr;
Expand All @@ -509,16 +528,46 @@
top: -10px;
}

// status message
.sts-enrollment-value {
@extend %ui-depth1;
@extend %copy-badge;
border-radius: 0;
padding: ($baseline/4) ($baseline/2) ($baseline/4) $baseline;
background: $verified-color-lvl3;
color: $white;
color: tint($verified-color-lvl1, 85%);
}
}
}

// CASE: "enrolled as" status - honor code
&.honor {

// changes to cover
.cover {
border-color: $honorcode-color-lvl2;
padding: ($baseline/10);
}

// status message
.sts-enrollment-value {
background: $honorcode-color-lvl1;
color: tint($honorcode-color-lvl1, 85%);
}
}

// CASE: "enrolled as" status - auditing
&.audit {

// changes to cover
.cover {
border-color: $audit-color-lvl2;
padding: ($baseline/10);
}

// status message
.sts-enrollment-value {
background: $audit-color-lvl1;
color: shade($audit-color-lvl1, 33%);
}
}
}

// ====================
Expand Down
Loading