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
303c229f
Commit
303c229f
authored
Aug 25, 2015
by
David Ormsbee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Partial use of SharedModuleStoreTestCase in verify student tests.
Done for performance.
parent
fdfaa565
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
77 additions
and
53 deletions
+77
-53
lms/djangoapps/verify_student/tests/test_views.py
+77
-53
No files found.
lms/djangoapps/verify_student/tests/test_views.py
View file @
303c229f
...
@@ -49,7 +49,7 @@ from verify_student.models import (
...
@@ -49,7 +49,7 @@ from verify_student.models import (
VerificationDeadline
,
SoftwareSecurePhotoVerification
,
VerificationDeadline
,
SoftwareSecurePhotoVerification
,
VerificationCheckpoint
,
VerificationStatus
VerificationCheckpoint
,
VerificationStatus
)
)
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
,
SharedModuleStoreTestCase
from
xmodule.modulestore.tests.factories
import
CourseFactory
,
ItemFactory
from
xmodule.modulestore.tests.factories
import
CourseFactory
,
ItemFactory
from
xmodule.modulestore.tests.utils
import
XssTestMixin
from
xmodule.modulestore.tests.utils
import
XssTestMixin
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.django
import
modulestore
...
@@ -82,7 +82,7 @@ class StartView(TestCase):
...
@@ -82,7 +82,7 @@ class StartView(TestCase):
@ddt.ddt
@ddt.ddt
class
TestPayAndVerifyView
(
UrlResetMixin
,
ModuleStoreTestCase
,
XssTestMixin
):
class
TestPayAndVerifyView
(
UrlResetMixin
,
Shared
ModuleStoreTestCase
,
XssTestMixin
):
"""
"""
Tests for the payment and verification flow views.
Tests for the payment and verification flow views.
"""
"""
...
@@ -94,6 +94,16 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -94,6 +94,16 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
YESTERDAY
=
NOW
-
timedelta
(
days
=
1
)
YESTERDAY
=
NOW
-
timedelta
(
days
=
1
)
TOMORROW
=
NOW
+
timedelta
(
days
=
1
)
TOMORROW
=
NOW
+
timedelta
(
days
=
1
)
@classmethod
@mock.patch.dict
(
settings
.
FEATURES
,
{
'EMBARGO'
:
True
})
def
setUpClass
(
cls
):
super
(
TestPayAndVerifyView
,
cls
)
.
setUpClass
()
cls
.
courses
=
{
course_mode
:
cls
.
_create_course
(
course_mode
)
for
course_mode
in
[
"honor"
,
"verified"
,
"professional"
,
"no-id-professional"
]
}
@mock.patch.dict
(
settings
.
FEATURES
,
{
'EMBARGO'
:
True
})
@mock.patch.dict
(
settings
.
FEATURES
,
{
'EMBARGO'
:
True
})
def
setUp
(
self
):
def
setUp
(
self
):
super
(
TestPayAndVerifyView
,
self
)
.
setUp
(
'embargo'
)
super
(
TestPayAndVerifyView
,
self
)
.
setUp
(
'embargo'
)
...
@@ -103,7 +113,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -103,7 +113,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
@ddt.data
(
"verified"
,
"professional"
)
@ddt.data
(
"verified"
,
"professional"
)
def
test_start_flow_not_verified
(
self
,
course_mode
):
def
test_start_flow_not_verified
(
self
,
course_mode
):
course
=
self
.
_create_course
(
course_mode
)
course
=
self
.
courses
[
course_mode
]
self
.
_enroll
(
course
.
id
,
"honor"
)
self
.
_enroll
(
course
.
id
,
"honor"
)
response
=
self
.
_get_page
(
'verify_student_start_flow'
,
course
.
id
)
response
=
self
.
_get_page
(
'verify_student_start_flow'
,
course
.
id
)
self
.
_assert_displayed_mode
(
response
,
course_mode
)
self
.
_assert_displayed_mode
(
response
,
course_mode
)
...
@@ -121,7 +131,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -121,7 +131,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
@ddt.data
(
"no-id-professional"
)
@ddt.data
(
"no-id-professional"
)
def
test_start_flow_with_no_id_professional
(
self
,
course_mode
):
def
test_start_flow_with_no_id_professional
(
self
,
course_mode
):
course
=
self
.
_create_course
(
course_mode
)
course
=
self
.
courses
[
course_mode
]
# by default enrollment is honor
# by default enrollment is honor
self
.
_enroll
(
course
.
id
,
"honor"
)
self
.
_enroll
(
course
.
id
,
"honor"
)
response
=
self
.
_get_page
(
'verify_student_start_flow'
,
course
.
id
)
response
=
self
.
_get_page
(
'verify_student_start_flow'
,
course
.
id
)
...
@@ -136,7 +146,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -136,7 +146,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
@ddt.data
(
"expired"
,
"denied"
)
@ddt.data
(
"expired"
,
"denied"
)
def
test_start_flow_expired_or_denied_verification
(
self
,
verification_status
):
def
test_start_flow_expired_or_denied_verification
(
self
,
verification_status
):
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
self
.
_enroll
(
course
.
id
,
"verified"
)
self
.
_enroll
(
course
.
id
,
"verified"
)
self
.
_set_verification_status
(
verification_status
)
self
.
_set_verification_status
(
verification_status
)
response
=
self
.
_get_page
(
'verify_student_start_flow'
,
course
.
id
)
response
=
self
.
_get_page
(
'verify_student_start_flow'
,
course
.
id
)
...
@@ -162,7 +172,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -162,7 +172,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
)
)
@ddt.unpack
@ddt.unpack
def
test_start_flow_already_verified
(
self
,
course_mode
,
verification_status
):
def
test_start_flow_already_verified
(
self
,
course_mode
,
verification_status
):
course
=
self
.
_create_course
(
course_mode
)
course
=
self
.
courses
[
course_mode
]
self
.
_enroll
(
course
.
id
,
"honor"
)
self
.
_enroll
(
course
.
id
,
"honor"
)
self
.
_set_verification_status
(
verification_status
)
self
.
_set_verification_status
(
verification_status
)
response
=
self
.
_get_page
(
'verify_student_start_flow'
,
course
.
id
)
response
=
self
.
_get_page
(
'verify_student_start_flow'
,
course
.
id
)
...
@@ -177,7 +187,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -177,7 +187,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
@ddt.data
(
"verified"
,
"professional"
)
@ddt.data
(
"verified"
,
"professional"
)
def
test_start_flow_already_paid
(
self
,
course_mode
):
def
test_start_flow_already_paid
(
self
,
course_mode
):
course
=
self
.
_create_course
(
course_mode
)
course
=
self
.
courses
[
course_mode
]
self
.
_enroll
(
course
.
id
,
course_mode
)
self
.
_enroll
(
course
.
id
,
course_mode
)
response
=
self
.
_get_page
(
'verify_student_start_flow'
,
course
.
id
)
response
=
self
.
_get_page
(
'verify_student_start_flow'
,
course
.
id
)
self
.
_assert_displayed_mode
(
response
,
course_mode
)
self
.
_assert_displayed_mode
(
response
,
course_mode
)
...
@@ -193,7 +203,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -193,7 +203,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
])
])
def
test_start_flow_not_enrolled
(
self
):
def
test_start_flow_not_enrolled
(
self
):
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
self
.
_set_verification_status
(
"submitted"
)
self
.
_set_verification_status
(
"submitted"
)
response
=
self
.
_get_page
(
'verify_student_start_flow'
,
course
.
id
)
response
=
self
.
_get_page
(
'verify_student_start_flow'
,
course
.
id
)
...
@@ -209,7 +219,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -209,7 +219,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
self
.
_assert_requirements_displayed
(
response
,
[])
self
.
_assert_requirements_displayed
(
response
,
[])
def
test_start_flow_unenrolled
(
self
):
def
test_start_flow_unenrolled
(
self
):
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
self
.
_set_verification_status
(
"submitted"
)
self
.
_set_verification_status
(
"submitted"
)
self
.
_enroll
(
course
.
id
,
"verified"
)
self
.
_enroll
(
course
.
id
,
"verified"
)
self
.
_unenroll
(
course
.
id
)
self
.
_unenroll
(
course
.
id
)
...
@@ -231,7 +241,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -231,7 +241,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
)
)
@ddt.unpack
@ddt.unpack
def
test_start_flow_already_verified_and_paid
(
self
,
course_mode
,
verification_status
):
def
test_start_flow_already_verified_and_paid
(
self
,
course_mode
,
verification_status
):
course
=
self
.
_create_course
(
course_mode
)
course
=
self
.
courses
[
course_mode
]
self
.
_enroll
(
course
.
id
,
course_mode
)
self
.
_enroll
(
course
.
id
,
course_mode
)
self
.
_set_verification_status
(
verification_status
)
self
.
_set_verification_status
(
verification_status
)
response
=
self
.
_get_page
(
response
=
self
.
_get_page
(
...
@@ -243,7 +253,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -243,7 +253,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
@patch.dict
(
settings
.
FEATURES
,
{
"IS_EDX_DOMAIN"
:
True
})
@patch.dict
(
settings
.
FEATURES
,
{
"IS_EDX_DOMAIN"
:
True
})
def
test_pay_and_verify_hides_header_nav
(
self
):
def
test_pay_and_verify_hides_header_nav
(
self
):
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
self
.
_enroll
(
course
.
id
,
"verified"
)
self
.
_enroll
(
course
.
id
,
"verified"
)
response
=
self
.
_get_page
(
'verify_student_start_flow'
,
course
.
id
)
response
=
self
.
_get_page
(
'verify_student_start_flow'
,
course
.
id
)
...
@@ -254,7 +264,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -254,7 +264,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
def
test_verify_now
(
self
):
def
test_verify_now
(
self
):
# We've already paid, and now we're trying to verify
# We've already paid, and now we're trying to verify
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
self
.
_enroll
(
course
.
id
,
"verified"
)
self
.
_enroll
(
course
.
id
,
"verified"
)
response
=
self
.
_get_page
(
'verify_student_verify_now'
,
course
.
id
)
response
=
self
.
_get_page
(
'verify_student_verify_now'
,
course
.
id
)
...
@@ -277,7 +287,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -277,7 +287,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
])
])
def
test_verify_now_already_verified
(
self
):
def
test_verify_now_already_verified
(
self
):
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
self
.
_enroll
(
course
.
id
,
"verified"
)
self
.
_enroll
(
course
.
id
,
"verified"
)
self
.
_set_verification_status
(
"submitted"
)
self
.
_set_verification_status
(
"submitted"
)
...
@@ -291,7 +301,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -291,7 +301,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
self
.
_assert_redirects_to_dashboard
(
response
)
self
.
_assert_redirects_to_dashboard
(
response
)
def
test_verify_now_user_details
(
self
):
def
test_verify_now_user_details
(
self
):
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
self
.
_enroll
(
course
.
id
,
"verified"
)
self
.
_enroll
(
course
.
id
,
"verified"
)
response
=
self
.
_get_page
(
'verify_student_verify_now'
,
course
.
id
)
response
=
self
.
_get_page
(
'verify_student_verify_now'
,
course
.
id
)
self
.
_assert_user_details
(
response
,
self
.
user
.
profile
.
name
)
self
.
_assert_user_details
(
response
,
self
.
user
.
profile
.
name
)
...
@@ -301,7 +311,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -301,7 +311,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
"verify_student_payment_confirmation"
"verify_student_payment_confirmation"
)
)
def
test_verify_now_not_enrolled
(
self
,
page_name
):
def
test_verify_now_not_enrolled
(
self
,
page_name
):
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
response
=
self
.
_get_page
(
page_name
,
course
.
id
,
expected_status_code
=
302
)
response
=
self
.
_get_page
(
page_name
,
course
.
id
,
expected_status_code
=
302
)
self
.
_assert_redirects_to_start_flow
(
response
,
course
.
id
)
self
.
_assert_redirects_to_start_flow
(
response
,
course
.
id
)
...
@@ -310,7 +320,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -310,7 +320,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
"verify_student_payment_confirmation"
"verify_student_payment_confirmation"
)
)
def
test_verify_now_unenrolled
(
self
,
page_name
):
def
test_verify_now_unenrolled
(
self
,
page_name
):
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
self
.
_enroll
(
course
.
id
,
"verified"
)
self
.
_enroll
(
course
.
id
,
"verified"
)
self
.
_unenroll
(
course
.
id
)
self
.
_unenroll
(
course
.
id
)
response
=
self
.
_get_page
(
page_name
,
course
.
id
,
expected_status_code
=
302
)
response
=
self
.
_get_page
(
page_name
,
course
.
id
,
expected_status_code
=
302
)
...
@@ -321,21 +331,21 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -321,21 +331,21 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
"verify_student_payment_confirmation"
"verify_student_payment_confirmation"
)
)
def
test_verify_now_not_paid
(
self
,
page_name
):
def
test_verify_now_not_paid
(
self
,
page_name
):
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
self
.
_enroll
(
course
.
id
,
"honor"
)
self
.
_enroll
(
course
.
id
,
"honor"
)
response
=
self
.
_get_page
(
page_name
,
course
.
id
,
expected_status_code
=
302
)
response
=
self
.
_get_page
(
page_name
,
course
.
id
,
expected_status_code
=
302
)
self
.
_assert_redirects_to_upgrade
(
response
,
course
.
id
)
self
.
_assert_redirects_to_upgrade
(
response
,
course
.
id
)
def
test_verify_later
(
self
):
def
test_verify_later
(
self
):
""" The deprecated verify-later page should redirect to the verification start page. """
""" The deprecated verify-later page should redirect to the verification start page. """
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
course_key
=
course
.
id
course_key
=
course
.
id
self
.
_enroll
(
course_key
,
"verified"
)
self
.
_enroll
(
course_key
,
"verified"
)
response
=
self
.
_get_page
(
"verify_student_verify_later"
,
course_key
,
expected_status_code
=
301
)
response
=
self
.
_get_page
(
"verify_student_verify_later"
,
course_key
,
expected_status_code
=
301
)
self
.
_assert_redirects_to_verify_start
(
response
,
course_key
,
301
)
self
.
_assert_redirects_to_verify_start
(
response
,
course_key
,
301
)
def
test_payment_confirmation
(
self
):
def
test_payment_confirmation
(
self
):
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
self
.
_enroll
(
course
.
id
,
"verified"
)
self
.
_enroll
(
course
.
id
,
"verified"
)
response
=
self
.
_get_page
(
'verify_student_payment_confirmation'
,
course
.
id
)
response
=
self
.
_get_page
(
'verify_student_payment_confirmation'
,
course
.
id
)
...
@@ -366,7 +376,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -366,7 +376,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
skip it. Despite setting the parameter, the current step should still be
skip it. Despite setting the parameter, the current step should still be
MAKE_PAYMENT_STEP.
MAKE_PAYMENT_STEP.
"""
"""
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
response
=
self
.
_get_page
(
response
=
self
.
_get_page
(
'verify_student_start_flow'
,
'verify_student_start_flow'
,
course
.
id
,
course
.
id
,
...
@@ -386,7 +396,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -386,7 +396,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
)
)
def
test_payment_confirmation_already_verified
(
self
):
def
test_payment_confirmation_already_verified
(
self
):
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
self
.
_enroll
(
course
.
id
,
"verified"
)
self
.
_enroll
(
course
.
id
,
"verified"
)
self
.
_set_verification_status
(
"submitted"
)
self
.
_set_verification_status
(
"submitted"
)
...
@@ -404,7 +414,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -404,7 +414,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
)
)
def
test_payment_confirmation_already_verified_skip_first_step
(
self
):
def
test_payment_confirmation_already_verified_skip_first_step
(
self
):
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
self
.
_enroll
(
course
.
id
,
"verified"
)
self
.
_enroll
(
course
.
id
,
"verified"
)
self
.
_set_verification_status
(
"submitted"
)
self
.
_set_verification_status
(
"submitted"
)
...
@@ -446,7 +456,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -446,7 +456,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
@ddt.data
(
"verified"
,
"professional"
)
@ddt.data
(
"verified"
,
"professional"
)
def
test_upgrade
(
self
,
course_mode
):
def
test_upgrade
(
self
,
course_mode
):
course
=
self
.
_create_course
(
course_mode
)
course
=
self
.
courses
[
course_mode
]
self
.
_enroll
(
course
.
id
,
"honor"
)
self
.
_enroll
(
course
.
id
,
"honor"
)
response
=
self
.
_get_page
(
'verify_student_upgrade_and_verify'
,
course
.
id
)
response
=
self
.
_get_page
(
'verify_student_upgrade_and_verify'
,
course
.
id
)
...
@@ -465,7 +475,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -465,7 +475,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
self
.
assert_xss
(
response
,
'<script>alert("XSS")</script>'
)
self
.
assert_xss
(
response
,
'<script>alert("XSS")</script>'
)
def
test_upgrade_already_verified
(
self
):
def
test_upgrade_already_verified
(
self
):
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
self
.
_enroll
(
course
.
id
,
"honor"
)
self
.
_enroll
(
course
.
id
,
"honor"
)
self
.
_set_verification_status
(
"submitted"
)
self
.
_set_verification_status
(
"submitted"
)
...
@@ -479,7 +489,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -479,7 +489,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
self
.
_assert_requirements_displayed
(
response
,
[])
self
.
_assert_requirements_displayed
(
response
,
[])
def
test_upgrade_already_paid
(
self
):
def
test_upgrade_already_paid
(
self
):
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
self
.
_enroll
(
course
.
id
,
"verified"
)
self
.
_enroll
(
course
.
id
,
"verified"
)
# If we've already paid, then the upgrade messaging
# If we've already paid, then the upgrade messaging
...
@@ -493,7 +503,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -493,7 +503,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
self
.
_assert_redirects_to_verify_start
(
response
,
course
.
id
)
self
.
_assert_redirects_to_verify_start
(
response
,
course
.
id
)
def
test_upgrade_already_verified_and_paid
(
self
):
def
test_upgrade_already_verified_and_paid
(
self
):
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
self
.
_enroll
(
course
.
id
,
"verified"
)
self
.
_enroll
(
course
.
id
,
"verified"
)
self
.
_set_verification_status
(
"submitted"
)
self
.
_set_verification_status
(
"submitted"
)
...
@@ -506,7 +516,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -506,7 +516,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
self
.
_assert_redirects_to_dashboard
(
response
)
self
.
_assert_redirects_to_dashboard
(
response
)
def
test_upgrade_not_enrolled
(
self
):
def
test_upgrade_not_enrolled
(
self
):
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
response
=
self
.
_get_page
(
response
=
self
.
_get_page
(
'verify_student_upgrade_and_verify'
,
'verify_student_upgrade_and_verify'
,
course
.
id
,
course
.
id
,
...
@@ -515,7 +525,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -515,7 +525,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
self
.
_assert_redirects_to_start_flow
(
response
,
course
.
id
)
self
.
_assert_redirects_to_start_flow
(
response
,
course
.
id
)
def
test_upgrade_unenrolled
(
self
):
def
test_upgrade_unenrolled
(
self
):
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
self
.
_enroll
(
course
.
id
,
"verified"
)
self
.
_enroll
(
course
.
id
,
"verified"
)
self
.
_unenroll
(
course
.
id
)
self
.
_unenroll
(
course
.
id
)
response
=
self
.
_get_page
(
response
=
self
.
_get_page
(
...
@@ -557,7 +567,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -557,7 +567,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
)
)
def
test_require_login
(
self
,
url_name
):
def
test_require_login
(
self
,
url_name
):
self
.
client
.
logout
()
self
.
client
.
logout
()
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
response
=
self
.
_get_page
(
url_name
,
course
.
id
,
expected_status_code
=
302
)
response
=
self
.
_get_page
(
url_name
,
course
.
id
,
expected_status_code
=
302
)
original_url
=
reverse
(
url_name
,
kwargs
=
{
'course_id'
:
unicode
(
course
.
id
)})
original_url
=
reverse
(
url_name
,
kwargs
=
{
'course_id'
:
unicode
(
course
.
id
)})
...
@@ -583,7 +593,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -583,7 +593,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
def
test_account_not_active
(
self
):
def
test_account_not_active
(
self
):
self
.
user
.
is_active
=
False
self
.
user
.
is_active
=
False
self
.
user
.
save
()
self
.
user
.
save
()
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
response
=
self
.
_get_page
(
'verify_student_start_flow'
,
course
.
id
)
response
=
self
.
_get_page
(
'verify_student_start_flow'
,
course
.
id
)
self
.
_assert_steps_displayed
(
self
.
_assert_steps_displayed
(
response
,
response
,
...
@@ -598,13 +608,13 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -598,13 +608,13 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
def
test_no_contribution
(
self
):
def
test_no_contribution
(
self
):
# Do NOT specify a contribution for the course in a session var.
# Do NOT specify a contribution for the course in a session var.
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
response
=
self
.
_get_page
(
"verify_student_start_flow"
,
course
.
id
)
response
=
self
.
_get_page
(
"verify_student_start_flow"
,
course
.
id
)
self
.
_assert_contribution_amount
(
response
,
""
)
self
.
_assert_contribution_amount
(
response
,
""
)
def
test_contribution_other_course
(
self
):
def
test_contribution_other_course
(
self
):
# Specify a contribution amount for another course in the session
# Specify a contribution amount for another course in the session
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
other_course_id
=
CourseLocator
(
org
=
"other"
,
run
=
"test"
,
course
=
"test"
)
other_course_id
=
CourseLocator
(
org
=
"other"
,
run
=
"test"
,
course
=
"test"
)
self
.
_set_contribution
(
"12.34"
,
other_course_id
)
self
.
_set_contribution
(
"12.34"
,
other_course_id
)
...
@@ -614,7 +624,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -614,7 +624,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
def
test_contribution
(
self
):
def
test_contribution
(
self
):
# Specify a contribution amount for this course in the session
# Specify a contribution amount for this course in the session
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
self
.
_set_contribution
(
"12.34"
,
course
.
id
)
self
.
_set_contribution
(
"12.34"
,
course
.
id
)
# Expect that the contribution amount is pre-filled,
# Expect that the contribution amount is pre-filled,
...
@@ -623,7 +633,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -623,7 +633,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
def
test_verification_deadline
(
self
):
def
test_verification_deadline
(
self
):
deadline
=
datetime
(
2999
,
1
,
2
,
tzinfo
=
pytz
.
UTC
)
deadline
=
datetime
(
2999
,
1
,
2
,
tzinfo
=
pytz
.
UTC
)
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
# Set a deadline on the course mode AND on the verification deadline model.
# Set a deadline on the course mode AND on the verification deadline model.
# This simulates the common case in which the upgrade deadline (course mode expiration)
# This simulates the common case in which the upgrade deadline (course mode expiration)
...
@@ -639,7 +649,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -639,7 +649,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
def
test_course_mode_expired
(
self
):
def
test_course_mode_expired
(
self
):
deadline
=
datetime
(
1999
,
1
,
2
,
tzinfo
=
pytz
.
UTC
)
deadline
=
datetime
(
1999
,
1
,
2
,
tzinfo
=
pytz
.
UTC
)
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
# Set the upgrade deadline (course mode expiration) and verification deadline
# Set the upgrade deadline (course mode expiration) and verification deadline
# to the same value. This used to be the default when we used the expiration datetime
# to the same value. This used to be the default when we used the expiration datetime
...
@@ -657,7 +667,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -657,7 +667,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
@ddt.data
(
datetime
(
2999
,
1
,
2
,
tzinfo
=
pytz
.
UTC
),
None
)
@ddt.data
(
datetime
(
2999
,
1
,
2
,
tzinfo
=
pytz
.
UTC
),
None
)
def
test_course_mode_expired_verification_deadline_in_future
(
self
,
verification_deadline
):
def
test_course_mode_expired_verification_deadline_in_future
(
self
,
verification_deadline
):
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
# Set the upgrade deadline in the past, but the verification
# Set the upgrade deadline in the past, but the verification
# deadline in the future.
# deadline in the future.
...
@@ -691,7 +701,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -691,7 +701,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
self
.
assertEqual
(
data
[
"verification_deadline"
],
""
)
self
.
assertEqual
(
data
[
"verification_deadline"
],
""
)
def
test_course_mode_not_expired_verification_deadline_passed
(
self
):
def
test_course_mode_not_expired_verification_deadline_passed
(
self
):
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
# Set the upgrade deadline in the future
# Set the upgrade deadline in the future
# and the verification deadline in the past
# and the verification deadline in the past
...
@@ -717,7 +727,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -717,7 +727,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
@mock.patch.dict
(
settings
.
FEATURES
,
{
'EMBARGO'
:
True
})
@mock.patch.dict
(
settings
.
FEATURES
,
{
'EMBARGO'
:
True
})
def
test_embargo_restrict
(
self
):
def
test_embargo_restrict
(
self
):
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
with
restrict_course
(
course
.
id
)
as
redirect_url
:
with
restrict_course
(
course
.
id
)
as
redirect_url
:
# Simulate that we're embargoed from accessing this
# Simulate that we're embargoed from accessing this
# course based on our IP address.
# course based on our IP address.
...
@@ -726,10 +736,11 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -726,10 +736,11 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
@mock.patch.dict
(
settings
.
FEATURES
,
{
'EMBARGO'
:
True
})
@mock.patch.dict
(
settings
.
FEATURES
,
{
'EMBARGO'
:
True
})
def
test_embargo_allow
(
self
):
def
test_embargo_allow
(
self
):
course
=
self
.
_create_course
(
"verified"
)
course
=
self
.
courses
[
"verified"
]
self
.
_get_page
(
'verify_student_start_flow'
,
course
.
id
)
self
.
_get_page
(
'verify_student_start_flow'
,
course
.
id
)
def
_create_course
(
self
,
*
course_modes
,
**
kwargs
):
@classmethod
def
_create_course
(
cls
,
*
course_modes
,
**
kwargs
):
"""Create a new course with the specified course modes. """
"""Create a new course with the specified course modes. """
course
=
CourseFactory
.
create
(
display_name
=
'<script>alert("XSS")</script>'
)
course
=
CourseFactory
.
create
(
display_name
=
'<script>alert("XSS")</script>'
)
...
@@ -742,7 +753,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -742,7 +753,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
mode_kwargs
[
'sku'
]
=
kwargs
[
'sku'
]
mode_kwargs
[
'sku'
]
=
kwargs
[
'sku'
]
for
course_mode
in
course_modes
:
for
course_mode
in
course_modes
:
min_price
=
(
0
if
course_mode
in
[
"honor"
,
"audit"
]
else
self
.
MIN_PRICE
)
min_price
=
(
0
if
course_mode
in
[
"honor"
,
"audit"
]
else
cls
.
MIN_PRICE
)
CourseModeFactory
(
CourseModeFactory
(
course_id
=
course
.
id
,
course_id
=
course
.
id
,
mode_slug
=
course_mode
,
mode_slug
=
course_mode
,
...
@@ -974,7 +985,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
...
@@ -974,7 +985,7 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
self
.
assertNotEqual
(
httpretty
.
last_request
()
.
headers
,
{})
self
.
assertNotEqual
(
httpretty
.
last_request
()
.
headers
,
{})
class
CheckoutTestMixin
(
object
):
class
CheckoutTestMixin
(
SharedModuleStoreTestCase
):
"""
"""
Mixin implementing test methods that should behave identically regardless
Mixin implementing test methods that should behave identically regardless
of which backend is used (shoppingcart or ecommerce service). Subclasses
of which backend is used (shoppingcart or ecommerce service). Subclasses
...
@@ -986,12 +997,17 @@ class CheckoutTestMixin(object):
...
@@ -986,12 +997,17 @@ class CheckoutTestMixin(object):
compatibility, the effect of using this endpoint is to choose a specific product
compatibility, the effect of using this endpoint is to choose a specific product
(i.e. course mode) and trigger immediate checkout.
(i.e. course mode) and trigger immediate checkout.
"""
"""
@classmethod
def
setUpClass
(
cls
):
super
(
CheckoutTestMixin
,
cls
)
.
setUpClass
()
# This course will continue to exist in the modulestore, even if
cls
.
course
=
CourseFactory
.
create
()
def
setUp
(
self
):
def
setUp
(
self
):
""" Create a user and course. """
""" Create a user and course. """
super
(
CheckoutTestMixin
,
self
)
.
setUp
()
super
(
CheckoutTestMixin
,
self
)
.
setUp
()
self
.
user
=
UserFactory
.
create
(
username
=
"test"
,
password
=
"test"
)
self
.
user
=
UserFactory
.
create
(
username
=
"test"
,
password
=
"test"
)
self
.
course
=
CourseFactory
.
create
()
for
mode
,
min_price
in
((
'audit'
,
0
),
(
'honor'
,
0
),
(
'verified'
,
100
)):
for
mode
,
min_price
in
((
'audit'
,
0
),
(
'honor'
,
0
),
(
'verified'
,
100
)):
CourseModeFactory
(
mode_slug
=
mode
,
course_id
=
self
.
course
.
id
,
min_price
=
min_price
,
sku
=
self
.
make_sku
())
CourseModeFactory
(
mode_slug
=
mode
,
course_id
=
self
.
course
.
id
,
min_price
=
min_price
,
sku
=
self
.
make_sku
())
self
.
client
.
login
(
username
=
"test"
,
password
=
"test"
)
self
.
client
.
login
(
username
=
"test"
,
password
=
"test"
)
...
@@ -1100,7 +1116,7 @@ class CheckoutTestMixin(object):
...
@@ -1100,7 +1116,7 @@ class CheckoutTestMixin(object):
@patch
(
'verify_student.views.checkout_with_shoppingcart'
,
return_value
=
TEST_PAYMENT_DATA
)
@patch
(
'verify_student.views.checkout_with_shoppingcart'
,
return_value
=
TEST_PAYMENT_DATA
)
class
TestCreateOrderShoppingCart
(
CheckoutTestMixin
,
ModuleStoreTestCase
):
class
TestCreateOrderShoppingCart
(
CheckoutTestMixin
):
""" Test view behavior when the shoppingcart is used. """
""" Test view behavior when the shoppingcart is used. """
def
make_sku
(
self
):
def
make_sku
(
self
):
...
@@ -1114,7 +1130,7 @@ class TestCreateOrderShoppingCart(CheckoutTestMixin, ModuleStoreTestCase):
...
@@ -1114,7 +1130,7 @@ class TestCreateOrderShoppingCart(CheckoutTestMixin, ModuleStoreTestCase):
@override_settings
(
ECOMMERCE_API_URL
=
TEST_API_URL
,
ECOMMERCE_API_SIGNING_KEY
=
TEST_API_SIGNING_KEY
)
@override_settings
(
ECOMMERCE_API_URL
=
TEST_API_URL
,
ECOMMERCE_API_SIGNING_KEY
=
TEST_API_SIGNING_KEY
)
@patch
(
'verify_student.views.checkout_with_ecommerce_service'
,
return_value
=
TEST_PAYMENT_DATA
)
@patch
(
'verify_student.views.checkout_with_ecommerce_service'
,
return_value
=
TEST_PAYMENT_DATA
)
class
TestCreateOrderEcommerceService
(
CheckoutTestMixin
,
ModuleStoreTestCase
):
class
TestCreateOrderEcommerceService
(
CheckoutTestMixin
):
""" Test view behavior when the ecommerce service is used. """
""" Test view behavior when the ecommerce service is used. """
def
make_sku
(
self
):
def
make_sku
(
self
):
...
@@ -1500,15 +1516,20 @@ class TestSubmitPhotosForVerification(TestCase):
...
@@ -1500,15 +1516,20 @@ class TestSubmitPhotosForVerification(TestCase):
return
json
.
loads
(
last_request
.
body
)
return
json
.
loads
(
last_request
.
body
)
class
TestPhotoVerificationResultsCallback
(
ModuleStoreTestCase
):
class
TestPhotoVerificationResultsCallback
(
Shared
ModuleStoreTestCase
):
"""
"""
Tests for the results_callback view.
Tests for the results_callback view.
"""
"""
@classmethod
def
setUpClass
(
cls
):
super
(
TestPhotoVerificationResultsCallback
,
cls
)
.
setUpClass
()
cls
.
course
=
CourseFactory
.
create
(
org
=
'Robot'
,
number
=
'999'
,
display_name
=
'Test Course'
)
cls
.
course_id
=
cls
.
course
.
id
def
setUp
(
self
):
def
setUp
(
self
):
super
(
TestPhotoVerificationResultsCallback
,
self
)
.
setUp
()
super
(
TestPhotoVerificationResultsCallback
,
self
)
.
setUp
()
self
.
course
=
CourseFactory
.
create
(
org
=
'Robot'
,
number
=
'999'
,
display_name
=
'Test Course'
)
self
.
course_id
=
self
.
course
.
id
self
.
user
=
UserFactory
.
create
()
self
.
user
=
UserFactory
.
create
()
self
.
attempt
=
SoftwareSecurePhotoVerification
(
self
.
attempt
=
SoftwareSecurePhotoVerification
(
status
=
"submitted"
,
status
=
"submitted"
,
...
@@ -1894,12 +1915,9 @@ class TestInCourseReverifyView(ModuleStoreTestCase):
...
@@ -1894,12 +1915,9 @@ class TestInCourseReverifyView(ModuleStoreTestCase):
# pylint: disable=attribute-defined-outside-init
# pylint: disable=attribute-defined-outside-init
self
.
course_key
=
SlashSeparatedCourseKey
(
"Robot"
,
"999"
,
"Test_Course"
)
self
.
course_key
=
SlashSeparatedCourseKey
(
"Robot"
,
"999"
,
"Test_Course"
)
self
.
course
=
CourseFactory
.
create
(
org
=
'Robot'
,
number
=
'999'
,
display_name
=
'Test Course'
)
# Create the course modes
with
self
.
store
.
bulk_operations
(
self
.
course_key
,
emit_signals
=
False
):
for
mode
in
(
'audit'
,
'honor'
,
'verified'
):
self
.
course
=
CourseFactory
.
create
(
org
=
'Robot'
,
number
=
'999'
,
display_name
=
'Test Course'
)
min_price
=
0
if
mode
in
[
"honor"
,
"audit"
]
else
1
CourseModeFactory
(
mode_slug
=
mode
,
course_id
=
self
.
course_key
,
min_price
=
min_price
)
# Create the 'edx-reverification-block' in course tree
# Create the 'edx-reverification-block' in course tree
section
=
ItemFactory
.
create
(
parent
=
self
.
course
,
category
=
'chapter'
,
display_name
=
'Test Section'
)
section
=
ItemFactory
.
create
(
parent
=
self
.
course
,
category
=
'chapter'
,
display_name
=
'Test Section'
)
...
@@ -1916,6 +1934,12 @@ class TestInCourseReverifyView(ModuleStoreTestCase):
...
@@ -1916,6 +1934,12 @@ class TestInCourseReverifyView(ModuleStoreTestCase):
self
.
reverification_location
=
unicode
(
self
.
reverification
.
location
)
self
.
reverification_location
=
unicode
(
self
.
reverification
.
location
)
self
.
reverification_assessment
=
self
.
reverification
.
related_assessment
self
.
reverification_assessment
=
self
.
reverification
.
related_assessment
# Create the course modes
for
mode
in
(
'audit'
,
'honor'
,
'verified'
):
min_price
=
0
if
mode
in
[
"honor"
,
"audit"
]
else
1
CourseModeFactory
(
mode_slug
=
mode
,
course_id
=
self
.
course_key
,
min_price
=
min_price
)
def
setUp
(
self
):
def
setUp
(
self
):
super
(
TestInCourseReverifyView
,
self
)
.
setUp
()
super
(
TestInCourseReverifyView
,
self
)
.
setUp
()
...
...
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