diff options
| author | Tom Christie | 2012-01-21 17:58:06 +0000 |
|---|---|---|
| committer | Tom Christie | 2012-01-21 17:58:06 +0000 |
| commit | add6c88a265858a6c9943e5cc73b22e2866c98b9 (patch) | |
| tree | af9df7188eb5df2522cbd45bd869c3ec83832cb8 /djangorestframework/tests | |
| parent | c94423151b5e135c5d977d63a7092cc4a8ab5de4 (diff) | |
| parent | 417eacb2eda46feec0e8fb7fac5eb3131ab996f8 (diff) | |
| download | django-rest-framework-add6c88a265858a6c9943e5cc73b22e2866c98b9.tar.bz2 | |
Merge https://github.com/mjumbewu/django-rest-framework
Diffstat (limited to 'djangorestframework/tests')
| -rw-r--r-- | djangorestframework/tests/mixins.py | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/djangorestframework/tests/mixins.py b/djangorestframework/tests/mixins.py index d655841f..72e0b8b0 100644 --- a/djangorestframework/tests/mixins.py +++ b/djangorestframework/tests/mixins.py @@ -4,14 +4,47 @@ from django.utils import simplejson as json from djangorestframework import status from djangorestframework.compat import RequestFactory from django.contrib.auth.models import Group, User -from djangorestframework.mixins import CreateModelMixin, PaginatorMixin +from djangorestframework.mixins import CreateModelMixin, PaginatorMixin, ReadModelMixin from djangorestframework.resources import ModelResource -from djangorestframework.response import Response +from djangorestframework.response import Response, ErrorResponse from djangorestframework.tests.models import CustomUser from djangorestframework.tests.testcases import TestModelsTestCase from djangorestframework.views import View +class TestModelRead(TestModelsTestCase): + """Tests on ReadModelMixin""" + + def setUp(self): + super(TestModelRead, self).setUp() + self.req = RequestFactory() + + def test_read(self): + Group.objects.create(name='other group') + group = Group.objects.create(name='my group') + + class GroupResource(ModelResource): + model = Group + + request = self.req.get('/groups') + mixin = ReadModelMixin() + mixin.resource = GroupResource + + response = mixin.get(request, group.id) + self.assertEquals(group.name, response.name) + + def test_read_404(self): + class GroupResource(ModelResource): + model = Group + + request = self.req.get('/groups') + mixin = ReadModelMixin() + mixin.resource = GroupResource + + with self.assertRaises(ErrorResponse): + response = mixin.get(request, 12345) + + class TestModelCreation(TestModelsTestCase): """Tests on CreateModelMixin""" |
