Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Jérome Perrin
erp5
Commits
5a0d4baf
Commit
5a0d4baf
authored
Sep 30, 2015
by
Ayush Tiwari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_data_notebook bt5: Add exception handling while serializing result
parent
f807b0b6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
12 deletions
+20
-12
bt5/erp5_data_notebook/SkinTemplateItem/portal_skins/erp5_data_notebook/Base_executeJupyter.xml
...m/portal_skins/erp5_data_notebook/Base_executeJupyter.xml
+15
-7
bt5/erp5_data_notebook/TestTemplateItem/portal_components/test.erp5.testExecuteJupyter.py
...ateItem/portal_components/test.erp5.testExecuteJupyter.py
+5
-5
No files found.
bt5/erp5_data_notebook/SkinTemplateItem/portal_skins/erp5_data_notebook/Base_executeJupyter.xml
View file @
5a0d4baf
...
@@ -61,12 +61,9 @@
...
@@ -61,12 +61,9 @@
</item>
</item>
<item>
<item>
<key>
<string>
_body
</string>
</key>
<key>
<string>
_body
</string>
</key>
<value>
<string>
from Products.CMFActivity.ActiveResult import ActiveResult\n
<value>
<string>
import json\n
import json\n
\n
\n
selection_id = \'python_shell_selection\'\n
portal = context.getPortalObject()\n
portal = context.getPortalObject()\n
portal_selections = portal.portal_selections\n
\n
\n
# The boolean values via requests are received as \n
# The boolean values via requests are received as \n
request_reference = {\'True\': True, \'False\': False}.get(request_reference, False)\n
request_reference = {\'True\': True, \'False\': False}.get(request_reference, False)\n
...
@@ -129,9 +126,20 @@ result = {\n
...
@@ -129,9 +126,20 @@ result = {\n
u\'status\': status\n
u\'status\': status\n
}\n
}\n
\n
\n
data_notebook_message.edit(notebook_code_result=code_result)\n
try:\n
\n
serialized_result = json.dumps(result)\n
return json.dumps(result)\n
data_notebook_message.edit(notebook_code_result=code_result)\n
except UnicodeDecodeError:\n
result = {\n
u\'code_result\': None,\n
u\'ename\': u\'UnicodeDecodeError\',\n
u\'evalue\': None,\n
u\'traceback\': None,\n
u\'status\': u\'error\'\n
}\n
serialized_result = json.dumps(result)\n
\n
return serialized_result\n
</string>
</value>
</string>
</value>
</item>
</item>
<item>
<item>
...
...
bt5/erp5_data_notebook/TestTemplateItem/portal_components/test.erp5.testExecuteJupyter.py
View file @
5a0d4baf
...
@@ -39,7 +39,7 @@ class TestExecuteJupyter(SecurityTestCase):
...
@@ -39,7 +39,7 @@ class TestExecuteJupyter(SecurityTestCase):
"""
"""
self
.
notebook_module
=
self
.
portal
.
getDefaultModule
(
portal_type
=
'Data Notebook'
)
self
.
notebook_module
=
self
.
portal
.
getDefaultModule
(
portal_type
=
'Data Notebook'
)
self
.
assertTrue
(
self
.
notebook_module
is
not
None
)
self
.
assertTrue
(
self
.
notebook_module
is
not
None
)
# Create user to be used in tests
# Create user to be used in tests
user_folder
=
self
.
getPortal
().
acl_users
user_folder
=
self
.
getPortal
().
acl_users
user_folder
.
_doAddUser
(
'dev_user'
,
''
,
[
'Manager'
,],
[])
user_folder
.
_doAddUser
(
'dev_user'
,
''
,
[
'Manager'
,],
[])
...
@@ -96,7 +96,7 @@ class TestExecuteJupyter(SecurityTestCase):
...
@@ -96,7 +96,7 @@ class TestExecuteJupyter(SecurityTestCase):
result_title
=
[
obj
.
getTitle
()
for
obj
in
notebook_search_result
]
result_title
=
[
obj
.
getTitle
()
for
obj
in
notebook_search_result
]
if
result_title
:
if
result_title
:
self
.
assertEquals
(
notebook
.
getTitle
(),
result_title
[
0
])
self
.
assertEquals
(
notebook
.
getTitle
(),
result_title
[
0
])
def
testUserCanCreateNotebookWithCode
(
self
):
def
testUserCanCreateNotebookWithCode
(
self
):
"""
"""
Test if user can create Data Notebook Message object or not
Test if user can create Data Notebook Message object or not
...
@@ -105,8 +105,8 @@ class TestExecuteJupyter(SecurityTestCase):
...
@@ -105,8 +105,8 @@ class TestExecuteJupyter(SecurityTestCase):
notebook
=
self
.
_newNotebook
(
reference
=
'new_notebook_with_code'
)
notebook
=
self
.
_newNotebook
(
reference
=
'new_notebook_with_code'
)
self
.
tic
()
self
.
tic
()
notebook_code
=
'some_random_invalid_notebook_code %s'
%
time
.
time
()
notebook_code
=
'some_random_invalid_notebook_code %s'
%
time
.
time
()
self
.
_newNotebookMessage
(
self
.
_newNotebookMessage
(
notebook_module
=
notebook
,
notebook_module
=
notebook
,
notebook_code
=
notebook_code
notebook_code
=
notebook_code
...
@@ -155,7 +155,7 @@ class TestExecuteJupyter(SecurityTestCase):
...
@@ -155,7 +155,7 @@ class TestExecuteJupyter(SecurityTestCase):
python_expression
=
"print 52"
python_expression
=
"print 52"
reference
=
'Test.Notebook.AddNewNotebookMessage %s'
%
time
.
time
()
reference
=
'Test.Notebook.AddNewNotebookMessage %s'
%
time
.
time
()
title
=
'Test NB Title %s'
%
time
.
time
()
title
=
'Test NB Title %s'
%
time
.
time
()
# Calling the function twice, first to create a new notebook and then
# Calling the function twice, first to create a new notebook and then
# sending python_expression to check if it adds to the same notebook
# sending python_expression to check if it adds to the same notebook
portal
.
Base_executeJupyter
(
title
=
title
,
reference
=
reference
)
portal
.
Base_executeJupyter
(
title
=
title
,
reference
=
reference
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment