Permalink
Browse files

wrote a test for #670, toolbar shown in statically served HTML

  • Loading branch information...
1 parent a02b915 commit 431a61b2c023e1a1be8f46cf6988bf1d7eb6e7d9 Jonas Obrist committed Jan 25, 2011
Showing with 23 additions and 0 deletions.
  1. +6 −0 cms/middleware/toolbar.py
  2. +1 −0 cms/tests/__init__.py
  3. +16 −0 cms/tests/toolbar.py
@@ -14,6 +14,7 @@
from django.utils import simplejson
from django.utils.encoding import smart_unicode
from django.utils.translation import ugettext as _
+from django.views.static import serve
HTML_TYPES = ('text/html', 'application/xhtml+xml')
@@ -39,6 +40,8 @@ class ToolbarMiddleware(object):
"""
def show_toolbar(self, request, response):
+ if getattr(request, 'view_func', None) is serve:
+ return False
if request.is_ajax():
return False
if response.status_code != 200:
@@ -75,6 +78,9 @@ def process_request(self, request):
request.session['cms_edit'] = False
if "edit" in request.GET:
request.session['cms_edit'] = True
+
+ def process_view(self, request, view_func, view_args, view_kwargs):
+ request.view_func = view_func
def process_response(self, request, response):
if self.show_toolbar(request, response):
View
@@ -19,6 +19,7 @@
from cms.tests.mail import MailTestCase
from cms.tests.settings import SettingsTests
from cms.tests.forms import FormsTestCase
+from cms.tests.toolbar import ToolbarTests
from cms.tests.middleware import MiddlewareTestCase
try:
from cms.tests.javascript import JavascriptTestCase
View
@@ -0,0 +1,16 @@
+from cms.test.testcases import SettingsOverrideTestCase
+from cms.test.util.context_managers import UserLoginContext
+from django.conf import settings
+
+
+class ToolbarTests(SettingsOverrideTestCase):
+ settings_overrides = {'CMS_MODERATOR': False}
+
+ def test_01_static_html(self):
+ page = self.create_page(published=True)
+ superuser = self.get_superuser()
+ with UserLoginContext(self, superuser):
+ response = self.client.get('%sstatic.html?edit' % settings.MEDIA_URL)
+ self.assertTemplateNotUsed(response, 'cms/toolbar/toolbar.html')
+ response = self.client.get('%s?edit' % page.get_absolute_url())
+ self.assertTemplateUsed(response, 'cms/toolbar/toolbar.html')

0 comments on commit 431a61b

Please sign in to comment.