Ejemplo n.º 1
0
    def post(self, request, course_id):
        """
        Updates the request user's calendar sync subscription status

        Arguments:
            request: HTTP request
            course_id (str): string of a course key
        """
        course_key = CourseKey.from_string(course_id)
        tool_data = request.POST.get('tool_data')
        if not tool_data:
            return HttpResponse('Tool data was not provided.',
                                status=status.HTTP_422_UNPROCESSABLE_ENTITY)

        json_acceptable_string = tool_data.replace("'", "\"")
        data = json.loads(json_acceptable_string)
        toggle_data = data.get('toggle_data')
        if toggle_data == SUBSCRIBE:
            subscribe_user_to_calendar(request.user, course_key)
        elif toggle_data == UNSUBSCRIBE:
            unsubscribe_user_to_calendar(request.user, course_key)
        else:
            return HttpResponse(
                'Toggle data was not provided or had unknown value.',
                status=status.HTTP_422_UNPROCESSABLE_ENTITY)
        return redirect(
            reverse('openedx.course_experience.course_home', args=[course_id]))
Ejemplo n.º 2
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.º 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)