Skip to content

Commit

Permalink
additianal testcases added
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Lauber committed Jan 15, 2010
1 parent 03a78d9 commit ffcd359
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
3 changes: 2 additions & 1 deletion cms/tests/base.py
Expand Up @@ -33,6 +33,7 @@ def _post_teardown(self):

def login_user(self, user):
logged_in = self.client.login(username=user.username, password=user.username)
self.user = user
self.assertEqual(logged_in, True)


Expand Down Expand Up @@ -183,6 +184,6 @@ def get_request(self, path="/"):
}
request = WSGIRequest(environ)
request.session = self.client.session
request.user = User()
request.user = self.user
request.LANGUAGE_CODE = settings.LANGUAGES[0][0]
return request
40 changes: 38 additions & 2 deletions cms/tests/menu.py
Expand Up @@ -6,7 +6,8 @@
from cms.tests.base import CMSTestCase, URL_CMS_PAGE, URL_CMS_PAGE_ADD
from cms.models import Page, Title
from cms.menu import CMSMenu
from menus.templatetags.menu_tags import show_menu, show_sub_menu
from menus.templatetags.menu_tags import show_menu, show_sub_menu,\
show_breadcrumb, language_chooser, page_language_url, show_menu_below_id


class MenusTestCase(CMSTestCase):
Expand All @@ -16,7 +17,6 @@ def setUp(self):
u = User(username="test", is_staff = True, is_active = True, is_superuser = True)
u.set_password("test")
u.save()

self.login_user(u)

def create_some_nodes(self):
Expand Down Expand Up @@ -125,3 +125,39 @@ def test_09_show_submenu(self):
self.assertEqual(len(nodes), 1)
self.assertEqual(len(nodes[0].children), 0)

def test_10_show_breadcrumb(self):
self.create_some_nodes()
context = self.get_context(path=self.page3.get_absolute_url())
nodes = show_breadcrumb(context)['ancestors']
self.assertEqual(len(nodes), 3)
nodes = show_breadcrumb(context, 1)['ancestors']
self.assertEqual(len(nodes), 2)
context = self.get_context()
nodes = show_breadcrumb(context)['ancestors']
self.assertEqual(len(nodes), 1)
nodes = show_breadcrumb(context, 1)['ancestors']
self.assertEqual(len(nodes), 0)

def test_11_language_chooser(self):
self.create_some_nodes()
context = self.get_context(path=self.page3.get_absolute_url())
new_context = language_chooser(context)
self.assertEqual(len(new_context['languages']), len(settings.LANGUAGES))
self.assertEqual(new_context['current_language'], settings.LANGUAGES[0][0])

def test_12_page_language_url(self):
self.create_some_nodes()
context = self.get_context(path=self.page3.get_absolute_url())
url = page_language_url(context, settings.LANGUAGES[0][0])['content']
self.assertEqual( url, "/%s%s" % (settings.LANGUAGES[0][0], self.page3.get_absolute_url()))

def test_13_show_menu_below_id(self):
self.create_some_nodes()
self.page2.reverse_id = "hello"
self.page2.save()
context = self.get_context(path=self.page5.get_absolute_url())
nodes = show_menu_below_id(context, "hello")
self.assertEqual(len(nodes), 1)
self.assertEqual(nodes[0].get_absolute_url(), self.node3.get_absolute_url())


2 changes: 1 addition & 1 deletion cms/views.py
Expand Up @@ -107,7 +107,7 @@ def details(request, page_id=None, slug=None, template_name=settings.CMS_TEMPLAT
return "cms/new.html", locals()
raise Http404("CMS: No page found for site %s" % unicode(site.name))

if current_page:
if current_page:
has_change_permissions = current_page.has_change_permission(request)
request._current_page_cache = current_page

Expand Down
3 changes: 2 additions & 1 deletion menus/templatetags/menu_tags.py
Expand Up @@ -144,7 +144,8 @@ def show_breadcrumb(context, start_level=0, template="menu/breadcrumb.html"):
while n:
ancestors.append(n)
n = n.parent
ancestors.append(home)
if not ancestors or (ancestors and ancestors[-1] != home):
ancestors.append(home)
ancestors.reverse()
if len(ancestors) >= start_level:
ancestors = ancestors[start_level:]
Expand Down

0 comments on commit ffcd359

Please sign in to comment.