Commits

Mikhail Korobov committed 6a71f4f Merge

Merge pull request #23 from kharandziuk/feature/ability-to-add-xhr-arg

Feature/ability to add xhr arg

  • Participants
  • Parent commits 78cf8c8, d518641

Comments (0)

Files changed (4)

+*.pyc
 * Iurii Kriachko
 * Will Bradley
 * Julien Aubert
+* Max Kharandziuk <https://github.com/kharandziuk>

File django_webtest/__init__.py

 
     def get(self, url, params=None, headers=None, extra_environ=None,
             status=None, expect_errors=False, user=None, auto_follow=False,
-            content_type=None):
+            content_type=None, **kwargs):
         extra_environ = self._update_environ(extra_environ, user)
         response = super(DjangoTestApp, self).get(
-                  url, params, headers, extra_environ, status, expect_errors)
+                url, params, headers, extra_environ, status, expect_errors, **kwargs)
 
         is_redirect = lambda r: r.status_int >= 300 and r.status_int < 400
         while auto_follow and is_redirect(response):
 
     def post(self, url, params='', headers=None, extra_environ=None,
              status=None, upload_files=None, expect_errors=False,
-             content_type=None, user=None):
+             content_type=None, user=None, **kwargs):
         extra_environ = self._update_environ(extra_environ, user)
         return super(DjangoTestApp, self).post(
                    url, params, headers, extra_environ, status,
-                   upload_files, expect_errors, content_type)
+                   upload_files, expect_errors, content_type, **kwargs)
 
     def put(self, url, params='', headers=None, extra_environ=None,
              status=None, upload_files=None, expect_errors=False,
-             content_type=None, user=None):
+             content_type=None, user=None, **kwargs):
         extra_environ = self._update_environ(extra_environ, user)
         return super(DjangoTestApp, self).put(
                    url, params, headers, extra_environ, status,
 
     def patch(self, url, params='', headers=None, extra_environ=None,
              status=None, upload_files=None, expect_errors=False,
-             content_type=None, user=None):
+             content_type=None, user=None, **kwargs):
         extra_environ = self._update_environ(extra_environ, user)
         return super(DjangoTestApp, self).patch(
                    url, params, headers, extra_environ, status,
-                   upload_files, expect_errors, content_type)
+                   upload_files, expect_errors, content_type, **kwargs)
 
     def options(self, url, params='', headers=None, extra_environ=None,
              status=None, upload_files=None, expect_errors=False,
-             content_type=None, user=None):
+             content_type=None, user=None, **kwargs):
         extra_environ = self._update_environ(extra_environ, user)
         return super(DjangoTestApp, self).options(
-                   url, params, headers, extra_environ, status)
+                   url, params, headers, extra_environ, status, **kwargs)
 
     def delete(self, url, params=NoDefault, headers=None, extra_environ=None,
              status=None, expect_errors=False,
-             content_type=None, user=None):
+             content_type=None, user=None, **kwargs):
         extra_environ = self._update_environ(extra_environ, user)
         return super(DjangoTestApp, self).delete(
                    url, params, headers, extra_environ, status,
-                   expect_errors, content_type)
+                   expect_errors, content_type, **kwargs)
 
     @property
     def session(self):

File django_webtest_tests/testapp_tests/tests.py

         response.mustcontain(name)
         #self.assertTrue(name in response)
 
+    def assertMethodWorksXHR(self, meth, name):
+        try:
+            response = meth('/', xhr=True)
+        except TypeError as e:
+            # for webtest < 2
+            self.assertIn('xhr', e.message)
+        else:
+            # for webtest == 2
+            self.assertEqual(response.status_int, 200)
+            response.mustcontain(name)
+
     def test_get(self):
         self.assertMethodWorks(self.app.get, 'GET')
 
     def test_delete(self):
         self.assertMethodWorks(self.app.delete, 'DELETE')
 
+    def test_get_xhr(self):
+        self.assertMethodWorksXHR(self.app.get, 'GET')
+
+    def test_post_xhr(self):
+        self.assertMethodWorksXHR(self.app.post, 'POST')
+
+    def test_put_xhr(self):
+        self.assertMethodWorksXHR(self.app.put, 'PUT')
+
+    def test_delete_xhr(self):
+        self.assertMethodWorksXHR(self.app.delete, 'DELETE')
+
     if hasattr(TestApp, 'patch'):  # old WebTest versions don't have 'patch' method
         def test_patch(self):
             self.assertMethodWorks(self.app.patch, 'PATCH')