Skip to content

Commit

Permalink
Fix updating an existing script from a file
Browse files Browse the repository at this point in the history
A `TypeError` occured when one tried to update an existing script from a
file.

This has been fixed.

modified:   CHANGES.rst
modified:   src/Products/PythonScripts/PythonScript.py
modified:   src/Products/PythonScripts/tests/testPythonScript.py
  • Loading branch information
jugmac00 committed May 22, 2020
1 parent e4f9240 commit 4166d3e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -3,6 +3,8 @@ Changelog

4.12 (unreleased)
-----------------
- fix ``TypeError`` when updating an existing script from a file
(`#43 <https://github.com/zopefoundation/Products.PythonScripts/issues/43>`_)


4.11 (2020-02-11)
Expand Down
1 change: 1 addition & 0 deletions src/Products/PythonScripts/PythonScript.py
Expand Up @@ -195,6 +195,7 @@ def ZPythonScriptHTML_upload(self, REQUEST, file=''):
manage_tabs_message='No file specified',
manage_tabs_type='warning')
file = file.read()
file = file.decode('utf-8')

self.write(file)
message = 'Saved changes.'
Expand Down
8 changes: 8 additions & 0 deletions src/Products/PythonScripts/tests/testPythonScript.py
Expand Up @@ -430,3 +430,11 @@ 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)

def test_ZPythonScriptHTML_upload__with_file(self):
file_contents = b'print("hello")'
self.browser.getControl('file').add_file(
file_contents, 'text/plain', 'script.py')
self.browser.getControl('Upload File').click()

assert 'Saved changes.' in self.browser.contents

0 comments on commit 4166d3e

Please sign in to comment.