Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
ecommerce
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
ecommerce
Commits
9feab946
Commit
9feab946
authored
Apr 24, 2018
by
Robert Raposa
Committed by
Christopher Lee
Apr 24, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix cache enrollments of None.
LEARNER-5001
parent
7faa62c7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
3 deletions
+29
-3
ecommerce/programs/conditions.py
+6
-2
ecommerce/programs/tests/test_conditions.py
+23
-1
No files found.
ecommerce/programs/conditions.py
View file @
9feab946
...
...
@@ -20,6 +20,9 @@ Condition = get_model('offer', 'Condition')
logger
=
logging
.
getLogger
(
__name__
)
CACHE_MISS
=
object
()
class
ProgramCourseRunSeatsCondition
(
SingleItemConsumptionConditionMixin
,
Condition
):
class
Meta
(
object
):
app_label
=
'programs'
...
...
@@ -52,8 +55,9 @@ class ProgramCourseRunSeatsCondition(SingleItemConsumptionConditionMixin, Condit
resource
=
resource_name
,
username
=
basket
.
owner
.
username
,
)
data_list
=
cache
.
get
(
cache_key
)
if
not
data_list
:
data_list
=
cache
.
get
(
cache_key
,
CACHE_MISS
)
if
data_list
is
CACHE_MISS
:
data_list
=
None
user
=
basket
.
owner
.
username
try
:
if
waffle
.
switch_is_active
(
"debug_logging_for_excessive_lms_calls"
):
...
...
ecommerce/programs/tests/test_conditions.py
View file @
9feab946
...
...
@@ -22,7 +22,7 @@ class ProgramCourseRunSeatsConditionTests(ProgramTestMixin, TestCase):
def
setUp
(
self
):
super
(
ProgramCourseRunSeatsConditionTests
,
self
)
.
setUp
()
self
.
condition
=
factories
.
ProgramCourseRunSeatsConditionFactory
()
self
.
test_product
=
ProductFactory
(
stockrecords__price_excl_tax
=
10
)
self
.
test_product
=
ProductFactory
(
stockrecords__price_excl_tax
=
10
,
categories
=
[]
)
self
.
site
.
siteconfiguration
.
enable_partial_program
=
True
def
test_name
(
self
):
...
...
@@ -266,3 +266,25 @@ class ProgramCourseRunSeatsConditionTests(ProgramTestMixin, TestCase):
with
mock
.
patch
(
'ecommerce.programs.conditions.traverse_pagination'
)
as
mock_processing_entitlements
:
self
.
assertFalse
(
self
.
condition
.
is_satisfied
(
offer
,
basket
))
mock_processing_entitlements
.
assert_not_called
()
@httpretty.activate
def
test_get_lms_resource_for_user_caching_none
(
self
):
"""
LMS resource should be properly cached when enrollments is None.
"""
basket
=
factories
.
BasketFactory
(
site
=
self
.
site
,
owner
=
factories
.
UserFactory
())
resource_name
=
'test_resource_name'
mock_endpoint
=
mock
.
Mock
()
mock_endpoint
.
get
.
return_value
=
None
return_value
=
self
.
condition
.
_get_lms_resource_for_user
(
basket
,
resource_name
,
mock_endpoint
)
# pylint: disable=protected-access
self
.
assertEqual
(
return_value
,
[])
self
.
assertEquals
(
mock_endpoint
.
get
.
call_count
,
1
,
'Endpoint should be called before caching.'
)
mock_endpoint
.
reset_mock
()
return_value
=
self
.
condition
.
_get_lms_resource_for_user
(
basket
,
resource_name
,
mock_endpoint
)
# pylint: disable=protected-access
self
.
assertEqual
(
return_value
,
[])
self
.
assertEquals
(
mock_endpoint
.
get
.
call_count
,
0
,
'Endpoint should NOT be called after caching.'
)
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