diff --git a/openedx/core/djangoapps/notifications/tests/test_views.py b/openedx/core/djangoapps/notifications/tests/test_views.py index e09b4989d537..57fe1532d3ba 100644 --- a/openedx/core/djangoapps/notifications/tests/test_views.py +++ b/openedx/core/djangoapps/notifications/tests/test_views.py @@ -210,11 +210,13 @@ def setUp(self): enrollment=enrollment_data ) - def _expected_api_response(self): + def _expected_api_response(self, course=None): """ Helper method to return expected API response. """ - return { + if course is None: + course = self.course + response = { 'id': 1, 'course_name': 'course-v1:testorg+testcourse+testrun Course', 'course_id': 'course-v1:testorg+testcourse+testrun', @@ -245,6 +247,12 @@ def _expected_api_response(self): } } } + if not ENABLE_COURSEWIDE_NOTIFICATIONS.is_enabled(course.id): + app_prefs = response['notification_preference_config']['discussion'] + notification_types = app_prefs['notification_types'] + for notification_type in ['new_discussion_post', 'new_question_post']: + notification_types.pop(notification_type) + return response def test_get_user_notification_preference_without_login(self): """ @@ -254,13 +262,13 @@ def test_get_user_notification_preference_without_login(self): self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) @mock.patch("eventtracking.tracker.emit") + @override_waffle_flag(ENABLE_COURSEWIDE_NOTIFICATIONS, active=True) def test_get_user_notification_preference(self, mock_emit): """ Test get user notification preference. """ self.client.login(username=self.user.username, password=self.TEST_PASSWORD) - with override_waffle_flag(ENABLE_COURSEWIDE_NOTIFICATIONS, active=True): - response = self.client.get(self.path) + response = self.client.get(self.path) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data, self._expected_api_response()) event_name, event_data = mock_emit.call_args[0] diff --git a/openedx/core/djangoapps/notifications/views.py b/openedx/core/djangoapps/notifications/views.py index 810aa7492825..7cad6052a106 100644 --- a/openedx/core/djangoapps/notifications/views.py +++ b/openedx/core/djangoapps/notifications/views.py @@ -219,7 +219,8 @@ def patch(self, request, course_key_string): updated_notification_preferences = preference_update.save() notification_preference_update_event(request.user, course_id, preference_update.validated_data) serializer = UserCourseNotificationPreferenceSerializer(updated_notification_preferences) - return Response(serializer.data, status=status.HTTP_200_OK) + preferences = filter_course_wide_preferences(course_id, serializer.data) + return Response(preferences, status=status.HTTP_200_OK) @allow_any_authenticated_user()