30
30
c = container.Container('palpatine', self._config, self._monitor, self._client, lambda task: task)
31
31
with unittest.mock.patch('libertine.service.container.SearchTask') as MockSearchTask:
32
32
c.search('darkseid')
33
MockSearchTask.assert_called_once_with('palpatine', cache, 'darkseid', self._monitor, unittest.mock.ANY)
33
MockSearchTask.assert_called_once_with('palpatine', cache, 'darkseid', self._config, self._monitor, unittest.mock.ANY)
34
34
MockSearchTask.return_value.start.assert_called_once_with()
36
36
def test_app_info_creates_app_info_task(self):
49
49
with unittest.mock.patch('libertine.service.container.InstallTask') as MockInstallTask:
50
50
MockInstallTask.return_value.package = 'darkside'
51
51
MockInstallTask.return_value.matches.return_value = False
52
install_task_id = c.install('darkside')
52
install_task_id = c.install('darkside', False)
53
53
with unittest.mock.patch('libertine.service.container.RemoveTask') as MockRemoveTask:
54
54
MockRemoveTask.return_value.package = 'darkside'
55
55
remove_task_id = c.remove('darkside')
62
62
with unittest.mock.patch('libertine.service.container.apt.AptCache') as MockCache:
63
63
c = container.Container('palpatine', self._config, self._monitor, self._client, lambda task: task)
64
64
with unittest.mock.patch('libertine.service.container.InstallTask') as MockInstallTask:
66
MockInstallTask.assert_called_once_with('force', 'palpatine', self._config, unittest.mock.ANY, self._monitor, self._client, unittest.mock.ANY)
65
c.install('force', False)
66
MockInstallTask.assert_called_once_with('force', 'palpatine', False, self._config, unittest.mock.ANY, self._monitor, self._client)
67
67
MockInstallTask.return_value.start.assert_called_once_with()
69
69
def test_install_only_calls_once_when_unfinished(self):
70
70
with unittest.mock.patch('libertine.service.container.apt.AptCache') as MockCache:
71
71
c = container.Container('palpatine', self._config, self._monitor, self._client, lambda task: task)
72
72
with unittest.mock.patch('libertine.service.container.InstallTask') as MockInstallTask:
76
MockInstallTask.assert_called_once_with('darkside', 'palpatine', self._config, unittest.mock.ANY, self._monitor, self._client, unittest.mock.ANY)
73
c.install('darkside', False)
74
c.install('darkside', False)
75
c.install('darkside', False)
76
MockInstallTask.assert_called_once_with('darkside', 'palpatine', False, self._config, unittest.mock.ANY, self._monitor, self._client)
77
77
MockInstallTask.return_value.start.assert_called_once_with()
79
79
def test_remove_creates_remove_task(self):
81
81
c = container.Container('palpatine', self._config, self._monitor, self._client, lambda task: task)
82
82
with unittest.mock.patch('libertine.service.container.RemoveTask') as MockRemoveTask:
84
MockRemoveTask.assert_called_once_with('force', 'palpatine', self._config, unittest.mock.ANY, self._monitor, self._client, unittest.mock.ANY)
84
MockRemoveTask.assert_called_once_with('force', 'palpatine', self._config, unittest.mock.ANY, self._monitor, self._client)
85
85
MockRemoveTask.return_value.start.assert_called_once_with()
87
87
def test_remove_only_calls_once_when_unfinished(self):
91
91
c.remove('darkside')
92
92
c.remove('darkside')
93
93
c.remove('darkside')
94
MockRemoveTask.assert_called_once_with('darkside', 'palpatine', self._config, unittest.mock.ANY, self._monitor, self._client, unittest.mock.ANY)
94
MockRemoveTask.assert_called_once_with('darkside', 'palpatine', self._config, unittest.mock.ANY, self._monitor, self._client)
95
95
MockRemoveTask.return_value.start.assert_called_once_with()
97
97
def test_create_creates_create_task(self):
100
100
with unittest.mock.patch('libertine.service.container.CreateTask') as MockCreateTask:
101
101
c.create('Emperor Palpatine', 'zesty', 'lxd', False)
102
102
MockCreateTask.assert_called_once_with('palpatine', 'Emperor Palpatine', 'zesty', 'lxd', False,
103
self._config, unittest.mock.ANY, self._monitor, self._client, unittest.mock.ANY)
103
self._config, unittest.mock.ANY, self._monitor, self._client)
104
104
MockCreateTask.return_value.start.assert_called_once_with()
106
106
def test_create_only_calls_once_when_unfinished(self):
111
111
c.create('Emperor Palpatine', 'zesty', 'lxd', False)
112
112
c.create('Emperor Palpatine', 'zesty', 'lxd', False)
113
113
MockCreateTask.assert_called_once_with('palpatine', 'Emperor Palpatine', 'zesty', 'lxd', False,
114
self._config, unittest.mock.ANY, self._monitor, self._client, unittest.mock.ANY)
114
self._config, unittest.mock.ANY, self._monitor, self._client)
115
115
MockCreateTask.return_value.start.assert_called_once_with()
117
117
def test_destroy_creates_destroy_task(self):
118
118
with unittest.mock.patch('libertine.service.container.apt.AptCache') as MockCache:
119
119
c = container.Container('palpatine', self._config, self._monitor, self._client, lambda task: task)
120
120
with unittest.mock.patch('libertine.service.container.DestroyTask') as MockDestroyTask:
122
MockDestroyTask.assert_called_once_with('palpatine', self._config, unittest.mock.ANY, self._monitor, self._client, unittest.mock.ANY)
122
MockDestroyTask.assert_called_once_with('palpatine', self._config, False, unittest.mock.ANY, self._monitor, self._client)
123
123
MockDestroyTask.return_value.start.assert_called_once_with()
125
125
def test_destroy_only_calls_once_when_unfinished(self):
126
126
with unittest.mock.patch('libertine.service.container.apt.AptCache') as MockCache:
127
127
c = container.Container('palpatine', self._config, self._monitor, self._client, lambda task: task)
128
128
with unittest.mock.patch('libertine.service.container.DestroyTask') as MockDestroyTask:
132
MockDestroyTask.assert_called_once_with('palpatine', self._config, unittest.mock.ANY, self._monitor, self._client, unittest.mock.ANY)
132
MockDestroyTask.assert_called_once_with('palpatine', self._config, False, unittest.mock.ANY, self._monitor, self._client)
133
133
MockDestroyTask.return_value.start.assert_called_once_with()
135
135
def test_update_creates_update_task(self):
137
137
c = container.Container('palpatine', self._config, self._monitor, self._client, lambda task: task)
138
138
with unittest.mock.patch('libertine.service.container.UpdateTask') as MockUpdateTask:
140
MockUpdateTask.assert_called_once_with('palpatine', self._config, unittest.mock.ANY, self._monitor, self._client, unittest.mock.ANY)
140
MockUpdateTask.assert_called_once_with('palpatine', self._config, unittest.mock.ANY, self._monitor, self._client)
141
141
MockUpdateTask.return_value.start.assert_called_once_with()
143
143
def test_update_only_calls_once_when_unfinished(self):
150
MockUpdateTask.assert_called_once_with('palpatine', self._config, unittest.mock.ANY, self._monitor, self._client, unittest.mock.ANY)
150
MockUpdateTask.assert_called_once_with('palpatine', self._config, unittest.mock.ANY, self._monitor, self._client)
151
151
MockUpdateTask.return_value.start.assert_called_once_with()
153
153
def test_list_app_ids_creates_list_app_ids_task(self):
158
158
MockListAppIdsTask.assert_called_once_with('palpatine', self._config, self._monitor, unittest.mock.ANY)
159
159
MockListAppIdsTask.return_value.start.assert_called_once_with()
161
def test_removes_task_during_callback(self):
161
def test_removes_task_during_cleanup(self):
162
162
with unittest.mock.patch('libertine.service.container.apt.AptCache') as MockCache:
163
163
c = container.Container('palpatine', self._config, self._monitor, self._client, lambda task: task)
164
164
with unittest.mock.patch('libertine.service.container.InstallTask') as MockInstallTask:
165
165
MockInstallTask.return_value.package = 'force'
166
c.install('force', False)
167
167
self.assertEqual(1, len(MockInstallTask.return_value.start.mock_calls)) # ensure initial mocks were called
168
c.install('force', False)
169
169
self.assertEqual(1, len(MockInstallTask.return_value.start.mock_calls)) # ensure no more mocks were called
170
name, args, kwargs = MockInstallTask.mock_calls[0]
171
args[len(args)-1](MockInstallTask.return_value.start.return_value)
170
MockInstallTask.return_value.should_delete = True
172
c.install('force', False)
173
173
self.assertEqual(2, len(MockInstallTask.return_value.start.mock_calls)) # ensure mocks were called again
175
175
def test_completing_all_tasks_fires_callback(self):
179
179
self._container_id = container.id
180
180
c = container.Container('palpatine', self._config, self._monitor, self._client, callback)
181
181
with unittest.mock.patch('libertine.service.container.InstallTask') as MockInstallTask:
183
name, args, kwargs = MockInstallTask.mock_calls[0]
184
args[len(args)-1](MockInstallTask.return_value)
182
c.install('force', False)
183
MockInstallTask.return_value.should_delete = True
185
185
self.assertEqual('palpatine', self._container_id)