Skip to content

Commit

Permalink
better test
Browse files Browse the repository at this point in the history
  • Loading branch information
fivethreeo committed Jan 25, 2011
1 parent d5d075c commit 8bf3fdc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 3 additions & 1 deletion cms/appresolver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
from cms.apphook_pool import apphook_pool
from cms.exceptions import NoHomeFound
from cms.utils.moderator import get_page_queryset

from django.conf import settings
from django.conf.urls.defaults import patterns
from django.contrib.sites.models import Site
Expand All @@ -12,13 +14,13 @@
APP_RESOLVERS = []

def clear_app_resolvers():
global APP_RESOLVERS
APP_RESOLVERS = []

def applications_page_check(request, current_page=None, path=None):
"""Tries to find if given path was resolved over application.
Applications have higher priority than other cms pages.
"""
from cms.utils.moderator import get_page_queryset
if current_page:
return current_page
if path is None:
Expand Down
14 changes: 8 additions & 6 deletions cms/tests/apphooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,35 +98,37 @@ def test_04_get_page_for_apphook(self):
child_child_page.title_set.all().update(application_urls='SampleApp')

child_child_page.publish()
# publisher_public is set to draft on publish, issue with onetoone reverse
child_child_page = self.reload(child_child_page)

en_title = child_child_page.get_title('en')
en_title = child_child_page.publisher_public.get_title_obj('en')

path = reverse('en:sample-settings')

request = self.get_request(path)
request.LANGUAGE_CODE = 'en'

attached_to_page = applications_page_check(request, path=path[1:]) # strip leading slash
self.assertEquals(attached_to_page.get_title('en'), en_title)
self.assertEquals(attached_to_page.pk, en_title.page.pk)

response = self.client.get(path)
self.assertEquals(response.status_code, 200)

self.assertTemplateUsed(response, 'sampleapp/home.html')
self.assertContains(response, en_title)
self.assertContains(response, en_title.title)

de_title = child_child_page.get_title('de')
de_title = child_child_page.publisher_public.get_title_obj('de')
path = reverse('de:sample-settings')

request = self.get_request(path)
request.LANGUAGE_CODE = 'de'

attached_to_page = applications_page_check(request, path=path[4:]) # strip leading slash and language prefix
self.assertEquals(attached_to_page.get_title('de'), de_title)
self.assertEquals(attached_to_page.pk, de_title.page.pk)

response = self.client.get(path)
self.assertEquals(response.status_code, 200)
self.assertTemplateUsed(response, 'sampleapp/home.html')
self.assertContains(response, de_title)
self.assertContains(response, de_title.title)

apphook_pool.clear()

0 comments on commit 8bf3fdc

Please sign in to comment.