def testJupyterCompileErrorRaise(self):
    """
    Test if JupyterCompile portal_component correctly catches exceptions as 
    expected by the Jupyter frontend as also automatically abort the current
    transaction.
    Take the case in which one line in a statement is valid and another is not.
    """
    portal = self.getPortalObject()
    script_id = "JupyterCompile_errorResult"
    script_container = portal.portal_skins.custom

    new_test_title = "Wendelin Test 1"
    # Check if the existing title is different from new_test_title or not
    if portal.getTitle()==new_test_title:
      new_test_title = "Wendelin"

    python_script = """
portal = context.getPortalObject()
portal.setTitle('%s')
print an_undefined_variable
"""%new_test_title

    # Create python_script object with the above given code and containers
    createZODBPythonScript(script_container, script_id, '', python_script)
    self.tic()

    # Call the above created script in jupyter_code
    jupyter_code = """
portal = context.getPortalObject()
portal.%s()
"""%script_id
    
    # Make call to Base_runJupyter to run the jupyter code which is making
    # a call to the newly created ZODB python_script and assert if the call 
    # processes correctly the NameError as we are sending an invalid 
    # python_code to it.
    # 
    result = portal.Base_runJupyter(
      jupyter_code=jupyter_code, 
      old_notebook_context=portal.Base_createNotebookContext()
    )
    
    self.assertEquals(result['ename'], 'NameError')
    self.assertEquals(result['result_string'], None)
    
    # There's no need to abort the current transaction. The error handling code
    # should be responsible for this, so we check the script's title
    script_title = script_container.JupyterCompile_errorResult.getTitle()
    self.assertNotEqual(script_title, new_test_title)
    
    removeZODBPythonScript(script_container, script_id)

    # Test that calling Base_runJupyter shouldn't change the context Title
    self.assertNotEqual(portal.getTitle(), new_test_title)
예제 #2
0
  def testJupyterCompileErrorRaise(self):
    """
    Test if JupyterCompile portal_component correctly catches exceptions as 
    expected by the Jupyter frontend as also automatically abort the current
    transaction.
    Take the case in which one line in a statement is valid and another is not.
    """
    portal = self.getPortalObject()
    script_id = "JupyterCompile_errorResult"
    script_container = portal.portal_skins.custom

    new_test_title = "Wendelin Test 1"
    # Check if the existing title is different from new_test_title or not
    if portal.getTitle()==new_test_title:
      new_test_title = "Wendelin"

    python_script = """
portal = context.getPortalObject()
portal.setTitle('%s')
print an_undefined_variable
"""%new_test_title

    # Create python_script object with the above given code and containers
    createZODBPythonScript(script_container, script_id, '', python_script)
    self.tic()

    # Call the above created script in jupyter_code
    jupyter_code = """
portal = context.getPortalObject()
portal.%s()
"""%script_id
    
    # Make call to Base_runJupyter to run the jupyter code which is making
    # a call to the newly created ZODB python_script and assert if the call 
    # processes correctly the NameError as we are sending an invalid 
    # python_code to it.
    # 
    result = portal.Base_runJupyter(
      jupyter_code=jupyter_code, 
      old_notebook_context=portal.Base_createNotebookContext()
    )
    
    self.assertEquals(result['ename'], 'NameError')
    self.assertEquals(result['result_string'], None)
    
    # There's no need to abort the current transaction. The error handling code
    # should be responsible for this, so we check the script's title
    script_title = script_container.JupyterCompile_errorResult.getTitle()
    self.assertNotEqual(script_title, new_test_title)
    
    removeZODBPythonScript(script_container, script_id)

    # Test that calling Base_runJupyter shouldn't change the context Title
    self.assertNotEqual(portal.getTitle(), new_test_title)
예제 #3
0
  def beforeTearDown(self):
    for module_id in ('event_module', 'internet_message_post_module', 'letter_post_module'):
      module = getattr(self.portal, module_id)
      module.manage_delObjects(list(module.objectIds()))

    custom_skin = self.portal.portal_skins.custom
    if 'Entity_sendEmail' in custom_skin.objectIds():
      removeZODBPythonScript(
        custom_skin,
        'Entity_sendEmail',
      )
      self.commit()
    def beforeTearDown(self):
        for module_id in ('event_module', 'internet_message_post_module',
                          'letter_post_module'):
            module = getattr(self.portal, module_id)
            module.manage_delObjects(list(module.objectIds()))

        custom_skin = self.portal.portal_skins.custom
        if 'Entity_sendEmail' in custom_skin.objectIds():
            removeZODBPythonScript(
                custom_skin,
                'Entity_sendEmail',
            )
            self.commit()
  def testBase_executeJupyterRespectPreference(self):
    self.login('dev_user')
    removeZODBPythonScript(self.getPortal().portal_skins.custom, "ERP5Site_isDataNotebookEnabled")
    createZODBPythonScript(self.getPortal().portal_skins.custom, "ERP5Site_isDataNotebookEnabled", '', "return False")
    self.tic()

    jupyter_code = "a = 1\na"
    reference = 'Test.Notebook.PreferenceHandle'
    result = self.portal.Base_executeJupyter(
      reference=reference,
      python_expression=jupyter_code
    )
    self.assertEqual(result, 'The synchronous and unrestricted implementation is not enabled on the server')
