aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/tests/modelviews.py
diff options
context:
space:
mode:
authorTom Christie2012-10-30 14:32:31 +0000
committerTom Christie2012-10-30 14:32:31 +0000
commit9b30dab4f772f67a626e176dc4fae0a3ef9c2c81 (patch)
treeca138abf4792f58ffa28684f784f201ee1eef6d7 /djangorestframework/tests/modelviews.py
parent7e5b1501b5cede61a9391fb1a751d2ebcdb37031 (diff)
parent4e7805cb24d73e7f706318b5e5a27e3f9ba39d14 (diff)
downloaddjango-rest-framework-9b30dab4f772f67a626e176dc4fae0a3ef9c2c81.tar.bz2
Merge branch 'restframework2' into rest-framework-2-merge2.0.0
Conflicts: .gitignore .travis.yml AUTHORS README.rst djangorestframework/mixins.py djangorestframework/renderers.py djangorestframework/resources.py djangorestframework/serializer.py djangorestframework/templates/djangorestframework/base.html djangorestframework/templates/djangorestframework/login.html djangorestframework/templatetags/add_query_param.py djangorestframework/tests/accept.py djangorestframework/tests/authentication.py djangorestframework/tests/content.py djangorestframework/tests/reverse.py djangorestframework/tests/serializer.py djangorestframework/views.py docs/examples.rst docs/examples/blogpost.rst docs/examples/modelviews.rst docs/examples/objectstore.rst docs/examples/permissions.rst docs/examples/pygments.rst docs/examples/views.rst docs/howto/alternativeframeworks.rst docs/howto/mixin.rst docs/howto/reverse.rst docs/howto/usingurllib2.rst docs/index.rst docs/topics/release-notes.md examples/sandbox/views.py rest_framework/__init__.py rest_framework/compat.py rest_framework/utils/breadcrumbs.py setup.py
Diffstat (limited to 'djangorestframework/tests/modelviews.py')
-rw-r--r--djangorestframework/tests/modelviews.py90
1 files changed, 0 insertions, 90 deletions
diff --git a/djangorestframework/tests/modelviews.py b/djangorestframework/tests/modelviews.py
deleted file mode 100644
index ccd8513f..00000000
--- a/djangorestframework/tests/modelviews.py
+++ /dev/null
@@ -1,90 +0,0 @@
-from django.conf.urls.defaults import patterns, url
-from django.forms import ModelForm
-from django.contrib.auth.models import Group, User
-from djangorestframework.resources import ModelResource
-from djangorestframework.views import ListOrCreateModelView, InstanceModelView
-from djangorestframework.tests.models import CustomUser
-from djangorestframework.tests.testcases import TestModelsTestCase
-
-
-class GroupResource(ModelResource):
- model = Group
-
-
-class UserForm(ModelForm):
- class Meta:
- model = User
- exclude = ('last_login', 'date_joined')
-
-
-class UserResource(ModelResource):
- model = User
- form = UserForm
-
-
-class CustomUserResource(ModelResource):
- model = CustomUser
-
-urlpatterns = patterns('',
- url(r'^users/$', ListOrCreateModelView.as_view(resource=UserResource), name='users'),
- url(r'^users/(?P<id>[0-9]+)/$', InstanceModelView.as_view(resource=UserResource)),
- url(r'^customusers/$', ListOrCreateModelView.as_view(resource=CustomUserResource), name='customusers'),
- url(r'^customusers/(?P<id>[0-9]+)/$', InstanceModelView.as_view(resource=CustomUserResource)),
- url(r'^groups/$', ListOrCreateModelView.as_view(resource=GroupResource), name='groups'),
- url(r'^groups/(?P<id>[0-9]+)/$', InstanceModelView.as_view(resource=GroupResource)),
-)
-
-
-class ModelViewTests(TestModelsTestCase):
- """Test the model views djangorestframework provides"""
- urls = 'djangorestframework.tests.modelviews'
-
- def test_creation(self):
- """Ensure that a model object can be created"""
- self.assertEqual(0, Group.objects.count())
-
- response = self.client.post('/groups/', {'name': 'foo'})
-
- self.assertEqual(response.status_code, 201)
- self.assertEqual(1, Group.objects.count())
- self.assertEqual('foo', Group.objects.all()[0].name)
-
- def test_creation_with_m2m_relation(self):
- """Ensure that a model object with a m2m relation can be created"""
- group = Group(name='foo')
- group.save()
- self.assertEqual(0, User.objects.count())
-
- response = self.client.post('/users/', {'username': 'bar', 'password': 'baz', 'groups': [group.id]})
-
- self.assertEqual(response.status_code, 201)
- self.assertEqual(1, User.objects.count())
-
- user = User.objects.all()[0]
- self.assertEqual('bar', user.username)
- self.assertEqual('baz', user.password)
- self.assertEqual(1, user.groups.count())
-
- group = user.groups.all()[0]
- self.assertEqual('foo', group.name)
-
- def test_creation_with_m2m_relation_through(self):
- """
- Ensure that a model object with a m2m relation can be created where that
- relation uses a through table
- """
- group = Group(name='foo')
- group.save()
- self.assertEqual(0, User.objects.count())
-
- response = self.client.post('/customusers/', {'username': 'bar', 'groups': [group.id]})
-
- self.assertEqual(response.status_code, 201)
- self.assertEqual(1, CustomUser.objects.count())
-
- user = CustomUser.objects.all()[0]
- self.assertEqual('bar', user.username)
- self.assertEqual(1, user.groups.count())
-
- group = user.groups.all()[0]
- self.assertEqual('foo', group.name)