aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/tests
diff options
context:
space:
mode:
Diffstat (limited to 'rest_framework/tests')
-rw-r--r--rest_framework/tests/__init__.py5
-rw-r--r--rest_framework/tests/generics.py30
-rw-r--r--rest_framework/tests/models.py62
3 files changed, 69 insertions, 28 deletions
diff --git a/rest_framework/tests/__init__.py b/rest_framework/tests/__init__.py
index 85ee18b6..adeaf6da 100644
--- a/rest_framework/tests/__init__.py
+++ b/rest_framework/tests/__init__.py
@@ -1,4 +1,7 @@
-"""Force import of all modules in this package in order to get the standard test runner to pick up the tests. Yowzers."""
+"""
+Force import of all modules in this package in order to get the standard test
+runner to pick up the tests. Yowzers.
+"""
import os
modules = [filename.rsplit('.', 1)[0]
diff --git a/rest_framework/tests/generics.py b/rest_framework/tests/generics.py
new file mode 100644
index 00000000..dc9c6226
--- /dev/null
+++ b/rest_framework/tests/generics.py
@@ -0,0 +1,30 @@
+from django.test import TestCase
+from django.test.client import RequestFactory
+from rest_framework import generics, status
+from rest_framework.tests.models import BasicModel
+
+
+factory = RequestFactory()
+
+
+class RootView(generics.RootAPIView):
+ model = BasicModel
+
+
+class TestListView(TestCase):
+ def setUp(self):
+ items = ['foo', 'bar', 'baz']
+ for item in items:
+ BasicModel(text=item).save()
+ self.objects = BasicModel.objects
+ self.data = [
+ {'id': obj.id, 'text': obj.text}
+ for obj in self.objects.all()
+ ]
+
+ def test_get_root_view(self):
+ view = RootView.as_view()
+ request = factory.get('/')
+ response = view(request).render()
+ self.assertEquals(response.status_code, status.HTTP_200_OK)
+ self.assertEquals(response.data, self.data)
diff --git a/rest_framework/tests/models.py b/rest_framework/tests/models.py
index 4cae68b6..7429d863 100644
--- a/rest_framework/tests/models.py
+++ b/rest_framework/tests/models.py
@@ -1,28 +1,36 @@
from django.db import models
-from django.contrib.auth.models import Group
-
-class CustomUser(models.Model):
- """
- A custom user model, which uses a 'through' table for the foreign key
- """
- username = models.CharField(max_length=255, unique=True)
- groups = models.ManyToManyField(
- to=Group, blank=True, null=True, through='UserGroupMap'
- )
-
- @models.permalink
- def get_absolute_url(self):
- return ('custom_user', (), {
- 'pk': self.id
- })
-
-
-class UserGroupMap(models.Model):
- user = models.ForeignKey(to=CustomUser)
- group = models.ForeignKey(to=Group)
-
- @models.permalink
- def get_absolute_url(self):
- return ('user_group_map', (), {
- 'pk': self.id
- })
+# from django.contrib.auth.models import Group
+
+
+# class CustomUser(models.Model):
+# """
+# A custom user model, which uses a 'through' table for the foreign key
+# """
+# username = models.CharField(max_length=255, unique=True)
+# groups = models.ManyToManyField(
+# to=Group, blank=True, null=True, through='UserGroupMap'
+# )
+
+# @models.permalink
+# def get_absolute_url(self):
+# return ('custom_user', (), {
+# 'pk': self.id
+# })
+
+
+# class UserGroupMap(models.Model):
+# user = models.ForeignKey(to=CustomUser)
+# group = models.ForeignKey(to=Group)
+
+# @models.permalink
+# def get_absolute_url(self):
+# return ('user_group_map', (), {
+# 'pk': self.id
+# })
+
+
+class BasicModel(models.Model):
+ text = models.CharField(max_length=100)
+
+ class Meta:
+ app_label = 'rest_framework'