diff options
| author | Tom Christie | 2014-08-20 12:06:29 +0100 |
|---|---|---|
| committer | Tom Christie | 2014-08-20 12:06:29 +0100 |
| commit | 6ffc97c808f8026c063011e2d048604f3a6b70fa (patch) | |
| tree | 93586ece6e50ab5ef6282ffd104e886ed48d9180 /tests/test_breadcrumbs.py | |
| parent | f7b3e1e62b8e2c8bd1d1eb79a1cb0b3f4a0559a9 (diff) | |
| parent | 874d2be83c612fb5e04aa6a28901c2afe4bf9d3b (diff) | |
| download | django-rest-framework-6ffc97c808f8026c063011e2d048604f3a6b70fa.tar.bz2 | |
Merge pull request #1770 from tomchristie/2.4.0
2.4.0 Release.
Diffstat (limited to 'tests/test_breadcrumbs.py')
| -rw-r--r-- | tests/test_breadcrumbs.py | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/tests/test_breadcrumbs.py b/tests/test_breadcrumbs.py new file mode 100644 index 00000000..780fd5c4 --- /dev/null +++ b/tests/test_breadcrumbs.py @@ -0,0 +1,100 @@ +from __future__ import unicode_literals +from django.conf.urls import patterns, url +from django.test import TestCase +from rest_framework.utils.breadcrumbs import get_breadcrumbs +from rest_framework.views import APIView + + +class Root(APIView): + pass + + +class ResourceRoot(APIView): + pass + + +class ResourceInstance(APIView): + pass + + +class NestedResourceRoot(APIView): + pass + + +class NestedResourceInstance(APIView): + pass + +urlpatterns = patterns( + '', + 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()), +) + + +class BreadcrumbTests(TestCase): + """Tests the breadcrumb functionality used by the HTML renderer.""" + + urls = 'tests.test_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' + self.assertEqual( + get_breadcrumbs(url), + [('Root', '/')] + ) |
