class BrowsableAPIRendererTests(URLPatternsTestCase): class ExampleViewSet(ViewSet): def list(self, request): return Response() @action(detail=False, name="Extra list action") def list_action(self, request): raise NotImplementedError router = SimpleRouter() router.register('examples', ExampleViewSet, base_name='example') urlpatterns = [url(r'^api/', include(router.urls))] def setUp(self): self.renderer = BrowsableAPIRenderer() def test_get_description_returns_empty_string_for_401_and_403_statuses(self): assert self.renderer.get_description({}, status_code=401) == '' assert self.renderer.get_description({}, status_code=403) == '' def test_get_filter_form_returns_none_if_data_is_not_list_instance(self): class DummyView(object): get_queryset = None filter_backends = None result = self.renderer.get_filter_form(data='not list', view=DummyView(), request={}) assert result is None def test_extra_actions_dropdown(self): resp = self.client.get('/api/examples/', HTTP_ACCEPT='text/html') assert 'id="extra-actions-menu"' in resp.content.decode('utf-8') assert '/api/examples/list_action/' in resp.content.decode('utf-8') assert '>Extra list action<' in resp.content.decode('utf-8')
class BrowsableAPIRendererTests(URLPatternsTestCase): class ExampleViewSet(ViewSet): def list(self, request): return Response() @action(detail=False, name="Extra list action") def list_action(self, request): raise NotImplementedError router = SimpleRouter() router.register('examples', ExampleViewSet, basename='example') urlpatterns = [url(r'^api/', include(router.urls))] def setUp(self): self.renderer = BrowsableAPIRenderer() def test_get_description_returns_empty_string_for_401_and_403_statuses(self): assert self.renderer.get_description({}, status_code=401) == '' assert self.renderer.get_description({}, status_code=403) == '' def test_get_filter_form_returns_none_if_data_is_not_list_instance(self): class DummyView: get_queryset = None filter_backends = None result = self.renderer.get_filter_form(data='not list', view=DummyView(), request={}) assert result is None def test_extra_actions_dropdown(self): resp = self.client.get('/api/examples/', HTTP_ACCEPT='text/html') assert 'id="extra-actions-menu"' in resp.content.decode('utf-8') assert '/api/examples/list_action/' in resp.content.decode('utf-8') assert '>Extra list action<' in resp.content.decode('utf-8')
class BrowsableAPIRendererTests(TestCase): def setUp(self): self.renderer = BrowsableAPIRenderer() def test_get_description_returns_empty_string_for_401_and_403_statuses(self): assert self.renderer.get_description({}, status_code=401) == '' assert self.renderer.get_description({}, status_code=403) == '' def test_get_filter_form_returns_none_if_data_is_not_list_instance(self): class DummyView(object): get_queryset = None filter_backends = None result = self.renderer.get_filter_form(data='not list', view=DummyView(), request={}) assert result is None
def setUp(self): self.renderer = BrowsableAPIRenderer()
def test_keeps_url_fields_if_accepted_renderer_is_browsable_api(self): drf_request = Request(HttpRequest()) drf_request.accepted_renderer = BrowsableAPIRenderer() serializer = _SerializerWithUrlFields(context={'request': drf_request}) self.assertEqual(3, len(serializer.fields))