aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/tests/methods.py
diff options
context:
space:
mode:
authortom christie tom@tomchristie.com2011-02-04 21:52:21 +0000
committertom christie tom@tomchristie.com2011-02-04 21:52:21 +0000
commitfcd7f414c407c8dab7c0badbfa16476826dad3ae (patch)
tree4d532d354e5f63b0ab31212d2dfc26d937c2720d /djangorestframework/tests/methods.py
parenteebcdc4dc0e3b34fa76eca638c469b1e79240844 (diff)
downloaddjango-rest-framework-fcd7f414c407c8dab7c0badbfa16476826dad3ae.tar.bz2
Huge stack of refactoring getting stuff into Mixin classes, and loads of tests. Kickass.
Diffstat (limited to 'djangorestframework/tests/methods.py')
-rw-r--r--djangorestframework/tests/methods.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/djangorestframework/tests/methods.py b/djangorestframework/tests/methods.py
new file mode 100644
index 00000000..e580ba02
--- /dev/null
+++ b/djangorestframework/tests/methods.py
@@ -0,0 +1,52 @@
+from django.test import TestCase
+from djangorestframework.tests.utils import RequestFactory
+from djangorestframework.methods import MethodMixin, StandardMethodMixin, OverloadedPOSTMethodMixin
+
+
+class TestMethodMixins(TestCase):
+ def setUp(self):
+ self.req = RequestFactory()
+
+ # Interface tests
+
+ def test_method_mixin_interface(self):
+ """Ensure the base ContentMixin interface is as expected."""
+ self.assertRaises(NotImplementedError, MethodMixin().determine_method, None)
+
+ def test_standard_method_mixin_interface(self):
+ """Ensure the StandardMethodMixin interface is as expected."""
+ self.assertTrue(issubclass(StandardMethodMixin, MethodMixin))
+ getattr(StandardMethodMixin, 'determine_method')
+
+ def test_overloaded_method_mixin_interface(self):
+ """Ensure the OverloadedPOSTMethodMixin interface is as expected."""
+ self.assertTrue(issubclass(OverloadedPOSTMethodMixin, MethodMixin))
+ getattr(OverloadedPOSTMethodMixin, 'FORM_PARAM_METHOD')
+ getattr(OverloadedPOSTMethodMixin, 'determine_method')
+
+ # Behavioural tests
+
+ def test_standard_behaviour_determines_GET(self):
+ """GET requests identified as GET method with StandardMethodMixin"""
+ request = self.req.get('/')
+ self.assertEqual(StandardMethodMixin().determine_method(request), 'GET')
+
+ def test_standard_behaviour_determines_POST(self):
+ """POST requests identified as POST method with StandardMethodMixin"""
+ request = self.req.post('/')
+ self.assertEqual(StandardMethodMixin().determine_method(request), 'POST')
+
+ def test_overloaded_POST_behaviour_determines_GET(self):
+ """GET requests identified as GET method with OverloadedPOSTMethodMixin"""
+ request = self.req.get('/')
+ self.assertEqual(OverloadedPOSTMethodMixin().determine_method(request), 'GET')
+
+ def test_overloaded_POST_behaviour_determines_POST(self):
+ """POST requests identified as POST method with OverloadedPOSTMethodMixin"""
+ request = self.req.post('/')
+ self.assertEqual(OverloadedPOSTMethodMixin().determine_method(request), 'POST')
+
+ def test_overloaded_POST_behaviour_determines_overloaded_method(self):
+ """POST requests can be overloaded to another method by setting a reserved form field with OverloadedPOSTMethodMixin"""
+ request = self.req.post('/', {OverloadedPOSTMethodMixin.FORM_PARAM_METHOD: 'DELETE'})
+ self.assertEqual(OverloadedPOSTMethodMixin().determine_method(request), 'DELETE')