Commits

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: