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:
@ -36,7 +36,9 @@ class NetBoxGraphQLView(GraphQLView):
|
|||||||
|
|
||||||
# Enforce LOGIN_REQUIRED
|
# Enforce LOGIN_REQUIRED
|
||||||
if settings.LOGIN_REQUIRED and not request.user.is_authenticated:
|
if settings.LOGIN_REQUIRED and not request.user.is_authenticated:
|
||||||
# return redirect_to_login(reverse('graphql'))
|
if request.accepts("text/html"):
|
||||||
|
return redirect_to_login(reverse('graphql'))
|
||||||
|
else:
|
||||||
return HttpResponseForbidden("No credentials provided.")
|
return HttpResponseForbidden("No credentials provided.")
|
||||||
|
|
||||||
return super().dispatch(request, *args, **kwargs)
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
@ -33,5 +33,4 @@ class GraphQLTestCase(TestCase):
|
|||||||
self.client.logout()
|
self.client.logout()
|
||||||
response = self.client.get(url, **header)
|
response = self.client.get(url, **header)
|
||||||
with disable_warnings('django.request'):
|
with disable_warnings('django.request'):
|
||||||
# self.assertHttpStatus(response, 302) # Redirect to login page
|
self.assertHttpStatus(response, 302) # Redirect to login page
|
||||||
self.assertHttpStatus(response, 403) # Redirect to login page
|
|
||||||
|
@ -499,7 +499,10 @@ class APIViewTestCases:
|
|||||||
|
|
||||||
# Non-authenticated requests should fail
|
# Non-authenticated requests should fail
|
||||||
with disable_warnings('django.request'):
|
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
|
# Add object-level permission
|
||||||
obj_perm = ObjectPermission(
|
obj_perm = ObjectPermission(
|
||||||
@ -524,7 +527,10 @@ class APIViewTestCases:
|
|||||||
|
|
||||||
# Non-authenticated requests should fail
|
# Non-authenticated requests should fail
|
||||||
with disable_warnings('django.request'):
|
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
|
# Add object-level permission
|
||||||
obj_perm = ObjectPermission(
|
obj_perm = ObjectPermission(
|
||||||
|
Reference in New Issue
Block a user