aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/tests/mixins.py
diff options
context:
space:
mode:
authorCraig Blaszczyk2011-07-08 17:37:20 +0100
committerCraig Blaszczyk2011-07-08 17:37:20 +0100
commit6e6b35b5c03d66f612e55c29e11d3096cd2703ac (patch)
treec4ca927eb820bac9f0e8817bed0d883069985e2c /djangorestframework/tests/mixins.py
parent8a2944acdf66a966f0bd4ea4770f012f2597fb4e (diff)
downloaddjango-rest-framework-6e6b35b5c03d66f612e55c29e11d3096cd2703ac.tar.bz2
add unit tests which show m2m creation failing for through table
Diffstat (limited to 'djangorestframework/tests/mixins.py')
-rw-r--r--djangorestframework/tests/mixins.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/djangorestframework/tests/mixins.py b/djangorestframework/tests/mixins.py
index 100109ca..1e8bf410 100644
--- a/djangorestframework/tests/mixins.py
+++ b/djangorestframework/tests/mixins.py
@@ -5,6 +5,7 @@ from djangorestframework.compat import RequestFactory
from django.contrib.auth.models import Group, User
from djangorestframework.mixins import CreateModelMixin
from djangorestframework.resources import ModelResource
+from djangorestframework.tests.models import CustomUser
class TestModelCreation(TestCase):
@@ -53,4 +54,30 @@ class TestModelCreation(TestCase):
self.assertEquals(1, response.cleaned_content.groups.count())
self.assertEquals('foo', response.cleaned_content.groups.all()[0].name)
+ def test_creation_with_m2m_relation_through(self):
+ """
+ Tests creation where the m2m relation uses a through table
+ """
+ class UserResource(ModelResource):
+ model = CustomUser
+
+ def url(self, instance):
+ return "/customusers/%i" % instance.id
+
+ group = Group(name='foo')
+ group.save()
+
+ form_data = {'username': 'bar', 'groups': [group.id]}
+ request = self.req.post('/groups', data=form_data)
+ cleaned_data = dict(form_data)
+ cleaned_data['groups'] = [group]
+ mixin = CreateModelMixin()
+ mixin.resource = UserResource
+ mixin.CONTENT = cleaned_data
+
+ response = mixin.post(request)
+ self.assertEquals(1, CustomUser.objects.count())
+ self.assertEquals(1, response.cleaned_content.groups.count())
+ self.assertEquals('foo', response.cleaned_content.groups.all()[0].name)
+