Merge pull request #23141 from edx/ddumesnil/create-calendar-event-id-AA-33
AA-33: Function to uniquely create calendar event id for user and assignment
This commit is contained in:
17
openedx/features/calendar_sync/__init__.py
Normal file
17
openedx/features/calendar_sync/__init__.py
Normal file
@@ -0,0 +1,17 @@
|
||||
"""
|
||||
Calendar syncing Course dates with a User.
|
||||
"""
|
||||
|
||||
|
||||
def get_calendar_event_id(user, block_key, date_type):
|
||||
"""
|
||||
Creates a unique event id based on a user and a course block key
|
||||
|
||||
Parameters:
|
||||
user (User): The user requesting a calendar event
|
||||
block_key (str): The block key containing the date for the calendar event
|
||||
date_type (str): The type of the date (e.g. 'due', 'start', 'end', etc.)
|
||||
Returns:
|
||||
event id (str)
|
||||
"""
|
||||
return user.username + '.' + block_key + '.' + date_type
|
||||
0
openedx/features/calendar_sync/tests/__init__.py
Normal file
0
openedx/features/calendar_sync/tests/__init__.py
Normal file
25
openedx/features/calendar_sync/tests/test_init.py
Normal file
25
openedx/features/calendar_sync/tests/test_init.py
Normal file
@@ -0,0 +1,25 @@
|
||||
""" Tests the contents of the __init__.py file """
|
||||
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from openedx.features.calendar_sync import get_calendar_event_id
|
||||
from student.tests.factories import UserFactory
|
||||
|
||||
TEST_PASSWORD = 'test'
|
||||
|
||||
|
||||
class TestCalendarSyncInit(TestCase):
|
||||
""" Tests for the contents of __init__.py """
|
||||
def setUp(self):
|
||||
super(TestCalendarSyncInit, self).setUp()
|
||||
self.user = UserFactory(password=TEST_PASSWORD)
|
||||
|
||||
def test_get_calendar_event_id(self):
|
||||
block_key = 'block-v1:Org+Number+Term+type@sequential+block@gibberish'
|
||||
date_type = 'due'
|
||||
event_id = get_calendar_event_id(self.user, block_key, date_type)
|
||||
expected = '{username}.{block_key}.{date_type}'.format(
|
||||
username=self.user.username, block_key=block_key, date_type=date_type
|
||||
)
|
||||
self.assertEqual(event_id, expected)
|
||||
Reference in New Issue
Block a user