From 57dbb2d47ce9e762904afe99881944e7d4326755 Mon Sep 17 00:00:00 2001 From: Dillon Dumesnil Date: Wed, 19 Feb 2020 11:30:19 -0500 Subject: [PATCH] AA-33: Function to create calendar event id The function will create a unique event id using a user and assignment --- openedx/features/calendar_sync/__init__.py | 17 +++++++++++++ .../features/calendar_sync/tests/__init__.py | 0 .../features/calendar_sync/tests/test_init.py | 25 +++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 openedx/features/calendar_sync/__init__.py create mode 100644 openedx/features/calendar_sync/tests/__init__.py create mode 100644 openedx/features/calendar_sync/tests/test_init.py diff --git a/openedx/features/calendar_sync/__init__.py b/openedx/features/calendar_sync/__init__.py new file mode 100644 index 0000000000..f83d0001c5 --- /dev/null +++ b/openedx/features/calendar_sync/__init__.py @@ -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 diff --git a/openedx/features/calendar_sync/tests/__init__.py b/openedx/features/calendar_sync/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/openedx/features/calendar_sync/tests/test_init.py b/openedx/features/calendar_sync/tests/test_init.py new file mode 100644 index 0000000000..79e2584ff1 --- /dev/null +++ b/openedx/features/calendar_sync/tests/test_init.py @@ -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)