2011-02-19 13:26:27 +03:00
|
|
|
from django.conf.urls.defaults import patterns, url
|
|
|
|
from django.test import TestCase
|
2011-04-29 17:32:56 +04:00
|
|
|
from djangorestframework.utils.breadcrumbs import get_breadcrumbs
|
2011-05-24 13:27:24 +04:00
|
|
|
from djangorestframework.views import View
|
2011-02-19 13:26:27 +03:00
|
|
|
|
2011-05-24 13:27:24 +04:00
|
|
|
class Root(View):
|
2011-02-19 13:26:27 +03:00
|
|
|
pass
|
|
|
|
|
2011-05-24 13:27:24 +04:00
|
|
|
class ResourceRoot(View):
|
2011-02-19 13:26:27 +03:00
|
|
|
pass
|
|
|
|
|
2011-05-24 13:27:24 +04:00
|
|
|
class ResourceInstance(View):
|
2011-02-19 13:26:27 +03:00
|
|
|
pass
|
|
|
|
|
2011-05-24 13:27:24 +04:00
|
|
|
class NestedResourceRoot(View):
|
2011-02-19 13:26:27 +03:00
|
|
|
pass
|
|
|
|
|
2011-05-24 13:27:24 +04:00
|
|
|
class NestedResourceInstance(View):
|
2011-02-19 13:26:27 +03:00
|
|
|
pass
|
|
|
|
|
|
|
|
urlpatterns = patterns('',
|
2011-05-24 13:40:35 +04:00
|
|
|
url(r'^$', Root.as_view()),
|
|
|
|
url(r'^resource/$', ResourceRoot.as_view()),
|
|
|
|
url(r'^resource/(?P<key>[0-9]+)$', ResourceInstance.as_view()),
|
|
|
|
url(r'^resource/(?P<key>[0-9]+)/$', NestedResourceRoot.as_view()),
|
|
|
|
url(r'^resource/(?P<key>[0-9]+)/(?P<other>[A-Za-z]+)$', NestedResourceInstance.as_view()),
|
2011-02-19 13:26:27 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class BreadcrumbTests(TestCase):
|
2011-04-28 22:54:30 +04:00
|
|
|
"""Tests the breadcrumb functionality used by the HTML renderer."""
|
2011-02-19 13:26:27 +03:00
|
|
|
|
|
|
|
urls = 'djangorestframework.tests.breadcrumbs'
|
|
|
|
|
|
|
|
def test_root_breadcrumbs(self):
|
|
|
|
url = '/'
|
|
|
|
self.assertEqual(get_breadcrumbs(url), [('Root', '/')])
|
|
|
|
|
|
|
|
def test_resource_root_breadcrumbs(self):
|
|
|
|
url = '/resource/'
|
|
|
|
self.assertEqual(get_breadcrumbs(url), [('Root', '/'),
|
|
|
|
('Resource Root', '/resource/')])
|
|
|
|
|
|
|
|
def test_resource_instance_breadcrumbs(self):
|
|
|
|
url = '/resource/123'
|
|
|
|
self.assertEqual(get_breadcrumbs(url), [('Root', '/'),
|
|
|
|
('Resource Root', '/resource/'),
|
|
|
|
('Resource Instance', '/resource/123')])
|
|
|
|
|
|
|
|
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_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_broken_url_breadcrumbs_handled_gracefully(self):
|
|
|
|
url = '/foobar'
|
2011-12-29 17:31:12 +04:00
|
|
|
self.assertEqual(get_breadcrumbs(url), [('Root', '/')])
|