1
# Copyright 2016 Canonical Ltd.
3
# This program is free software: you can redistribute it and/or modify it
4
# under the terms of the GNU General Public License version 3, as published
5
# by the Free Software Foundation.
7
# This program is distributed in the hope that it will be useful, but
8
# WITHOUT ANY WARRANTY; without even the implied warranties of
9
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
10
# PURPOSE. See the GNU General Public License for more details.
12
# You should have received a copy of the GNU General Public License along
13
# with this program. If not, see <http://www.gnu.org/licenses/>.
17
from unittest import TestCase
18
from libertine.service import tasks
19
from libertine.ContainersConfig import ContainersConfig
22
class TestListAppsTask(TestCase):
24
self.config = unittest.mock.create_autospec(ContainersConfig)
25
self.connection = unittest.mock.Mock()
26
self.lock = unittest.mock.MagicMock()
27
self.called_with = None
29
def callback(self, task):
30
self.called_with = task
32
def test_sends_error_on_non_existent_container(self):
33
self.config.container_exists.return_value = False
34
with unittest.mock.patch('libertine.service.tasks.base_task.libertine.service.progress.Progress') as MockProgress:
35
progress = MockProgress.return_value
36
task = tasks.ListAppsTask('palpatine', self.config, self.connection, self.callback)
37
task._instant_callback = True
39
with unittest.mock.patch('libertine.service.tasks.list_apps_task.LibertineContainer') as MockContainer:
42
progress.error.assert_called_once_with('Container \'palpatine\' does not exist, skipping list')
43
self.assertEqual(task, self.called_with)
45
def test_successfully_lists_apps(self):
46
self.config.container_exists.return_value = True
47
with unittest.mock.patch('libertine.service.tasks.base_task.libertine.service.progress.Progress') as MockProgress:
48
progress = MockProgress.return_value
50
task = tasks.ListAppsTask('palpatine', self.config, self.connection, self.callback)
51
task._instant_callback = True
53
with unittest.mock.patch('libertine.service.tasks.list_apps_task.LibertineContainer') as MockContainer:
54
MockContainer.return_value.list_app_launchers.return_value = 'jarjar\nsidius'
57
progress.finished.assert_called_once_with('palpatine')
58
progress.data.assert_called_once_with('jarjar\nsidius')
59
self.assertEqual(task, self.called_with)