@@ -108,6 +108,51 @@ def test_has_put_as_create_permissions(self):
108
108
response = instance_view (request , pk = '2' )
109
109
self .assertEqual (response .status_code , status .HTTP_403_FORBIDDEN )
110
110
111
+ def test_options_permitted (self ):
112
+ request = factory .options ('/' , content_type = 'application/json' ,
113
+ HTTP_AUTHORIZATION = self .permitted_credentials )
114
+ response = root_view (request , pk = '1' )
115
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
116
+ self .assertIn ('actions' , response .data )
117
+ self .assertEquals (response .data ['actions' ].keys (), ['POST' , 'GET' ,])
118
+
119
+ request = factory .options ('/1' , content_type = 'application/json' ,
120
+ HTTP_AUTHORIZATION = self .permitted_credentials )
121
+ response = instance_view (request , pk = '1' )
122
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
123
+ self .assertIn ('actions' , response .data )
124
+ self .assertEquals (response .data ['actions' ].keys (), ['PUT' , 'PATCH' , 'DELETE' , 'GET' ,])
125
+
126
+ def test_options_disallowed (self ):
127
+ request = factory .options ('/' , content_type = 'application/json' ,
128
+ HTTP_AUTHORIZATION = self .disallowed_credentials )
129
+ response = root_view (request , pk = '1' )
130
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
131
+ self .assertIn ('actions' , response .data )
132
+ self .assertEquals (response .data ['actions' ].keys (), ['GET' ,])
133
+
134
+ request = factory .options ('/1' , content_type = 'application/json' ,
135
+ HTTP_AUTHORIZATION = self .disallowed_credentials )
136
+ response = instance_view (request , pk = '1' )
137
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
138
+ self .assertIn ('actions' , response .data )
139
+ self .assertEquals (response .data ['actions' ].keys (), ['GET' ,])
140
+
141
+ def test_options_updateonly (self ):
142
+ request = factory .options ('/' , content_type = 'application/json' ,
143
+ HTTP_AUTHORIZATION = self .updateonly_credentials )
144
+ response = root_view (request , pk = '1' )
145
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
146
+ self .assertIn ('actions' , response .data )
147
+ self .assertEquals (response .data ['actions' ].keys (), ['GET' ,])
148
+
149
+ request = factory .options ('/1' , content_type = 'application/json' ,
150
+ HTTP_AUTHORIZATION = self .updateonly_credentials )
151
+ response = instance_view (request , pk = '1' )
152
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
153
+ self .assertIn ('actions' , response .data )
154
+ self .assertEquals (response .data ['actions' ].keys (), ['PUT' , 'PATCH' , 'GET' ,])
155
+
111
156
112
157
class OwnerModel (models .Model ):
113
158
text = models .CharField (max_length = 100 )
0 commit comments