Skip to content

Commit

Permalink
test: Update tests to the new return code.
Browse files Browse the repository at this point in the history
When including `JwtAuthentication`, the auth_header becomes `JWT
realm="api"`. Without it, it is `None`. This changes the behavior of the
code in DRF and returns a slightly different auth response.

Relevant Code: https://github.com/encode/django-rest-framework/blob/56946fac8f29aa44ce84391f138d63c4c8a2a285/rest_framework/views.py#L456C3-L456C3
  • Loading branch information
feanil committed Aug 30, 2023
1 parent 4a03cef commit 93cc859
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion openedx/core/djangoapps/embargo/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def mock_country(reader, country):
def test_course_access_endpoint_with_logged_out_user(self):
self.client.logout()
response = self.client.get(self.url, data=self.request_data)
assert response.status_code == 403
assert response.status_code == 401

def test_course_access_endpoint_with_non_staff_user(self):
user = UserFactory(is_staff=False)
Expand Down
14 changes: 7 additions & 7 deletions openedx/core/djangoapps/notifications/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ def test_course_enrollment_list_view(self, show_notifications_tray):
def test_course_enrollment_api_permission(self):
"""
Calls api without login.
Check is 403 is returned
Check is 401 is returned
"""
url = reverse('enrollment-list')
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)


@override_waffle_flag(ENABLE_NOTIFICATIONS, active=True)
Expand Down Expand Up @@ -238,7 +238,7 @@ def test_get_user_notification_preference_without_login(self):
Test get user notification preference without login.
"""
response = self.client.get(self.path)
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)

@mock.patch("eventtracking.tracker.emit")
def test_get_user_notification_preference(self, mock_emit):
Expand Down Expand Up @@ -384,13 +384,13 @@ def test_list_notifications_with_app_name_filter(self):

def test_list_notifications_without_authentication(self):
"""
Test that the view returns 403 if the user is not authenticated.
Test that the view returns 401 if the user is not authenticated.
"""
# Make a request to the view without authenticating.
response = self.client.get(self.url)

# Assert that the response is unauthorized.
self.assertEqual(response.status_code, 403)
self.assertEqual(response.status_code, 401)

def test_list_notifications_with_expiry_date(self):
"""
Expand Down Expand Up @@ -506,10 +506,10 @@ def test_get_unseen_notifications_count_with_show_notifications_tray(self, show_

def test_get_unseen_notifications_count_for_unauthenticated_user(self):
"""
Test that the endpoint returns 403 for an unauthenticated user.
Test that the endpoint returns 401 for an unauthenticated user.
"""
response = self.client.get(self.url)
self.assertEqual(response.status_code, 403)
self.assertEqual(response.status_code, 401)

def test_get_unseen_notifications_count_for_user_with_no_notifications(self):
"""
Expand Down

0 comments on commit 93cc859

Please sign in to comment.