def test_modelviewset_list_action_breadcrumbs(self):
     url = '/resources/list_action/'
     assert get_breadcrumbs(url) == [
         ('Root', '/'),
         ('Resource List', '/resources/'),
         ('List action', '/resources/list_action/'),
     ]
Beispiel #2
0
 def test_resource_instance_customname_breadcrumbs(self):
     url = '/resource/customname'
     assert get_breadcrumbs(url) == [
         ('Root', '/'),
         ('Resource Root', '/resource/'),
         ('Foo', '/resource/customname')
     ]
 def test_resource_instance_breadcrumbs(self):
     url = '/resource/123'
     assert get_breadcrumbs(url) == [
         ('Root', '/'),
         ('Resource Root', '/resource/'),
         ('Resource Instance', '/resource/123')
     ]
Beispiel #4
0
 def test_modelviewset_resource_instance_breadcrumbs(self):
     url = '/resources/1/'
     assert get_breadcrumbs(url) == [
         ('Root', '/'),
         ('Resource List', '/resources/'),
         ('Resource Instance', '/resources/1/')
     ]
 def test_resource_instance_customname_breadcrumbs(self):
     url = '/resource/customname'
     assert get_breadcrumbs(url) == [
         ('Root', '/'),
         ('Resource Root', '/resource/'),
         ('Foo', '/resource/customname')
     ]
Beispiel #6
0
 def test_modelviewset_list_action_breadcrumbs(self):
     url = '/resources/list_action/'
     assert get_breadcrumbs(url) == [
         ('Root', '/'),
         ('Resource List', '/resources/'),
         ('List action', '/resources/list_action/'),
     ]
 def test_modelviewset_resource_instance_breadcrumbs(self):
     url = '/resources/1/'
     assert get_breadcrumbs(url) == [
         ('Root', '/'),
         ('Resource List', '/resources/'),
         ('Resource Instance', '/resources/1/')
     ]
Beispiel #8
0
 def test_resource_instance_breadcrumbs(self):
     url = '/resource/123'
     assert get_breadcrumbs(url) == [
         ('Root', '/'),
         ('Resource Root', '/resource/'),
         ('Resource Instance', '/resource/123')
     ]
 def test_nested_resource_instance_breadcrumbs(self):
     url = '/resource/123/abc'
     self.assertEqual(get_breadcrumbs(url), [('Root', '/'),
                                         ('Resource Root', '/resource/'),
                                         ('Resource Instance', '/resource/123'),
                                         ('Nested Resource Root', '/resource/123/'),
                                         ('Nested Resource Instance', '/resource/123/abc')])
 def test_nested_resource_instance_breadcrumbs(self):
     url = '/resource/123/abc'
     self.assertEqual(get_breadcrumbs(url),
                      [('Root', '/'), ('Resource Root', '/resource/'),
                       ('Resource Instance', '/resource/123'),
                       ('Nested Resource Root', '/resource/123/'),
                       ('Nested Resource Instance', '/resource/123/abc')])
Beispiel #11
0
 def test_modelviewset_detail_action_breadcrumbs(self):
     url = '/resources/1/detail_action/'
     assert get_breadcrumbs(url) == [
         ('Root', '/'),
         ('Resource List', '/resources/'),
         ('Resource Instance', '/resources/1/'),
         ('Detail action', '/resources/1/detail_action/'),
     ]
Beispiel #12
0
 def test_modelviewset_action_name_kwarg(self):
     url = '/resources/1/named_action/'
     assert get_breadcrumbs(url) == [
         ('Root', '/'),
         ('Resource List', '/resources/'),
         ('Resource Instance', '/resources/1/'),
         ('Custom Name', '/resources/1/named_action/'),
     ]
Beispiel #13
0
 def test_modelviewset_action_suffix_kwarg(self):
     url = '/resources/1/suffixed_action/'
     assert get_breadcrumbs(url) == [
         ('Root', '/'),
         ('Resource List', '/resources/'),
         ('Resource Instance', '/resources/1/'),
         ('Resource Custom Suffix', '/resources/1/suffixed_action/'),
     ]
 def test_modelviewset_action_suffix_kwarg(self):
     url = '/resources/1/suffixed_action/'
     assert get_breadcrumbs(url) == [
         ('Root', '/'),
         ('Resource List', '/resources/'),
         ('Resource Instance', '/resources/1/'),
         ('Resource Custom Suffix', '/resources/1/suffixed_action/'),
     ]
 def test_modelviewset_action_name_kwarg(self):
     url = '/resources/1/named_action/'
     assert get_breadcrumbs(url) == [
         ('Root', '/'),
         ('Resource List', '/resources/'),
         ('Resource Instance', '/resources/1/'),
         ('Custom Name', '/resources/1/named_action/'),
     ]
 def test_modelviewset_detail_action_breadcrumbs(self):
     url = '/resources/1/detail_action/'
     assert get_breadcrumbs(url) == [
         ('Root', '/'),
         ('Resource List', '/resources/'),
         ('Resource Instance', '/resources/1/'),
         ('Detail action', '/resources/1/detail_action/'),
     ]
Beispiel #17
0
 def test_resource_root_breadcrumbs(self):
     url = '/resource/'
     self.assertEqual(
         get_breadcrumbs(url),
         [
             ('Root', '/'),
             ('Resource Root', '/resource/')
         ]
     )
 def test_resource_root_breadcrumbs(self):
     url = '/resource/'
     self.assertEqual(
         get_breadcrumbs(url),
         [
             ('Root', '/'),
             ('Resource Root', '/resource/')
         ]
     )
    def render(self, data, accepted_media_type=None, renderer_context=None):
        """
        Renders *obj* using the :attr:`template` set on the class.

        The context used in the template contains all the information
        needed to self-document the response to this request.
        """
        accepted_media_type = accepted_media_type or ''
        renderer_context = renderer_context or {}

        view = renderer_context['view']
        request = renderer_context['request']
        response = renderer_context['response']

        renderer = self.get_default_renderer(view)
        content = self.get_content(renderer, data, accepted_media_type, renderer_context)

        put_form = self.get_form(view, 'PUT', request)
        post_form = self.get_form(view, 'POST', request)
        delete_form = self.get_form(view, 'DELETE', request)
        options_form = self.get_form(view, 'OPTIONS', request)

        name = self.get_name(view)
        description = self.get_description(view)
        breadcrumb_list = get_breadcrumbs(request.path)

        template = loader.get_template(self.template)
        context = RequestContext(request, {
            'content': content,
            'view': view,
            'request': request,
            'response': response,
            'description': description,
            'name': name,
            'version': VERSION,
            'breadcrumblist': breadcrumb_list,
            'allowed_methods': view.allowed_methods,
            'available_formats': [renderer.format for renderer in view.renderer_classes],
            'put_form': put_form,
            'post_form': post_form,
            'delete_form': delete_form,
            'options_form': options_form,
            'api_settings': api_settings
        })

        ret = template.render(context)

        # Munge DELETE Response code to allow us to return content
        # (Do this *after* we've rendered the template so that we include
        # the normal deletion response code in the output)
        if response.status_code == 204:
            response.status_code = 200

        return ret
 def test_nested_resource_breadcrumbs(self):
     url = "/resource/123/"
     self.assertEqual(
         get_breadcrumbs(url),
         [
             ("Root", "/"),
             ("Resource Root", "/resource/"),
             ("Resource Instance", "/resource/123"),
             ("Nested Resource Root", "/resource/123/"),
         ],
     )
 def test_broken_url_breadcrumbs_handled_gracefully(self):
     url = '/foobar'
     self.assertEqual(get_breadcrumbs(url), [('Root', '/')])
