2011-04-11 16:13:25 +04:00
|
|
|
from django.test import TestCase
|
|
|
|
from djangorestframework.compat import RequestFactory
|
2011-04-11 19:38:00 +04:00
|
|
|
from djangorestframework.mixins import RequestMixin
|
2011-04-11 16:14:51 +04:00
|
|
|
|
|
|
|
|
2011-04-11 16:13:25 +04:00
|
|
|
class TestMethodOverloading(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.req = RequestFactory()
|
2011-04-11 16:14:51 +04:00
|
|
|
|
2011-04-11 16:13:25 +04:00
|
|
|
def test_standard_behaviour_determines_GET(self):
|
|
|
|
"""GET requests identified"""
|
|
|
|
view = RequestMixin()
|
|
|
|
view.request = self.req.get('/')
|
|
|
|
self.assertEqual(view.method, 'GET')
|
|
|
|
|
|
|
|
def test_standard_behaviour_determines_POST(self):
|
|
|
|
"""POST requests identified"""
|
|
|
|
view = RequestMixin()
|
|
|
|
view.request = self.req.post('/')
|
|
|
|
self.assertEqual(view.method, 'POST')
|
|
|
|
|
|
|
|
def test_overloaded_POST_behaviour_determines_overloaded_method(self):
|
|
|
|
"""POST requests can be overloaded to another method by setting a reserved form field"""
|
|
|
|
view = RequestMixin()
|
2011-05-12 15:55:13 +04:00
|
|
|
view.request = self.req.post('/', {view._METHOD_PARAM: 'DELETE'})
|
|
|
|
view._perform_form_overloading()
|
2011-04-11 16:13:25 +04:00
|
|
|
self.assertEqual(view.method, 'DELETE')
|