Ejemplo n.º 1
0
    def test_unsubscribe_to_calendar(self):
        self.assertEqual(UserCalendarSyncConfig.objects.count(), 0)
        unsubscribe_user_to_calendar(self.user, self.course_key)
        self.assertEqual(UserCalendarSyncConfig.objects.count(), 0)

        UserCalendarSyncConfig.objects.create(user=self.user, course_key=self.course_key, enabled=True)
        self.assertTrue(UserCalendarSyncConfig.is_enabled_for_course(self.user, self.course_key))
        unsubscribe_user_to_calendar(self.user, self.course_key)
        self.assertFalse(UserCalendarSyncConfig.is_enabled_for_course(self.user, self.course_key))
Ejemplo n.º 2
0
    def test_is_enabled_for_course(self):
        # Calendar Sync Config does not exist and returns False
        self.assertFalse(UserCalendarSyncConfig.is_enabled_for_course(self.user, self.course_key))

        # Default value for enabled is False
        UserCalendarSyncConfig.objects.create(user=self.user, course_key=self.course_key)
        self.assertFalse(UserCalendarSyncConfig.is_enabled_for_course(self.user, self.course_key))

        UserCalendarSyncConfig.objects.filter(user=self.user, course_key=self.course_key).update(enabled=True)
        self.assertTrue(UserCalendarSyncConfig.is_enabled_for_course(self.user, self.course_key))
Ejemplo n.º 3
0
    def test_unsubscribe_to_calendar(self):
        assert UserCalendarSyncConfig.objects.count() == 0
        unsubscribe_user_to_calendar(self.user, self.course_key)
        assert UserCalendarSyncConfig.objects.count() == 0

        UserCalendarSyncConfig.objects.create(user=self.user,
                                              course_key=self.course_key,
                                              enabled=True)
        assert UserCalendarSyncConfig.is_enabled_for_course(
            self.user, self.course_key)
        unsubscribe_user_to_calendar(self.user, self.course_key)
        assert not UserCalendarSyncConfig.is_enabled_for_course(
            self.user, self.course_key)
Ejemplo n.º 4
0
 def test_subscribe_to_calendar(self):
     self.assertEqual(UserCalendarSyncConfig.objects.count(), 0)
     subscribe_user_to_calendar(self.user, self.course_key)
     self.assertEqual(UserCalendarSyncConfig.objects.count(), 1)
     self.assertTrue(
         UserCalendarSyncConfig.is_enabled_for_course(
             self.user, self.course_key))
Ejemplo n.º 5
0
    def is_enabled(cls, request, course_key):
        """
        The Calendar Sync toggle tool is limited to user enabled through a waffle flag.
        Staff always has access.
        """
        if not (CALENDAR_SYNC_FLAG.is_enabled(course_key) and RELATIVE_DATES_FLAG.is_enabled(course_key)):
            return False

        if CourseEnrollment.is_enrolled(request.user, course_key):
            if UserCalendarSyncConfig.is_enabled_for_course(request.user, course_key):
                cls.link_title = _('Unsubscribe from calendar updates')
                cls.toggle_data['toggle_data'] = UNSUBSCRIBE
            else:
                cls.link_title = _('Subscribe to calendar updates')
                cls.toggle_data['toggle_data'] = SUBSCRIBE
            return True
        return False
Ejemplo n.º 6
0
 def test_subscribe_to_calendar(self):
     assert UserCalendarSyncConfig.objects.count() == 0
     subscribe_user_to_calendar(self.user, self.course_key)
     assert UserCalendarSyncConfig.objects.count() == 1
     assert UserCalendarSyncConfig.is_enabled_for_course(
         self.user, self.course_key)