Carles Barrobés avatar Carles Barrobés committed 057e962

Yet more test refactoring, and remove Python 2.7+ unittest's 'assertIn'

Comments (0)

Files changed (1)

djangorestframework/tests/views.py

     
     def test_options_method_simple_view(self):
         response = self.client.options('/mock/')
-        self.assertEqual(response.status_code, 200)
-        self.assertEqual(response['Content-Type'].split(';')[0], 'application/json')        
-        parser = JSONParser(None)
-        (data, files) = parser.parse(StringIO(response.content))
-        self.assertIn('application/json', data['renders']) 
         self._verify_options_response(response, 
                                       name='Mock', 
                                       description='This is a basic mock view')
         
     def test_options_method_resource_view(self):
         response = self.client.options('/resourcemock/')
-        self.assertEqual(response.status_code, 200)
-        self.assertEqual(response['Content-Type'].split(';')[0], 'application/json')        
         self._verify_options_response(response, 
                                       name='Resource Mock', 
                                       description='This is a resource-based mock view', 
         
     def test_options_method_model_resource_list_view(self):
         response = self.client.options('/model/')
-        self.assertEqual(response.status_code, 200)
-        self.assertEqual(response['Content-Type'].split(';')[0], 'application/json')
         self._verify_options_response(response, 
                                       name='Mock List', 
                                       description='This is a mock model-based resource', 
 
     def test_options_method_model_resource_detail_view(self):
         response = self.client.options('/model/0/')
-        self.assertEqual(response.status_code, 200)
-        self.assertEqual(response['Content-Type'].split(';')[0], 'application/json')
         self._verify_options_response(response, 
                                       name='Mock Instance', 
                                       description='This is a mock model-based resource', 
                                               'baz':'CharField', 
                                               })
 
-    def _verify_options_response(self, response, name, description, fields=None):
+    def _verify_options_response(self, response, name, description, fields=None, status=200, 
+                                 mime_type='application/json'):
+        self.assertEqual(response.status_code, status)
+        self.assertEqual(response['Content-Type'].split(';')[0], mime_type)
         parser = JSONParser(None)
         (data, files) = parser.parse(StringIO(response.content))
-        self.assertIn('application/json', data['renders']) 
+        self.assertTrue('application/json' in data['renders']) 
         self.assertEqual(name, data['name']) 
         self.assertEqual(description, data['description']) 
         if fields is None:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.