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
3d520f4f
Commit
3d520f4f
authored
Mar 18, 2015
by
Clinton Blackburn
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7409 from edx/clintonb/filter-empty-string
Fixed CourseMode Filtering Bug
parents
a76fd944
783fb23f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
10 deletions
+27
-10
lms/djangoapps/commerce/tests.py
+25
-9
lms/djangoapps/commerce/views.py
+2
-1
No files found.
lms/djangoapps/commerce/tests.py
View file @
3d520f4f
...
...
@@ -203,17 +203,10 @@ class OrdersViewTests(ModuleStoreTestCase):
# TODO Eventually we should NOT be enrolling users directly from this view.
self
.
assertTrue
(
CourseEnrollment
.
is_enrolled
(
self
.
user
,
self
.
course
.
id
))
@httpretty.activate
def
test_course_without_sku
(
self
):
def
_test_course_without_sku
(
self
):
"""
If the course does NOT have a SKU, the user should be enrolled in the course (under the honor mode) and
redirected to the user dashboard.
Validates the view bypasses the E-Commerce API when the course has no CourseModes with SKUs.
"""
# Remove SKU from all course modes
for
course_mode
in
CourseMode
.
objects
.
filter
(
course_id
=
self
.
course
.
id
):
course_mode
.
sku
=
None
course_mode
.
save
()
# Place an order
self
.
_mock_ecommerce_api
()
response
=
self
.
_post_to_view
()
...
...
@@ -229,6 +222,19 @@ class OrdersViewTests(ModuleStoreTestCase):
self
.
assertIsInstance
(
httpretty
.
last_request
(),
HTTPrettyRequestEmpty
)
@httpretty.activate
def
test_course_without_sku
(
self
):
"""
If the course does NOT have a SKU, the user should be enrolled in the course (under the honor mode) and
redirected to the user dashboard.
"""
# Remove SKU from all course modes
for
course_mode
in
CourseMode
.
objects
.
filter
(
course_id
=
self
.
course
.
id
):
course_mode
.
sku
=
None
course_mode
.
save
()
self
.
_test_course_without_sku
()
@httpretty.activate
@override_settings
(
ECOMMERCE_API_URL
=
None
,
ECOMMERCE_API_SIGNING_KEY
=
None
)
def
test_no_settings
(
self
):
"""
...
...
@@ -245,3 +251,13 @@ class OrdersViewTests(ModuleStoreTestCase):
# Ensure that the user is not enrolled and that no calls were made to the E-Commerce API
self
.
assertTrue
(
CourseEnrollment
.
is_enrolled
(
self
.
user
,
self
.
course
.
id
))
self
.
assertIsInstance
(
httpretty
.
last_request
(),
HTTPrettyRequestEmpty
)
@httpretty.activate
def
test_empty_sku
(
self
):
""" If the CourseMode has an empty string for a SKU, the API should not be used. """
# Set SKU to empty string for all modes.
for
course_mode
in
CourseMode
.
objects
.
filter
(
course_id
=
self
.
course
.
id
):
course_mode
.
sku
=
''
course_mode
.
save
()
self
.
_test_course_without_sku
()
lms/djangoapps/commerce/views.py
View file @
3d520f4f
...
...
@@ -91,7 +91,8 @@ class OrdersView(APIView):
# Default to honor mode. In the future we may expand this view to support additional modes.
mode
=
CourseMode
.
DEFAULT_MODE_SLUG
course_modes
=
CourseMode
.
objects
.
filter
(
course_id
=
course_key
,
mode_slug
=
mode
,
sku__isnull
=
False
)
course_modes
=
CourseMode
.
objects
.
filter
(
course_id
=
course_key
,
mode_slug
=
mode
)
\
.
exclude
(
sku__isnull
=
True
)
.
exclude
(
sku__exact
=
''
)
# If there are no course modes with SKUs, enroll the user without contacting the external API.
if
not
course_modes
.
exists
():
...
...
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