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))
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]))
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)