File tree Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+ from __future__ import unicode_literals
2+ from django .conf .urls import patterns
3+
4+ # from tests.test_generics import RootView
5+
6+ from rest_framework .pagination import PageNumberPagination
7+ from rest_framework .serializers import ModelSerializer
8+ from rest_framework .viewsets import GenericViewSet
9+ from rest_framework .mixins import ListModelMixin
10+ from rest_framework import renderers
11+ from tests .models import BasicModel
12+
13+
14+ class BasicSerializer (ModelSerializer ):
15+ class Meta :
16+ model = BasicModel
17+
18+
19+ class Paginator (PageNumberPagination ):
20+ page_size = 10
21+
22+
23+ class BasicViewSet (GenericViewSet , ListModelMixin ):
24+ queryset = BasicModel .objects .all ()
25+ serializer_class = BasicSerializer
26+ renderer_classes = (renderers .BrowsableAPIRenderer , renderers .JSONRenderer )
27+ paginator = None
28+
29+
30+ urlpatterns = patterns (
31+ '' ,
32+ (r'^basic/' , BasicViewSet .as_view ({'get' : 'list' })),
33+ )
Original file line number Diff line number Diff line change 33from django .test import TestCase
44
55from rest_framework .test import APIClient
6+ from tests .models import BasicModel
67
78
89class DropdownWithAuthTests (TestCase ):
@@ -63,3 +64,27 @@ def test_dropdown_not_shown_when_logged_in(self):
6364 def test_dropdown_not_shown_when_logged_out (self ):
6465 response = self .client .get ('/' )
6566 self .assertNotContains (response , '<li class="dropdown">' )
67+
68+
69+ class PaginatorRenderingTests (TestCase ):
70+ """Tests correct dropdown behaviour with Auth views NOT enabled."""
71+
72+ urls = 'tests.browsable_api.example_modelviewset_urls'
73+
74+ def setUp (self ):
75+ items = ['foo' , 'bar' , 'baz' ]
76+ for item in items :
77+ BasicModel (text = item ).save ()
78+ self .objects = BasicModel .objects
79+ self .data = [
80+ {'id' : obj .id , 'text' : obj .text }
81+ for obj in self .objects .all ()
82+ ]
83+ self .client = APIClient (enforce_csrf_checks = True )
84+
85+ def tearDown (self ):
86+ self .client .logout ()
87+
88+ def test_none_paginator_allows_page_to_render (self ):
89+ response = self .client .get ('/basic/' )
90+ self .assertEqual (response .status_code , 200 )
You can’t perform that action at this time.
0 commit comments