Python rest_framework.generics.GenericAPIView() Examples
The following are 2
code examples of rest_framework.generics.GenericAPIView().
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.generics
, or try the search function
.
Example #1
Source File: test_utils.py From django-rest-framework-json-api with BSD 2-Clause "Simplified" License | 5 votes |
def test_get_resource_name(): view = APIView() context = {'view': view} with override_settings(JSON_API_FORMAT_TYPES=None): assert 'APIViews' == utils.get_resource_name(context), 'not formatted' context = {'view': view} with override_settings(JSON_API_FORMAT_TYPES='dasherize'): assert 'api-views' == utils.get_resource_name(context), 'derived from view' view.model = get_user_model() assert 'users' == utils.get_resource_name(context), 'derived from view model' view.resource_name = 'custom' assert 'custom' == utils.get_resource_name(context), 'manually set on view' view.response = Response(status=403) assert 'errors' == utils.get_resource_name(context), 'handles 4xx error' view.response = Response(status=500) assert 'errors' == utils.get_resource_name(context), 'handles 500 error' view = GenericAPIView() view.serializer_class = ResourceSerializer context = {'view': view} assert 'users' == utils.get_resource_name(context), 'derived from serializer' view.serializer_class.Meta.resource_name = 'rcustom' assert 'rcustom' == utils.get_resource_name(context), 'set on serializer' view = GenericAPIView() view.serializer_class = NonModelResourceSerializer context = {'view': view} assert 'users' == utils.get_resource_name(context), 'derived from non-model serializer'
Example #2
Source File: generics.py From django-rest-framework-mongoengine with MIT License | 5 votes |
def get_queryset(self): "" queryset = super(GenericAPIView, self).get_queryset() if isinstance(queryset, BaseQuerySet): queryset = queryset.all() return queryset