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
0d7f34b5
Commit
0d7f34b5
authored
Apr 29, 2014
by
Waqas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update the software secure result call back by correcting the typo
LMS-2516
parent
b914ddf7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
223 additions
and
1 deletions
+223
-1
lms/djangoapps/verify_student/tests/test_views.py
+216
-0
lms/djangoapps/verify_student/views.py
+1
-1
lms/envs/test.py
+6
-0
No files found.
lms/djangoapps/verify_student/tests/test_views.py
View file @
0d7f34b5
...
@@ -10,11 +10,14 @@ verify_student/start?course_id=MITx/6.002x/2013_Spring # create
...
@@ -10,11 +10,14 @@ verify_student/start?course_id=MITx/6.002x/2013_Spring # create
---> To Payment
---> To Payment
"""
"""
import
json
import
mock
import
urllib
import
urllib
from
mock
import
patch
,
Mock
from
mock
import
patch
,
Mock
import
pytz
import
pytz
from
datetime
import
timedelta
,
datetime
from
datetime
import
timedelta
,
datetime
from
django.test.client
import
Client
from
django.test
import
TestCase
from
django.test
import
TestCase
from
django.test.utils
import
override_settings
from
django.test.utils
import
override_settings
from
django.conf
import
settings
from
django.conf
import
settings
...
@@ -31,6 +34,7 @@ from verify_student.models import SoftwareSecurePhotoVerification
...
@@ -31,6 +34,7 @@ from verify_student.models import SoftwareSecurePhotoVerification
from
reverification.tests.factories
import
MidcourseReverificationWindowFactory
from
reverification.tests.factories
import
MidcourseReverificationWindowFactory
def
mock_render_to_response
(
*
args
,
**
kwargs
):
def
mock_render_to_response
(
*
args
,
**
kwargs
):
return
render_to_response
(
*
args
,
**
kwargs
)
return
render_to_response
(
*
args
,
**
kwargs
)
...
@@ -123,6 +127,218 @@ class TestReverifyView(TestCase):
...
@@ -123,6 +127,218 @@ class TestReverifyView(TestCase):
@override_settings
(
MODULESTORE
=
TEST_DATA_MONGO_MODULESTORE
)
@override_settings
(
MODULESTORE
=
TEST_DATA_MONGO_MODULESTORE
)
class
TestPhotoVerificationResultsCallback
(
TestCase
):
"""
Tests for the results_callback view.
"""
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
\\
tTesting"'
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"
:
"Invalid-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 BBBBBBBBBBBBBBBBBBBB:testing'
,
HTTP_DATE
=
'testdate'
)
self
.
assertIn
(
'edX ID Invalid-Id 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"
:
""
,
"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 failed verification.
"""
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"
:
""
,
"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
):
class
TestMidCourseReverifyView
(
TestCase
):
""" Tests for the midcourse reverification views """
""" Tests for the midcourse reverification views """
def
setUp
(
self
):
def
setUp
(
self
):
...
...
lms/djangoapps/verify_student/views.py
View file @
0d7f34b5
...
@@ -256,7 +256,7 @@ def results_callback(request):
...
@@ -256,7 +256,7 @@ def results_callback(request):
# If this is a reverification, log an event
# If this is a reverification, log an event
if
attempt
.
window
:
if
attempt
.
window
:
course_id
=
window
.
course_id
course_id
=
attempt
.
window
.
course_id
course
=
course_from_id
(
course_id
)
course
=
course_from_id
(
course_id
)
course_enrollment
=
CourseEnrollment
.
get_or_create_enrollment
(
attempt
.
user
,
course_id
)
course_enrollment
=
CourseEnrollment
.
get_or_create_enrollment
(
attempt
.
user
,
course_id
)
course_enrollment
.
emit_event
(
EVENT_NAME_USER_REVERIFICATION_REVIEWED_BY_SOFTWARESECURE
)
course_enrollment
.
emit_event
(
EVENT_NAME_USER_REVERIFICATION_REVIEWED_BY_SOFTWARESECURE
)
...
...
lms/envs/test.py
View file @
0d7f34b5
...
@@ -315,3 +315,9 @@ FEATURES['USE_MICROSITES'] = True
...
@@ -315,3 +315,9 @@ FEATURES['USE_MICROSITES'] = True
######### LinkedIn ########
######### LinkedIn ########
LINKEDIN_API
[
'COMPANY_ID'
]
=
'0000000'
LINKEDIN_API
[
'COMPANY_ID'
]
=
'0000000'
# Setting for the testing of Software Secure Result Callback
VERIFY_STUDENT
[
"SOFTWARE_SECURE"
]
=
{
"API_ACCESS_KEY"
:
"BBBBBBBBBBBBBBBBBBBB"
,
"API_SECRET_KEY"
:
"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
,
}
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