1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

9856 fix tests

This commit is contained in:
Arthur
2024-03-13 13:13:20 -07:00
parent 151717545a
commit b47c5ee1b8
3 changed files with 13 additions and 6 deletions

View File

@ -36,7 +36,9 @@ class NetBoxGraphQLView(GraphQLView):
# Enforce LOGIN_REQUIRED
if settings.LOGIN_REQUIRED and not request.user.is_authenticated:
# return redirect_to_login(reverse('graphql'))
return HttpResponseForbidden("No credentials provided.")
if request.accepts("text/html"):
return redirect_to_login(reverse('graphql'))
else:
return HttpResponseForbidden("No credentials provided.")
return super().dispatch(request, *args, **kwargs)

View File

@ -33,5 +33,4 @@ class GraphQLTestCase(TestCase):
self.client.logout()
response = self.client.get(url, **header)
with disable_warnings('django.request'):
# self.assertHttpStatus(response, 302) # Redirect to login page
self.assertHttpStatus(response, 403) # Redirect to login page
self.assertHttpStatus(response, 302) # Redirect to login page

View File

@ -499,7 +499,10 @@ class APIViewTestCases:
# Non-authenticated requests should fail
with disable_warnings('django.request'):
self.assertHttpStatus(self.client.post(url, data={'query': query}, format="json"), status.HTTP_403_FORBIDDEN)
header = {
'HTTP_ACCEPT': 'application/json',
}
self.assertHttpStatus(self.client.post(url, data={'query': query}, format="json", **header), status.HTTP_403_FORBIDDEN)
# Add object-level permission
obj_perm = ObjectPermission(
@ -524,7 +527,10 @@ class APIViewTestCases:
# Non-authenticated requests should fail
with disable_warnings('django.request'):
self.assertHttpStatus(self.client.post(url, data={'query': query}, format="json"), status.HTTP_403_FORBIDDEN)
header = {
'HTTP_ACCEPT': 'application/json',
}
self.assertHttpStatus(self.client.post(url, data={'query': query}, format="json", **header), status.HTTP_403_FORBIDDEN)
# Add object-level permission
obj_perm = ObjectPermission(