Beispiel #22
0
    def render(self, data, accepted_media_type=None, renderer_context=None):
        """
        Renders *obj* using the :attr:`template` set on the class.

        The context used in the template contains all the information
        needed to self-document the response to this request.
        """
        accepted_media_type = accepted_media_type or ''
        renderer_context = renderer_context or {}

        view = renderer_context['view']
        request = renderer_context['request']
        response = renderer_context['response']

        renderer = self.get_default_renderer(view)
        content = self.get_content(renderer, data, accepted_media_type,
                                   renderer_context)

        put_form = self.get_form(view, 'PUT', request)
        post_form = self.get_form(view, 'POST', request)
        delete_form = self.get_form(view, 'DELETE', request)
        options_form = self.get_form(view, 'OPTIONS', request)

        name = self.get_name(view)
        description = self.get_description(view)
        breadcrumb_list = get_breadcrumbs(request.path)

        template = loader.get_template(self.template)
        context = RequestContext(
            request, {
                'content':
                content,
                'view':
                view,
                'request':
                request,
                'response':
                response,
                'description':
                description,
                'name':
                name,
                'version':
                VERSION,
                'breadcrumblist':
                breadcrumb_list,
                'allowed_methods':
                view.allowed_methods,
                'available_formats':
                [renderer.format for renderer in view.renderer_classes],
                'put_form':
                put_form,
                'post_form':
                post_form,
                'delete_form':
                delete_form,
                'options_form':
                options_form,
                'api_settings':
                api_settings
            })

        ret = template.render(context)

        # Munge DELETE Response code to allow us to return content
        # (Do this *after* we've rendered the template so that we include
        # the normal deletion response code in the output)
        if response.status_code == status.HTTP_204_NO_CONTENT:
            response.status_code = status.HTTP_200_OK

        return ret
 def test_root_breadcrumbs(self):
     url = '/'
     self.assertEqual(get_breadcrumbs(url), [('Root', '/')])
    def render(self, data, accepted_media_type=None, renderer_context=None):
        """
        Renders *obj* using the :attr:`template` set on the class.

        The context used in the template contains all the information
        needed to self-document the response to this request.
        """
        accepted_media_type = accepted_media_type or ""
        renderer_context = renderer_context or {}

        view = renderer_context["view"]
        request = renderer_context["request"]
        response = renderer_context["response"]
        media_types = [parser.media_type for parser in view.parser_classes]

        renderer = self.get_default_renderer(view)
        content = self.get_content(renderer, data, accepted_media_type, renderer_context)

        put_form = self.get_form(view, "PUT", request)
        post_form = self.get_form(view, "POST", request)
        patch_form = self.get_form(view, "PATCH", request)
        delete_form = self.get_form(view, "DELETE", request)
        options_form = self.get_form(view, "OPTIONS", request)

        raw_data_put_form = self.get_raw_data_form(view, "PUT", request, media_types)
        raw_data_post_form = self.get_raw_data_form(view, "POST", request, media_types)
        raw_data_patch_form = self.get_raw_data_form(view, "PATCH", request, media_types)
        raw_data_put_or_patch_form = raw_data_put_form or raw_data_patch_form

        name = self.get_name(view)
        description = self.get_description(view)
        breadcrumb_list = get_breadcrumbs(request.path)

        template = loader.get_template(self.template)
        context = RequestContext(
            request,
            {
                "content": content,
                "view": view,
                "request": request,
                "response": response,
                "description": description,
                "name": name,
                "version": VERSION,
                "breadcrumblist": breadcrumb_list,
                "allowed_methods": view.allowed_methods,
                "available_formats": [renderer.format for renderer in view.renderer_classes],
                "put_form": put_form,
                "post_form": post_form,
                "patch_form": patch_form,
                "delete_form": delete_form,
                "options_form": options_form,
                "raw_data_put_form": raw_data_put_form,
                "raw_data_post_form": raw_data_post_form,
                "raw_data_patch_form": raw_data_patch_form,
                "raw_data_put_or_patch_form": raw_data_put_or_patch_form,
                "api_settings": api_settings,
            },
        )

        ret = template.render(context)

        # Munge DELETE Response code to allow us to return content
        # (Do this *after* we've rendered the template so that we include
        # the normal deletion response code in the output)
        if response.status_code == status.HTTP_204_NO_CONTENT:
            response.status_code = status.HTTP_200_OK

        return ret
 def test_root_breadcrumbs(self):
     url = "/"
     self.assertEqual(get_breadcrumbs(url), [("Root", "/")])
Beispiel #26
0
 def breadcrumbs(self):
     url = self.object.get_full_url()
     return get_breadcrumbs(url, self.request)
 def test_root_breadcrumbs(self):
     url = '/'
     self.assertEqual(
         get_breadcrumbs(url),
         [('Root', '/')]
     )
Beispiel #28
0
 def test_resource_root_breadcrumbs(self):
     url = '/resource/'
     assert get_breadcrumbs(url) == [
         ('Root', '/'), ('Resource Root', '/resource/')
     ]
Beispiel #29
0
 def test_root_breadcrumbs(self):
     url = '/'
     assert get_breadcrumbs(url) == [('Root', '/')]
 def test_broken_url_breadcrumbs_handled_gracefully(self):
     url = "/foobar"
     self.assertEqual(get_breadcrumbs(url), [("Root", "/")])
 def test_broken_url_breadcrumbs_handled_gracefully(self):
     url = '/foobar'
     assert get_breadcrumbs(url) == [('Root', '/')]
 def test_root_breadcrumbs(self):
     url = '/'
     assert get_breadcrumbs(url) == [('Root', '/')]
 def test_resource_root_breadcrumbs(self):
     url = '/resource/'
     assert get_breadcrumbs(url) == [
         ('Root', '/'), ('Resource Root', '/resource/')
     ]
 def test_broken_url_breadcrumbs_handled_gracefully(self):
     url = '/foobar'
     self.assertEqual(
         get_breadcrumbs(url),
         [('Root', '/')]
     )
 def test_resource_root_breadcrumbs(self):
     url = "/resource/"
     self.assertEqual(get_breadcrumbs(url), [("Root", "/"), ("Resource Root", "/resource/")])
Beispiel #36
0
 def test_broken_url_breadcrumbs_handled_gracefully(self):
     url = '/foobar'
     assert get_breadcrumbs(url) == [('Root', '/')]
 def get_breadcrumbs(self, request):
     return get_breadcrumbs(request.path)
 def get_breadcrumbs(self, request):
     return get_breadcrumbs(request.path)
Beispiel #39
0
 def breadcrumbs(self):
     url = self.request.GET.get('url')
     return get_breadcrumbs(url, self.request)