def test_no_units_provided(self, mock_associate): self.conduit.get_source_units.return_value = self.group_units associate.associate(self.source_repo, self.dest_repo, self.conduit, self.config) self.assertEqual(mock_associate.call_count, 2) # confirms that it used the conduit's get_source_units() method mock_associate.assert_any_call(self.dest_repo, self.conduit, self.group_units[0]) mock_associate.assert_any_call(self.dest_repo, self.conduit, self.group_units[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_calls_copy_rpms(self, mock_copy_rpms): mock_copy_rpms.return_value = set(self.rpm_units) ret = associate.associate(self.source_repo, self.dest_repo, self.conduit, self.config, self.rpm_units) self.assertEqual(set(ret), set(self.rpm_units)) self.assertEqual(mock_copy_rpms.call_count, 1) self.assertEqual(set(mock_copy_rpms.call_args[0][0]), set(self.rpm_units)) self.assertEqual(mock_copy_rpms.call_args[0][1], self.conduit) self.assertFalse(mock_copy_rpms.call_args[0][2])
def import_units(self, source_transfer_repo, dest_transfer_repo, import_conduit, config, units=None): source_repo = platform_models.Repository.objects.get( repo_id=source_transfer_repo.id) dest_repo = platform_models.Repository.objects.get( repo_id=dest_transfer_repo.id) return associate.associate(source_repo, dest_repo, import_conduit, config, units)
def test_copy_categories(self, mock_associate_unit, mock_copy_rpms, mock_filter): mock_copy_rpms.return_value = set() self.config.override_config = {constants.CONFIG_RECURSIVE: True} groups_to_copy = model_factory.group_units(2) for group in groups_to_copy: group.metadata['default_package_names'] = [] self.conduit.get_source_units.side_effect = [groups_to_copy, []] ret = associate.associate(self.source_repo, self.dest_repo, self.conduit, self.config, self.category_units) self.assertEqual(set(ret), set(self.category_units) | set(groups_to_copy)) self.assertEqual(mock_associate_unit.call_count, 4) mock_associate_unit.assert_any_call(self.dest_repo, self.conduit, self.category_units[0]) mock_associate_unit.assert_any_call(self.dest_repo, self.conduit, self.category_units[1]) mock_associate_unit.assert_any_call(self.dest_repo, self.conduit, groups_to_copy[0]) mock_associate_unit.assert_any_call(self.dest_repo, self.conduit, groups_to_copy[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 import_units(self, source_repo, dest_repo, import_conduit, config, units=None): return associate.associate(source_repo, dest_repo, import_conduit, config, units)
def import_units(self, source_transfer_repo, dest_transfer_repo, import_conduit, config, units=None): source_repo = platform_models.Repository.objects.get(repo_id=source_transfer_repo.id) dest_repo = platform_models.Repository.objects.get(repo_id=dest_transfer_repo.id) return associate.associate(source_repo, dest_repo, import_conduit, config, units)