Skip to content

Commit

Permalink
- Show a message for empty file into Page Template (fixes #357)
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed Nov 22, 2018
1 parent 3321d0d commit 63edf77
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ Fixes

- added note about the ``app`` toplevel object in the debugger

- Show a message instead of excption for empty file into Page Template
(`#357 <https://github.com/zopefoundation/Zope/issues/357>`_)


4.0b7 (2018-10-30)
------------------
Expand Down
4 changes: 3 additions & 1 deletion src/Products/PageTemplates/ZopePageTemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ def pt_upload(self, REQUEST, file='', encoding='utf-8'):
raise ResourceLockedError("File is locked.")

if not file:
raise ValueError('File not specified')
return self.pt_editForm(manage_tabs_message='No file specified',
manage_tabs_type='warning')

if hasattr(file, 'read'):
text = file.read()
filename = file.filename
Expand Down
33 changes: 32 additions & 1 deletion src/Products/PageTemplates/tests/testZopePageTemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Ensures that adding a page template works correctly.
"""

import codecs
import unittest
import transaction

Expand All @@ -13,7 +14,10 @@
from zope.publisher.http import HTTPCharsets

from Testing.makerequest import makerequest
from Testing.ZopeTestCase import ZopeTestCase, installProduct
from Testing.testbrowser import Browser
from Testing.ZopeTestCase import FunctionalTestCase
from Testing.ZopeTestCase import installProduct
from Testing.ZopeTestCase import ZopeTestCase
from Products.PageTemplates.PageTemplateFile import guess_type
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
from Products.PageTemplates.ZopePageTemplate import manage_addPageTemplate
Expand Down Expand Up @@ -500,6 +504,32 @@ def test___call__(self):
response = object()
self.assertEqual(src(request, response), 'TESTING')

class ZPTBrowserTests(FunctionalTestCase):
"""Browser testing ZopePageTemplate"""

def setUp(self):
from Products.PageTemplates.ZopePageTemplate import \
manage_addPageTemplate
super(ZPTBrowserTests, self).setUp()

Zope2.App.zcml.load_site(force=True)

uf = self.app.acl_users
uf.userFolderAddUser('manager', 'manager_pass', ['Manager'], [])
manage_addPageTemplate(self.app, 'page_template')

self.browser = Browser()
self.browser.addHeader(
'Authorization',
'basic {}'.format(codecs.encode(
b'manager:manager_pass', 'base64').decode()))
self.browser.open('http://localhost/page_template/manage_main')

def test_pt_upload__no_file(self):
"""It renders an error message if no file is uploaded."""
self.browser.getControl('Upload File').click()
self.assertIn('No file specified', self.browser.contents)


class DummyRequest(dict):
pass
Expand All @@ -523,6 +553,7 @@ def test_suite():
unittest.makeSuite(ZPTMacros),
unittest.makeSuite(ZopePageTemplateFileTests),
unittest.makeSuite(ZPTUnicodeEncodingConflictResolution),
unittest.makeSuite(ZPTBrowserTests),
unittest.makeSuite(PreferredCharsetUnicodeResolverTests),
unittest.makeSuite(SrcTests),
))

0 comments on commit 63edf77

Please sign in to comment.