def run_failure_test(self, sysroot_new_mock, async_new_mock, context_mock): """Test OSTree remote pull task failure""" data = _make_config_data() sysroot_mock = sysroot_new_mock() repo_mock = MagicMock() sysroot_mock.get_repo.return_value = [None, repo_mock] repo_mock.pull_with_options.side_effect = [GError("blah")] with patch.object(PullRemoteAndDeleteTask, "report_progress") as progress_mock: with self.assertRaises(PayloadInstallationError) as ex: task = PullRemoteAndDeleteTask(data) task.run() context_mock.assert_called_once() async_new_mock.assert_called_once() self.assertEqual(len(sysroot_new_mock.mock_calls), 4) # 1 above, 1 direct in run(), 2 on the result: load(), get_repo() repo_mock.pull_with_options.assert_called_once() name, args, kwargs = repo_mock.pull_with_options.mock_calls[0] opts = args[1] self.assertEqual(type(opts), Variant) self.assertDictEqual(opts.unpack(), {"refs": ["ref"]}) repo_mock.remote_delete.assert_not_called()
def test_run_success(self, sysroot_new_mock, async_new_mock, context_mock): """Test OSTree remote pull task""" data = _make_config_data() sysroot_mock = sysroot_new_mock() repo_mock = MagicMock() sysroot_mock.get_repo.return_value = [None, repo_mock] with patch.object(PullRemoteAndDeleteTask, "report_progress") as progress_mock: task = PullRemoteAndDeleteTask(data) task.run() context_mock.assert_called_once() async_new_mock.assert_called_once() assert len(sysroot_new_mock.mock_calls) == 4 # 1 above, 1 direct in run(), 2 on the result: load(), get_repo() repo_mock.pull_with_options.assert_called_once() name, args, kwargs = repo_mock.pull_with_options.mock_calls[0] opts = args[1] assert type(opts) == Variant assert opts.unpack() == {"refs": ["ref"]} repo_mock.remote_delete.assert_called_once_with("remote", None)