Skip to content

Commit

Permalink
fix: course wide preferences are visible when patch call is sent (#33726
Browse files Browse the repository at this point in the history
)
  • Loading branch information
muhammadadeeltajamul authored Nov 16, 2023
1 parent 94658f5 commit 1806b29
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
16 changes: 12 additions & 4 deletions openedx/core/djangoapps/notifications/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion openedx/core/djangoapps/notifications/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 1806b29

Please sign in to comment.