Commits

Mikhail Korobov committed 10bbf55

Fix OPTIONS method; add more tests

Comments (0)

Files changed (2)

django_webtest/__init__.py

              content_type=None, user=None):
         extra_environ = self._update_environ(extra_environ, user)
         return super(DjangoTestApp, self).options(
-                   url, params, headers, extra_environ, status,
-                   upload_files, expect_errors, content_type)
+                   url, params, headers, extra_environ, status)
 
     def delete(self, url, params='', headers=None, extra_environ=None,
              status=None, expect_errors=False,

django_webtest_tests/testapp_tests/tests.py

 # -*- coding: utf-8 -*-
 from __future__ import unicode_literals, absolute_import
-from webtest import AppError
+from webtest import AppError, TestApp
 
 import django
 from django_webtest import WebTest
 from django.contrib.auth.models import User
 from django.core.urlresolvers import reverse
 
-class GetRequestTest(WebTest):
-    def test_get_request(self):
-        response = self.app.get('/')
+class MethodsTest(WebTest):
+
+    csrf_checks = False
+
+    def assertMethodWorks(self, meth, name):
+        response = meth('/')
         self.assertEqual(response.status_int, 200)
-        self.assertTrue('GET' in response)
+        response.mustcontain(name)
+        #self.assertTrue(name in response)
+
+    def test_get(self):
+        self.assertMethodWorks(self.app.get, 'GET')
+
+    def test_post(self):
+        self.assertMethodWorks(self.app.post, 'POST')
+
+    def test_put(self):
+        self.assertMethodWorks(self.app.put, 'PUT')
+
+    def test_delete(self):
+        self.assertMethodWorks(self.app.delete, 'DELETE')
+
+    if hasattr(TestApp, 'patch'):  # old WebTest versions doesn't have patch method
+        def test_patch(self):
+            self.assertMethodWorks(self.app.patch, 'PATCH')
+
+    def test_head(self):
+        response = self.app.head('/')
+        self.assertEqual(response.status_int, 200)
+        assert response.body == b''
+
+    def test_options(self):
+        self.assertMethodWorks(self.app.options, 'OPTIONS')
+
 
 class PostRequestTest(WebTest):
     csrf_checks = False