Python rest_framework.renderers.BrowsableAPIRenderer() Examples
The following are 6
code examples of rest_framework.renderers.BrowsableAPIRenderer().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
rest_framework.renderers
, or try the search function
.
Example #1
Source File: test_api_view_serializer_class_getter.py From django-rest-registration with MIT License | 6 votes |
def test_browsable_renderer_put_render(input_put_view, decorator): """ Test, that PUT method works with BrowsableAPIRenderer This was not working in the past, because of `_get_serializer` didn't allow `instance parameter. """ data = {'blah': 'blah'} method = 'PUT' request = rest_request.Request(APIRequestFactory().get('blah')) output_view = decorator(input_put_view) wrapper_cls = _get_view_class(output_view) test_view_instance = wrapper_cls() renderer = renderers.BrowsableAPIRenderer() renderer.accepted_media_type = None renderer.renderer_context = {} response = renderer.get_raw_data_form( data, test_view_instance, method, request, ) assert response.data == {}
Example #2
Source File: test_cache.py From course-discovery with GNU Affero General Public License v3.0 | 6 votes |
def test_should_not_cache_for_non_json_responses(self): """ Verify that the decorator does not cache if the response is not json """ def key_func(**kwargs): # pylint: disable=unused-argument return 'non_json_cache_key' class TestView(views.APIView): permission_classes = [permissions.AllowAny] renderer_classes = [BrowsableAPIRenderer] # Non-json responses @compressed_cache_response(key_func=key_func) def get(self, request, *args, **kwargs): return Response('test response') view_instance = TestView() view_instance.headers = {} # pylint: disable=attribute-defined-outside-init view_instance.dispatch(request=self.request) # Verify nothing was cached self.assertEqual(cache.get('non_json_cache_key'), None)
Example #3
Source File: viewsets.py From dynamic-rest with MIT License | 5 votes |
def get_renderers(self): """Optionally block Browsable API rendering. """ renderers = super(WithDynamicViewSetMixin, self).get_renderers() if settings.ENABLE_BROWSABLE_API is False: return [ r for r in renderers if not isinstance(r, BrowsableAPIRenderer) ] else: return renderers
Example #4
Source File: data.py From kpi with GNU Affero General Public License v3.0 | 5 votes |
def get_queryset(self): # This method is needed when pagination is activated and renderer is # `BrowsableAPIRenderer`. Because data comes from Mongo, `list()` and # `retrieve()` don't need Django Queryset, we only need return `None`. return None
Example #5
Source File: views.py From logtacts with MIT License | 5 votes |
def get_renderers(self): renderers = [api_renderers.JSONRenderer] if self.request.user.is_staff: renderers += [api_renderers.BrowsableAPIRenderer] return [renderer() for renderer in renderers]
Example #6
Source File: views.py From Dailyfresh-B2C with Apache License 2.0 | 5 votes |
def __init__(self, *args, **kwargs): super(SchemaView, self).__init__(*args, **kwargs) if self.renderer_classes is None: if renderers.BrowsableAPIRenderer in api_settings.DEFAULT_RENDERER_CLASSES: self.renderer_classes = [ renderers.CoreJSONRenderer, renderers.BrowsableAPIRenderer, ] else: self.renderer_classes = [renderers.CoreJSONRenderer]