Skip to content

Commit

Permalink
- Show a message instead of exception for empty file upload (fixes #21)
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed Nov 22, 2018
1 parent 50fd79b commit b9ba63c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Changelog
4.3 (unreleased)
----------------

- Nothing changed yet.
- Show a message instead of exception for empty file upload
(`#21 <https://github.com/zopefoundation/Products.PythonScripts/issues/21>_`)


4.2 (2018-10-11)
Expand Down
4 changes: 3 additions & 1 deletion src/Products/PythonScripts/PythonScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ def ZPythonScriptHTML_upload(self, REQUEST, file=''):

if not isinstance(file, str):
if not file:
raise ValueError('File not specified')
return self.ZPythonScriptHTML_editForm(self, REQUEST,
manage_tabs_message='No file specified',
manage_tabs_type='warning')
file = file.read()

self.write(file)
Expand Down
30 changes: 30 additions & 0 deletions src/Products/PythonScripts/tests/testPythonScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
import codecs
import contextlib
import os
import six
Expand All @@ -19,6 +20,9 @@

from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManagement import noSecurityManager
from Testing.testbrowser import Browser
from Testing.ZopeTestCase import FunctionalTestCase
import Zope2

from Products.PythonScripts.PythonScript import PythonScript

Expand Down Expand Up @@ -323,3 +327,29 @@ def test_class_conforms_to_IWriteLock(self):
except ImportError:
from webdav.interfaces import IWriteLock
verifyClass(IWriteLock, PythonScript)


class PythonScriptBrowserTests(FunctionalTestCase):
"""Browser testing Python Scripts"""

def setUp(self):
from Products.PythonScripts.PythonScript import manage_addPythonScript
super(PythonScriptBrowserTests, self).setUp()

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

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

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

def test_ZPythonScriptHTML_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)

0 comments on commit b9ba63c

Please sign in to comment.