Esempio n. 1
0
 def test_install_creates_install_task(self):
     with unittest.mock.patch(
             'libertine.service.container.apt.AptCache') as MockCache:
         c = container.Container('palpatine', self._config, self._monitor,
                                 self._client, lambda task: task)
         with unittest.mock.patch('libertine.service.container.InstallTask'
                                  ) as MockInstallTask:
             c.install('force')
             MockInstallTask.assert_called_once_with(
                 'force', 'palpatine', self._config, unittest.mock.ANY,
                 self._monitor, self._client, unittest.mock.ANY)
             MockInstallTask.return_value.start.assert_called_once_with()
Esempio n. 2
0
 def test_list_app_ids_creates_list_app_ids_task(self):
     with unittest.mock.patch(
             'libertine.service.container.apt.AptCache') as MockCache:
         c = container.Container('palpatine', self._config, self._monitor,
                                 self._client, lambda task: task)
         with unittest.mock.patch(
                 'libertine.service.container.ListAppIdsTask'
         ) as MockListAppIdsTask:
             c.list_app_ids()
             MockListAppIdsTask.assert_called_once_with(
                 'palpatine', self._config, self._monitor, self._client,
                 unittest.mock.ANY)
             MockListAppIdsTask.return_value.start.assert_called_once_with()
Esempio n. 3
0
 def test_app_info_creates_app_info_task(self):
     with unittest.mock.patch(
             'libertine.service.container.apt.AptCache') as MockCache:
         cache = MockCache.return_value
         c = container.Container('palpatine', self._config, self._monitor,
                                 self._client, lambda task: task)
         with unittest.mock.patch('libertine.service.container.AppInfoTask'
                                  ) as MockAppInfoTask:
             c.app_info('force')
             MockAppInfoTask.assert_called_once_with(
                 'palpatine', cache, 'force', [], self._config,
                 self._monitor, unittest.mock.ANY)
             MockAppInfoTask.return_value.start.assert_called_once_with()
Esempio n. 4
0
 def test_create_creates_create_task(self):
     with unittest.mock.patch(
             'libertine.service.container.apt.AptCache') as MockCache:
         c = container.Container('palpatine', self._config, self._monitor,
                                 self._client, lambda task: task)
         with unittest.mock.patch('libertine.service.container.CreateTask'
                                  ) as MockCreateTask:
             c.create('Emperor Palpatine', 'zesty', 'lxd', False)
             MockCreateTask.assert_called_once_with(
                 'palpatine', 'Emperor Palpatine', 'zesty', 'lxd', False,
                 self._config, unittest.mock.ANY, self._monitor,
                 self._client, unittest.mock.ANY)
             MockCreateTask.return_value.start.assert_called_once_with()
Esempio n. 5
0
 def test_search_creates_search_task(self):
     with unittest.mock.patch(
             'libertine.service.container.apt.AptCache') as MockCache:
         cache = MockCache.return_value
         c = container.Container('palpatine', self._config, self._monitor,
                                 self._client, lambda task: task)
         with unittest.mock.patch('libertine.service.container.SearchTask'
                                  ) as MockSearchTask:
             c.search('darkseid')
             MockSearchTask.assert_called_once_with('palpatine', cache,
                                                    'darkseid',
                                                    self._monitor,
                                                    unittest.mock.ANY)
             MockSearchTask.return_value.start.assert_called_once_with()
Esempio n. 6
0
 def test_update_only_calls_once_when_unfinished(self):
     with unittest.mock.patch(
             'libertine.service.container.apt.AptCache') as MockCache:
         c = container.Container('palpatine', self._config, self._monitor,
                                 self._client, lambda task: task)
         with unittest.mock.patch('libertine.service.container.UpdateTask'
                                  ) as MockUpdateTask:
             c.update()
             c.update()
             c.update()
             MockUpdateTask.assert_called_once_with(
                 'palpatine', self._config, unittest.mock.ANY,
                 self._monitor, self._client, unittest.mock.ANY)
             MockUpdateTask.return_value.start.assert_called_once_with()
Esempio n. 7
0
    def test_completing_all_tasks_fires_callback(self):
        with unittest.mock.patch(
                'libertine.service.container.apt.AptCache') as MockCache:
            self._container_id = None

            def callback(container):
                self._container_id = container.id

            c = container.Container('palpatine', self._config, self._monitor,
                                    self._client, callback)
            with unittest.mock.patch('libertine.service.container.InstallTask'
                                     ) as MockInstallTask:
                c.install('force')
                name, args, kwargs = MockInstallTask.mock_calls[0]
                args[len(args) - 1](MockInstallTask.return_value)
            self.assertEqual('palpatine', self._container_id)
Esempio n. 8
0
 def test_removes_task_during_callback(self):
     with unittest.mock.patch(
             'libertine.service.container.apt.AptCache') as MockCache:
         c = container.Container('palpatine', self._config, self._monitor,
                                 self._client, lambda task: task)
         with unittest.mock.patch('libertine.service.container.InstallTask'
                                  ) as MockInstallTask:
             MockInstallTask.return_value.package = 'force'
             c.install('force')
             self.assertEqual(
                 1, len(MockInstallTask.return_value.start.mock_calls
                        ))  # ensure initial mocks were called
             c.install('force')
             self.assertEqual(
                 1, len(MockInstallTask.return_value.start.mock_calls
                        ))  # ensure no more mocks were called
             name, args, kwargs = MockInstallTask.mock_calls[0]
             args[len(args) - 1](
                 MockInstallTask.return_value.start.return_value)
             c.install('force')
             self.assertEqual(
                 2, len(MockInstallTask.return_value.start.mock_calls
                        ))  # ensure mocks were called again
Esempio n. 9
0
 def test_app_info_gets_related_task_info(self):
     with unittest.mock.patch(
             'libertine.service.container.apt.AptCache') as MockCache:
         cache = MockCache.return_value
         c = container.Container('palpatine', self._config, self._monitor,
                                 self._client, lambda task: task)
         with unittest.mock.patch('libertine.service.container.InstallTask'
                                  ) as MockInstallTask:
             MockInstallTask.return_value.package = 'darkside'
             MockInstallTask.return_value.matches.return_value = False
             install_task_id = c.install('darkside')
             with unittest.mock.patch(
                     'libertine.service.container.RemoveTask'
             ) as MockRemoveTask:
                 MockRemoveTask.return_value.package = 'darkside'
                 remove_task_id = c.remove('darkside')
             with unittest.mock.patch(
                     'libertine.service.container.AppInfoTask'
             ) as MockAppInfoTask:
                 c.app_info('darkside')
                 MockAppInfoTask.assert_called_once_with(
                     'palpatine', cache, 'darkside',
                     [install_task_id, remove_task_id], self._config,
                     self._monitor, unittest.mock.ANY)