Exemplo n.º 1
0
 def test_file_download(self):
     """
     Test file download
     """
     with mock.patch("JumpScale.j") as j_mock:
         from JumpScale import j
         import JumpScale.tools.cuisine.CuisineCore
         JumpScale.tools.cuisine.CuisineCore.j = j
         from JumpScale.tools.cuisine.CuisineCore import CuisineCore
         executor_mock = mock.MagicMock()
         j.tools.executor.getLocal.return_value = executor_mock
         executor = j.tools.executor.getLocal()
         cuisine = j.tools.cuisine.local
         cuisine_core = CuisineCore(executor, cuisine)
         url = 'http://hallo.com/downloadme.txt'
         to = '/tmp/path'
         cuisine_core.file_exists = mock.MagicMock()
         cuisine_core.file_exists.return_value = False
         cuisine_core.createDir = mock.MagicMock()
         cuisine_core.file_unlink = mock.MagicMock()
         cuisine_core.run = mock.MagicMock()
         cuisine_core.run.side_effect = [(33, '', 'err'), (0, 'Ok', '')]
         cuisine_core.touch = mock.MagicMock()
         cuisine_core.file_download(url, to)
         self.assertTrue(cuisine_core.touch.called)
         self.assertFalse(j.sal.fs.getBaseName.called)
Exemplo n.º 2
0
 def test_file_download_fail(self):
     """
     Test file download wth failure
     """
     with mock.patch("JumpScale.j") as j_mock:
         from JumpScale import j
         import JumpScale.tools.cuisine.CuisineCore
         JumpScale.tools.cuisine.CuisineCore.j = j
         from JumpScale.tools.cuisine.CuisineCore import CuisineCore
         from JumpScale.core.errorhandling import JSExceptions
         executor_mock = mock.MagicMock()
         j.tools.executor.getLocal.return_value = executor_mock
         executor = j.tools.executor.getLocal()
         cuisine = j.tools.cuisine.local
         cuisine_core = CuisineCore(executor, cuisine)
         url = 'http://hallo.com/downloadme.txt'
         to = '/tmp/path'
         cuisine_core.file_exists = mock.MagicMock()
         cuisine_core.file_exists.return_value = False
         cuisine_core.createDir = mock.MagicMock()
         cuisine_core.file_unlink = mock.MagicMock()
         cuisine_core.run = mock.MagicMock()
         cuisine_core.run.side_effect = [(32, '', 'err'), (0, 'Ok', '')]
         cuisine_core.touch = mock.MagicMock()
         j.exceptions.RuntimeError = JSExceptions.RuntimeError
         self.assertRaises(JSExceptions.RuntimeError,
                           cuisine_core.file_download, url, to)
Exemplo n.º 3
0
 def test_file_get_tmp_path(self):
     """
     Test file get tmp path
     """
     with mock.patch("JumpScale.j") as j_mock:
         from JumpScale import j
         import JumpScale.tools.cuisine.CuisineCore
         JumpScale.tools.cuisine.CuisineCore.j = j
         from JumpScale.tools.cuisine.CuisineCore import CuisineCore
         executor_mock = mock.MagicMock()
         j.tools.executor.getLocal.return_value = executor_mock
         executor = j.tools.executor.getLocal()
         cuisine = j.tools.cuisine.local
         cuisine_core = CuisineCore(executor, cuisine)
         cuisine_core.run = mock.MagicMock()
         cuisine_core.run.return_value = (0, 'hostname', '')
         cuisine_core.getenv = mock.MagicMock()
         cuisine_core.getenv.return_value = self.dump_env
         j.data.idgenerator.generateXCharID.return_value = 10 * 'a'
         expected_output = '/optvar//tmp/aaaaaaaaaa'
         actual_output = cuisine_core.file_get_tmp_path()
         self.assertEquals(expected_output, actual_output)
         expected_output = '/optvar//tmp/path'
         actual_output = cuisine_core.file_get_tmp_path(basepath="path")
         self.assertEquals(expected_output, actual_output)
