@@ -55,11 +55,16 @@ class EmptyListView(generics.ListCreateAPIView):
55
55
permission_classes = [permissions .DjangoModelPermissions ]
56
56
57
57
58
+ class IgnoredGetQuerySetListView (GetQuerySetListView ):
59
+ _ignore_model_permissions = True
60
+
61
+
58
62
root_view = RootView .as_view ()
59
63
api_root_view = DefaultRouter ().get_api_root_view ()
60
64
instance_view = InstanceView .as_view ()
61
65
get_queryset_list_view = GetQuerySetListView .as_view ()
62
66
empty_list_view = EmptyListView .as_view ()
67
+ ignored_get_queryset_list_view = IgnoredGetQuerySetListView .as_view ()
63
68
64
69
65
70
def basic_auth_header (username , password ):
@@ -107,6 +112,27 @@ def test_api_root_view_discard_default_django_model_permission(self):
107
112
response = api_root_view (request )
108
113
self .assertEqual (response .status_code , status .HTTP_200_OK )
109
114
115
+ def test_ignore_model_permissions_with_unauthenticated_user (self ):
116
+ """
117
+ We check that the ``_ignore_model_permissions`` attribute
118
+ doesn't ignore the authentication.
119
+ """
120
+ request = factory .get ('/' , format = 'json' )
121
+ request .resolver_match = ResolverMatch ('get' , (), {})
122
+ response = ignored_get_queryset_list_view (request )
123
+ self .assertEqual (response .status_code , status .HTTP_401_UNAUTHORIZED )
124
+
125
+ def test_ignore_model_permissions_with_authenticated_user (self ):
126
+ """
127
+ We check that the ``_ignore_model_permissions`` attribute
128
+ with an authenticated user.
129
+ """
130
+ request = factory .get ('/' , format = 'json' ,
131
+ HTTP_AUTHORIZATION = self .permitted_credentials )
132
+ request .resolver_match = ResolverMatch ('get' , (), {})
133
+ response = ignored_get_queryset_list_view (request )
134
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
135
+
110
136
def test_get_queryset_has_create_permissions (self ):
111
137
request = factory .post ('/' , {'text' : 'foobar' }, format = 'json' ,
112
138
HTTP_AUTHORIZATION = self .permitted_credentials )
0 commit comments