def setUp(self): super(TestGroupDistributorEnsureUnitsDownloaded, self).setUp() self.distributor = GroupDistributor() self.group = RepositoryGroup(id='g1', display_name='g1', description='g1', notes={}, repo_ids=['repo1', 'repo2'])
class TestGroupDistributorEnsureUnitsDownloaded(unittest.TestCase): def setUp(self): super(TestGroupDistributorEnsureUnitsDownloaded, self).setUp() self.distributor = GroupDistributor() self.group = RepositoryGroup(id='g1', display_name='g1', description='g1', notes={}, repo_ids=['repo1', 'repo2']) def test_all_false(self, mock_has_all_units): """ If all repos are found to have un-downloaded units, make sure the exception is raised. """ mock_has_all_units.return_value = False with self.assertRaises(PulpCodedException) as assertion: self.distributor.ensure_all_units_downloaded(self.group) self.assertEqual(assertion.exception.error_code, error_codes.PLP0046) def test_one_false(self, mock_has_all_units): """ If only 1 repo is found to have un-downloaded units, make sure the exception is raised. """ mock_has_all_units.side_effect = [False, True] with self.assertRaises(PulpCodedException) as assertion: self.distributor.ensure_all_units_downloaded(self.group) self.assertEqual(assertion.exception.error_code, error_codes.PLP0046) def test_does_not_raise_exception(self, mock_has_all_units): """ If all units are found to be downloaded, make sure an exception is not raised. """ self.distributor.ensure_all_units_downloaded(self.group) def test_repo_ids_none(self, mock_has_all_units): """ It seems like repo_ids shouldn't be allowed to be None, but in case it happens, it's easy enough to handle. """ self.group.repo_ids = None self.distributor.ensure_all_units_downloaded(self.group) def test_calls_controller(self, mock_has_all_units): """ Make sure it calls the controller with the right argument. """ self.distributor.ensure_all_units_downloaded(self.group) mock_has_all_units.assert_has_call('repo1') mock_has_all_units.assert_has_call('repo2') self.assertEqual(mock_has_all_units.call_count, 2)
def test_cancel_publish_group_calls_sys_exit(self, mock_sys_exit): GroupDistributor().cancel_publish_group(mock.Mock(), mock.Mock()) mock_sys_exit.assert_called_once_with()