Exemplo n.º 4
0
 def test_args_replace(self):
     """
     Test args replace
     """
     with patch("JumpScale.j") as j_mock:
         from JumpScale import j
         import JumpScale.tools.cuisine.CuisineCore
         JumpScale.tools.cuisine.CuisineCore.j = j
         from JumpScale.tools.cuisine.CuisineCore import CuisineCore
         executor_mock = MagicMock()
         j.tools.executor.getLocal.return_value = executor_mock
         executor = j.tools.executor.getLocal()
         cuisine = j.tools.cuisine.local
         cuisine_core = CuisineCore(executor, cuisine)
         cuisine_core.getenv = MagicMock()
         cuisine_core.getenv.return_value = self.dump_env
         cuisine_core.run = MagicMock()
         cuisine_core.run.return_value = (0, 'hostname', '')
         input_text = "$base:$appDir:$tmplsDir:$varDir:$binDir:$codeDir:$cfgDir:$homeDir:$jsLibDir:$libDir:$logDir:$pidDir:$tmpDir:$hostname"
         expected_output = "/opt/jumpscale8/:/opt/jumpscale8//apps:/opt/jumpscale8//templates:/optvar/:/opt/jumpscale8//bin:/opt/code/:/optvar//cfg:/root:/opt/jumpscale8//lib/JumpScale/:/opt/jumpscale8//lib/:/optvar//log:/optvar//pid:/optvar//tmp:hostname"
         actual_output = cuisine_core.args_replace(input_text)
         self.assertEqual(expected_output, actual_output)
Exemplo n.º 5
0
 def test_file_expand_fail(self):
     """
     Test file expand failure case
     """
     with mock.patch("JumpScale.j") as j_mock:
         from JumpScale import j
         import JumpScale.tools.cuisine.CuisineCore
         JumpScale.tools.cuisine.CuisineCore.j = j
         from JumpScale.tools.cuisine.CuisineCore import CuisineCore
         from JumpScale.core.errorhandling import JSExceptions
         executor_mock = mock.MagicMock()
         j.tools.executor.getLocal.return_value = executor_mock
         executor = j.tools.executor.getLocal()
         cuisine = j.tools.cuisine.local
         cuisine_core = CuisineCore(executor, cuisine)
         path = '/tmp/file.txt'
         to = '/tmp/dest'
         cuisine_core.run = mock.MagicMock()
         cuisine_core.args_replace = mock.MagicMock()
         cuisine_core.args_replace.side_effect = (path, to)
         j.exceptions.RuntimeError = JSExceptions.RuntimeError
         self.assertRaises(JSExceptions.RuntimeError,
                           cuisine_core.file_expand, path, to)
Exemplo n.º 6
0
 def test_touch(self):
     """
     Test touch
     """
     with mock.patch("JumpScale.j") as j_mock:
         from JumpScale import j
         import JumpScale.tools.cuisine.CuisineCore
         JumpScale.tools.cuisine.CuisineCore.j = j
         from JumpScale.tools.cuisine.CuisineCore import CuisineCore
         executor_mock = mock.MagicMock()
         j.tools.executor.getLocal.return_value = executor_mock
         executor = j.tools.executor.getLocal()
         cuisine = j.tools.cuisine.local
         cuisine_core = CuisineCore(executor, cuisine)
         cuisine_core.run = mock.MagicMock()
         cuisine_core.args_replace = mock.MagicMock()
         cuisine_core.file_write = mock.MagicMock()
         self.assertIsNone(cuisine_core.touch('/tmp/hello'))
         self.assertTrue(cuisine_core.file_write.called)
Exemplo n.º 7
0
 def test_file_expand(self):
     """
     Test file expand
     """
     with mock.patch("JumpScale.j") as j_mock:
         from JumpScale import j
         import JumpScale.tools.cuisine.CuisineCore
         JumpScale.tools.cuisine.CuisineCore.j = j
         from JumpScale.tools.cuisine.CuisineCore import CuisineCore
         executor_mock = mock.MagicMock()
         j.tools.executor.getLocal.return_value = executor_mock
         executor = j.tools.executor.getLocal()
         cuisine = j.tools.cuisine.local
         cuisine_core = CuisineCore(executor, cuisine)
         path = '/tmp/file.tgz'
         to = '/tmp/dest'
         cuisine_core.run = mock.MagicMock()
         cuisine_core.args_replace = mock.MagicMock()
         cuisine_core.file_expand(path, to)