12589 fix tests

This commit is contained in:
Arthur 2023-06-23 08:26:31 -07:00
parent 98ac45ec3c
commit 53b19980a1
3 changed files with 29 additions and 4 deletions

View File

@ -94,6 +94,7 @@ class ObjectPermissionMixin:
def has_perm(self, user_obj, perm, obj=None): def has_perm(self, user_obj, perm, obj=None):
app_label, action, model_name = resolve_permission(perm) app_label, action, model_name = resolve_permission(perm)
# breakpoint()
# Superusers implicitly have all permissions # Superusers implicitly have all permissions
if user_obj.is_active and user_obj.is_superuser: if user_obj.is_active and user_obj.is_superuser:

View File

@ -375,6 +375,15 @@ class NetBoxUserView(generic.ObjectView):
'active_tab': 'user', 'active_tab': 'user',
} }
def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)
def get(self, request, *args, **kwargs):
return super().get(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
return super().post(request, *args, **kwargs)
@register_model_view(NetBoxUser, 'edit') @register_model_view(NetBoxUser, 'edit')
class NetBoxUserEditView(generic.ObjectEditView): class NetBoxUserEditView(generic.ObjectEditView):

View File

@ -1,5 +1,6 @@
import csv import csv
from django.conf import settings
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.db.models import ForeignKey from django.db.models import ForeignKey
@ -64,6 +65,13 @@ class ViewTestCases:
def test_get_object_anonymous(self): def test_get_object_anonymous(self):
# Make the request as an unauthenticated user # Make the request as an unauthenticated user
self.client.logout() self.client.logout()
ct = ContentType.objects.get_for_model(self.model)
if (ct.app_label, ct.model) in settings.EXEMPT_EXCLUDE_MODELS:
# Models listed in EXEMPT_EXCLUDE_MODELS should not be accessible to anonymous users
with disable_warnings('django.request'):
response = self.client.get(self._get_queryset().first().get_absolute_url())
self.assertHttpStatus(response, 302)
else:
response = self.client.get(self._get_queryset().first().get_absolute_url()) response = self.client.get(self._get_queryset().first().get_absolute_url())
self.assertHttpStatus(response, 200) self.assertHttpStatus(response, 200)
@ -407,6 +415,13 @@ class ViewTestCases:
def test_list_objects_anonymous(self): def test_list_objects_anonymous(self):
# Make the request as an unauthenticated user # Make the request as an unauthenticated user
self.client.logout() self.client.logout()
ct = ContentType.objects.get_for_model(self.model)
if (ct.app_label, ct.model) in settings.EXEMPT_EXCLUDE_MODELS:
# Models listed in EXEMPT_EXCLUDE_MODELS should not be accessible to anonymous users
with disable_warnings('django.request'):
response = self.client.get(self._get_url('list'))
self.assertHttpStatus(response, 302)
else:
response = self.client.get(self._get_url('list')) response = self.client.get(self._get_url('list'))
self.assertHttpStatus(response, 200) self.assertHttpStatus(response, 200)