Skip to content

Commit

Permalink
Merge pull request #17 from edx/dcs/cache-bug
Browse files Browse the repository at this point in the history
Fixes EDUCATOR-4654 by including the course id in the cache key
  • Loading branch information
Dave St.Germain authored Sep 13, 2019
2 parents f6271a5 + 8d028a4 commit aed77e3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion edx_when/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

from __future__ import absolute_import, unicode_literals

__version__ = '0.3'
__version__ = '0.4'

default_app_config = 'edx_when.apps.EdxWhenConfig' # pylint: disable=invalid-name
2 changes: 1 addition & 1 deletion edx_when/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def get_dates_for_course(course_id, user=None, use_cached=True):
"""
log.debug("Getting dates for %s as %s", course_id, user)

cache_key = 'course_dates.%s'
cache_key = 'course_dates.%s' % course_id
if user:
if isinstance(user, int):
user_id = user
Expand Down
10 changes: 5 additions & 5 deletions test_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ def make_block_id(course_id='testX+tt101+2019', block_type='sequential+block'):
return UsageKey.from_string(block_id)


def make_items():
def make_items(course_id='testX+tt101+2019'):
"""
Return item list for set_dates_for_course.
"""
items = [
(make_block_id(), {'due': datetime(2019, 3, 22)}),
(make_block_id(), {'due': datetime(2019, 3, 23), 'test': '1'}),
(make_block_id(), {'start': datetime(2019, 3, 21), 'test': '1'}),
(make_block_id(), {'start': None, 'test': '1'}),
(make_block_id(course_id), {'due': datetime(2019, 3, 22)}),
(make_block_id(course_id), {'due': datetime(2019, 3, 23), 'test': '1'}),
(make_block_id(course_id), {'start': datetime(2019, 3, 21), 'test': '1'}),
(make_block_id(course_id), {'start': None, 'test': '1'}),
]
return items
9 changes: 9 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ def test_get_dates_for_course(self):
# second time is cached
retrieved = api.get_dates_for_course(items[0][0].course_key)
assert len(retrieved) == 3

# third time with new course_id
new_items = make_items('testX+tt202+2019')
api.set_dates_for_course(new_items[0][0].course_key, new_items)
new_retrieved = api.get_dates_for_course(new_items[0][0].course_key)
assert len(new_retrieved) == 3
first_id = list(new_retrieved.keys())[0][0]
last_id = list(retrieved.keys())[0][0]
assert first_id.course_key != last_id.course_key
return items

def test_clear_dates_for_course(self):
Expand Down

0 comments on commit aed77e3

Please sign in to comment.