Skip to content

Commit cfbb5b3

Browse files
author
Ryan P Kilby
committed
Add 'testapp', test_backends module
1 parent 5cfe1f8 commit cfbb5b3

File tree

10 files changed

+89
-6
lines changed

10 files changed

+89
-6
lines changed

tests/settings.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,26 @@
99
'django.contrib.auth',
1010
'django.contrib.contenttypes',
1111
'rest_framework',
12-
'tests',
12+
'tests.testapp',
1313
)
1414

1515
SECRET_KEY = 'testsecretkey'
16+
17+
TEMPLATES = [
18+
{
19+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
20+
'DIRS': [],
21+
'APP_DIRS': True,
22+
'OPTIONS': {
23+
'context_processors': [
24+
'django.template.context_processors.debug',
25+
'django.template.context_processors.request',
26+
'django.contrib.auth.context_processors.auth',
27+
'django.contrib.messages.context_processors.messages',
28+
],
29+
},
30+
},
31+
]
32+
33+
34+
ROOT_URLCONF = 'tests.testapp.urls'

tests/test_backends.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
from django.test import TestCase, Client
3+
4+
5+
class BackendTest(TestCase):
6+
def setUp(self):
7+
self.client = Client()
8+
9+
def test_get(self):
10+
self.client.get('/notes')

tests/test_deprecations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import warnings
33
from django.test import TestCase
44

5-
from .filters import UserFilter
5+
from .testapp.filters import UserFilter
66

77

88
class FilterSetCacheDeprecationTests(TestCase):

tests/test_filterset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
from rest_framework_filters import filters
1111

12-
from .models import (
12+
from .testapp.models import (
1313
User, Note, Post, Cover, Page, A, B, C, Person, Tag, BlogPost,
1414
)
1515

16-
from .filters import (
16+
from .testapp.filters import (
1717
NoteFilterWithAll,
1818
UserFilter,
1919
# UserFilterWithAll,

tests/testapp/__init__.py

Whitespace-only changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class Meta:
144144
#############################################################
145145
class AFilter(FilterSet):
146146
title = filters.CharFilter(name='title')
147-
b = RelatedFilter('tests.filters.BFilter', name='b')
147+
b = RelatedFilter('tests.testapp.filters.BFilter', name='b')
148148

149149
class Meta:
150150
model = A
@@ -168,7 +168,7 @@ class Meta:
168168

169169
class PersonFilter(FilterSet):
170170
name = AllLookupsFilter(name='name')
171-
best_friend = RelatedFilter('tests.filters.PersonFilter', name='best_friend')
171+
best_friend = RelatedFilter('tests.testapp.filters.PersonFilter', name='best_friend')
172172

173173
class Meta:
174174
model = Person
File renamed without changes.

tests/testapp/serializers.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
from rest_framework import serializers
3+
4+
from .models import User, Note
5+
6+
7+
class UserSerializer(serializers.ModelSerializer):
8+
class Meta:
9+
model = User
10+
fields = ('pk', 'username', 'email', 'is_staff', )
11+
12+
13+
class NoteSerializer(serializers.ModelSerializer):
14+
class Meta:
15+
model = Note
16+
fields = ('pk', 'title', 'content', 'author', )

tests/testapp/urls.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
from django.conf.urls import include, url
3+
from django.contrib import admin
4+
from rest_framework import routers
5+
6+
from . import views
7+
8+
9+
router = routers.DefaultRouter()
10+
router.register(r'users', views.UserViewSet,)
11+
router.register(r'notes', views.NoteViewSet,)
12+
13+
14+
urlpatterns = [
15+
url(r'^admin/', include(admin.site.urls)),
16+
url(r'^', include(router.urls)),
17+
]

tests/testapp/views.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
from rest_framework import viewsets
3+
from rest_framework_filters import backends
4+
5+
from .models import User, Note
6+
from .serializers import UserSerializer, NoteSerializer
7+
from .filters import UserFilterWithAll, NoteFilterWithRelatedAll
8+
9+
10+
class UserViewSet(viewsets.ModelViewSet):
11+
queryset = User.objects.all()
12+
serializer_class = UserSerializer
13+
filter_backends = (backends.DjangoFilterBackend, )
14+
filter_class = UserFilterWithAll
15+
16+
17+
class NoteViewSet(viewsets.ModelViewSet):
18+
queryset = Note.objects.all()
19+
serializer_class = NoteSerializer
20+
filter_backends = (backends.DjangoFilterBackend, )
21+
filter_class = NoteFilterWithRelatedAll

0 commit comments

Comments
 (0)