def setUp(self): super(TestRemoveOldVersions, self).setUp() self.rpms = model_factory.rpm_units(3, True) self.rpms.extend(model_factory.rpm_units(2, False)) self.srpms = model_factory.srpm_units(3, True) self.srpms.extend(model_factory.srpm_units(2, False)) self.drpms = model_factory.drpm_units(3, True) self.drpms.extend(model_factory.drpm_units(2, False))
def test_with_existing_deps(self, mock_find, mock_get_existing): conduit = mock.MagicMock() rpms = model_factory.rpm_units(1) deps = model_factory.rpm_units(2) mock_find.return_value = set(deps) mock_get_existing.return_value = deps associate.copy_rpms(rpms, conduit, True) self.assertEqual(conduit.associate_unit.call_count, 1) self.assertEqual(mock_find.call_count, 1) self.assertEqual(mock_find.call_args[0][1], set(rpms)) self.assertEqual(mock_get_existing.call_count, 1)
def test_copy_group_recursive(self, mock_associate, mock_get_existing, mock_copy): self.config.override_config = {constants.CONFIG_RECURSIVE: True} self.conduit.get_source_units.return_value = [] # make it look like half of the RPMs named by the groups being copied # already exist in the destination existing_rpms = model_factory.rpm_units(2) existing_rpms[0].unit_key['name'] = self.group1_names[1] existing_rpms[1].unit_key['name'] = self.group2_names[1] existing_rpm_names = [self.group1_names[1], self.group2_names[1]] mock_get_existing.side_effect = iter([[], [], existing_rpms]) mock_copy.return_value = set( u for u in self.rpm_units if u.unit_key['name'] not in existing_rpm_names) ret = associate.associate(self.source_repo, self.dest_repo, self.conduit, self.config, self.group_units) # this only happens if we successfully did a recursive call to associate() # and used the "existing" module to eliminate half the RPM names from those # that needed to be copied. mock_copy.assert_called_once_with( set([self.group1_names[0], self.group2_names[0]]), self.conduit, True) self.assertEqual(set(ret), set(self.group_units) | set(self.rpm_units))
def test_without_deps(self): conduit = mock.MagicMock() rpms = model_factory.rpm_units(3) associate.copy_rpms(rpms, conduit, False) self.assertEqual(conduit.associate_unit.call_count, 3) for rpm in rpms: conduit.associate_unit.assert_any_call(rpm)
def test_with_recursive_deps(self, mock_find, mock_get_existing): """ Test getting dependencies that do not exist in the repository already """ conduit = mock.MagicMock() # Create the primary RPMS that we want to copy rpms = model_factory.rpm_units(1) # Create the recursive dependencies that we want to copy deps = model_factory.rpm_units(2) mock_find.side_effect = iter([set(deps), set()]) # The get existing units always assumes there are no units in the target repository mock_get_existing.return_value = [] unit_set = associate.copy_rpms(rpms, conduit, True) merged_set = set(deps) merged_set.update(rpms) self.assertEquals(unit_set, merged_set)
def setUp(self): self.source_repo = Repository('repo-source') self.dest_repo = Repository('repo-dest') self.rpm_units = model_factory.rpm_units(2) self.category_units = model_factory.category_units(2) self.group_units = model_factory.group_units(2) self.group1_names = self.group_units[0].metadata['default_package_names'] self.group2_names = self.group_units[1].metadata['default_package_names'] self.conduit = mock.MagicMock() self.config = PluginCallConfiguration({}, {}, {})
def setUp(self): self.source_repo = Repository('repo-source') self.dest_repo = Repository('repo-dest') self.rpm_units = model_factory.rpm_units(2) self.category_units = model_factory.category_units(2) self.group_units = model_factory.group_units(2) self.group1_names = self.group_units[0].metadata[ 'default_package_names'] self.group2_names = self.group_units[1].metadata[ 'default_package_names'] self.conduit = mock.MagicMock() self.config = PluginCallConfiguration({}, {}, {})
def test_remove_missing_units(self, mock_get_existing): self.conduit.remove_unit = mock.MagicMock(spec_set=self.conduit.remove_unit) # setup such that only one of the 2 existing units appears to be present # in the remote repo, thus the other unit should be purged mock_get_existing.return_value = model_factory.rpm_units(2) remote_named_tuples = set(model.as_named_tuple for model in model_factory.rpm_models(2)) common_unit = mock_get_existing.return_value[1] common_named_tuple = models.RPM.NAMEDTUPLE(**common_unit.unit_key) remote_named_tuples.add(common_named_tuple) purge.remove_missing_units(self.conduit, models.RPM, remote_named_tuples) mock_get_existing.assert_called_once_with(models.RPM, self.conduit.get_units) self.conduit.remove_unit.assert_called_once_with(mock_get_existing.return_value[0])
def test_all_in_source(self, mock_copy): rpms = model_factory.rpm_units(2) names = [r.unit_key['name'] for r in rpms] conduit = mock.MagicMock() conduit.get_source_units.return_value = rpms associate.copy_rpms_by_name(names, conduit, False) self.assertEqual(conduit.get_source_units.call_count, 1) to_copy = list(mock_copy.call_args[0][0]) self.assertEqual(len(to_copy), 2) for unit in to_copy: self.assertTrue(isinstance(unit, Unit)) self.assertTrue(unit.unit_key['name'] in names) self.assertFalse(mock_copy.call_args[0][2])
def test_with_existing_deps(self, mock_find, mock_get_existing): conduit = mock.MagicMock() rpms = model_factory.rpm_units(1) deps = model_factory.rpm_models(2) dep_units = [Unit(model.TYPE, model.unit_key, model.metadata, '') for model in deps] mock_find.return_value = [r.as_named_tuple for r in deps] mock_get_existing.return_value = dep_units associate.copy_rpms(rpms, conduit, True) self.assertEqual(conduit.associate_unit.call_count, 1) self.assertEqual(mock_find.call_count, 1) self.assertEqual(mock_find.call_args[0][0], set(rpms)) # called once directly, and once from filter_available_rpms self.assertEqual(mock_get_existing.call_count, 2)
def test_multiple_versions(self, mock_copy): rpms = model_factory.rpm_units(2, True) names = list(set([r.unit_key['name'] for r in rpms])) conduit = mock.MagicMock() conduit.get_source_units.return_value = rpms associate.copy_rpms_by_name(names, conduit, False) self.assertEqual(conduit.get_source_units.call_count, 1) to_copy = list(mock_copy.call_args[0][0]) self.assertEqual(len(to_copy), 1) unit = to_copy[0] self.assertTrue(isinstance(unit, Unit)) self.assertTrue(unit.unit_key['name'] in names) self.assertEqual(unit.unit_key['version'], rpms[1].unit_key['version']) self.assertFalse(mock_copy.call_args[0][2])
def test_with_recursive_deps(self, mock_find, mock_get_existing, mock_filter): """ Test getting dependencies that do not exist in the repository already """ conduit = mock.MagicMock() # Create the primary RPMS that we want to copy rpms = model_factory.rpm_units(1) # Create the recursive dependencies that we want to copy deps = model_factory.rpm_models(2) dep_units = [Unit(model.TYPE, model.unit_key, model.metadata, '') for model in deps] # the first call to filter gets all the dependencies for the parent repository # The second time it is called during the recursion and all the units have already # been copied. mock_filter.side_effect = iter([dep_units, []]) # The get existing units always assumes there are no units in the target repository mock_get_existing.return_value = [] unit_set = associate.copy_rpms(rpms, conduit, True) merged_set = set(dep_units) merged_set.update(rpms) self.assertEquals(unit_set, merged_set)
def test_copy_group_recursive(self, mock_associate, mock_get_existing, mock_copy): self.config.override_config = {constants.CONFIG_RECURSIVE: True} self.conduit.get_source_units.return_value = [] # make it look like half of the RPMs named by the groups being copied # already exist in the destination existing_rpms = model_factory.rpm_units(2) existing_rpms[0].unit_key['name'] = self.group1_names[1] existing_rpms[1].unit_key['name'] = self.group2_names[1] existing_rpm_names = [self.group1_names[1], self.group2_names[1]] mock_get_existing.side_effect = iter([[], [], existing_rpms]) mock_copy.return_value = set(u for u in self.rpm_units if u.unit_key['name'] not in existing_rpm_names) ret = associate.associate(self.source_repo, self.dest_repo, self.conduit, self.config, self.group_units) # this only happens if we successfully did a recursive call to associate() # and used the "existing" module to eliminate half the RPM names from those # that needed to be copied. mock_copy.assert_called_once_with( set([self.group1_names[0], self.group2_names[0]]), self.conduit, True) self.assertEqual(set(ret), set(self.group_units) | set(self.rpm_units))
def setUp(self): self.units = model_factory.rpm_units(2) self.search_dicts = [unit.unit_key for unit in self.units] self.conduit = mock.MagicMock()