예제 #6
0
 def createAndRunScript(self, *args, **kwargs):
   # we do not care the script name for security test thus use uuid1
   name = str(uuid.uuid1())
   code = '\n'.join(args)
   expected = kwargs.get('expected', None)
   script_container = self.portal.portal_skins.custom
   try:
     createZODBPythonScript(script_container, name, '**kw', code)
     if expected:
       self.assertEqual(self.runScript(script_container, name), expected)
     else:
       self.runScript(script_container, name)
   finally:
     removeZODBPythonScript(script_container, name)
  def testJupyterCompileErrorRaise(self):
    """
    Test if JupyterCompile portal_component raises error on the server side.
    Take the case in which one line in a statement is valid and another is not.
    """
    portal = self.getPortalObject()
    script_id = "JupyterCompile_errorResult"
    script_container = portal.portal_skins.custom

    new_test_title = "Wendelin Test 1"
    # Check if the existing title is different from new_test_title or not
    if portal.getTitle()==new_test_title:
      new_test_title = "Wendelin"

    python_script = """
portal = context.getPortalObject()
portal.setTitle('%s')
print an_undefined_variable
"""%new_test_title

    # Create python_script object with the above given code and containers
    createZODBPythonScript(script_container, script_id, '', python_script)
    self.tic()

    # Call the above created script in jupyter_code
    jupyter_code = """
portal = context.getPortalObject()
portal.%s()
"""%script_id

    # Make call to Base_runJupyter to run the jupyter code which is making
    # a call to the newly created ZODB python_script and assert if the call raises
    # NameError as we are sending an invalid python_code to it
    self.assertRaises(
                      NameError,
                      portal.Base_runJupyter,
                      jupyter_code=jupyter_code,
                      old_local_variable_dict=portal.Base_addLocalVariableDict()
                      )
    # Abort the current transaction of test so that we can proceed to new one
    transaction.abort()
    # Clear the portal cache from previous transaction
    self.portal.portal_caches.clearAllCache()
    # Remove the ZODB python script created above
    removeZODBPythonScript(script_container, script_id)

    # Test that calling Base_runJupyter shouldn't change the context Title
    self.assertNotEqual(portal.getTitle(), new_test_title)
    def testJupyterCompileErrorRaise(self):
        """
    Test if JupyterCompile portal_component raises error on the server side.
    Take the case in which one line in a statement is valid and another is not.
    """
        portal = self.getPortalObject()
        script_id = "JupyterCompile_errorResult"
        script_container = portal.portal_skins.custom

        new_test_title = "Wendelin Test 1"
        # Check if the existing title is different from new_test_title or not
        if portal.getTitle() == new_test_title:
            new_test_title = "Wendelin"

        python_script = """
portal = context.getPortalObject()
portal.setTitle('%s')
print an_undefined_variable
""" % new_test_title

        # Create python_script object with the above given code and containers
        createZODBPythonScript(script_container, script_id, '', python_script)
        self.tic()

        # Call the above created script in jupyter_code
        jupyter_code = """
portal = context.getPortalObject()
portal.%s()
""" % script_id

        # Make call to Base_runJupyter to run the jupyter code which is making
        # a call to the newly created ZODB python_script and assert if the call raises
        # NameError as we are sending an invalid python_code to it
        self.assertRaises(
            NameError,
            portal.Base_runJupyter,
            jupyter_code=jupyter_code,
            old_local_variable_dict=portal.Base_addLocalVariableDict())
        # Abort the current transaction of test so that we can proceed to new one
        transaction.abort()
        # Clear the portal cache from previous transaction
        self.portal.portal_caches.clearAllCache()
        # Remove the ZODB python script created above
        removeZODBPythonScript(script_container, script_id)

        # Test that calling Base_runJupyter shouldn't change the context Title
        self.assertNotEqual(portal.getTitle(), new_test_title)
 def createAndRunScript(self, code, **kwargs):
     # we do not care the script name for security test thus use uuid1
     name = str(uuid.uuid1())
     expected = kwargs.get('expected', None)
     script_container = self.portal.portal_skins.custom
     try:
         createZODBPythonScript(script_container, name, '**kw',
                                textwrap.dedent(code))
         if expected:
             self.assertEqual(
                 self.runScript(script_container, name,
                                kwargs.get('kwargs', {})), expected)
         else:
             self.runScript(script_container, name,
                            kwargs.get('kwargs', {}))
     finally:
         removeZODBPythonScript(script_container, name)
 def beforeTearDown(self):
   removeZODBPythonScript(self.getPortal().portal_skins.custom, "ERP5Site_isDataNotebookEnabled")
   self.tic()