def test_custom_metadata_import_units(self): importer = YumImporter() src_repo = self._mock_repo("test-presto-delta-metadata-source") dst_repo = self._mock_repo("test-presto-delta-metadata-destination") source_units = self._test_drpm_repo_units() import_unit_conduit = mock_conduits.import_unit_conduit(dst_repo.working_dir, source_units=source_units) config = mock_conduits.plugin_call_config(copy_children=False) importer.import_units(src_repo, dst_repo, import_unit_conduit, config) # make sure the metadata unit was imported criteria = UnitAssociationCriteria(type_ids=[TYPE_ID_YUM_REPO_METADATA_FILE]) metadata_units = import_unit_conduit.get_units(criteria) self.assertEqual(len(metadata_units), 1) unit = metadata_units[0] self.assertEqual(unit.type_id, TYPE_ID_YUM_REPO_METADATA_FILE) self.assertEqual(unit.unit_key["data_type"], "prestodelta") # make sure the unit was uniquely copied prestodelta_path = os.path.join(dst_repo.working_dir, dst_repo.id, "prestodelta.xml.gz") self.assertTrue(os.path.exists(prestodelta_path), prestodelta_path)
def test_custom_metadata_publish(self): distributor = YumDistributor() repo = self._mock_repo('test-presto-delta-metadata') repo_units = self._test_drpm_repo_units() publish_conduit = mock_conduits.repo_publish_conduit(existing_units=repo_units) config = mock_conduits.plugin_call_config(http_publish_dir=self.content_dir, relative_url='', http=True, https=False) distributor.publish_repo(repo, publish_conduit, config) # make sure the metadata unit was published criteria = UnitAssociationCriteria(type_ids=[TYPE_ID_YUM_REPO_METADATA_FILE]) metadata_units = publish_conduit.get_units(criteria) self.assertEqual(len(metadata_units), 1) unit = metadata_units[0] self.assertEqual(unit.type_id, TYPE_ID_YUM_REPO_METADATA_FILE) self.assertEqual(unit.unit_key['data_type'], 'prestodelta') # make sure the file was copied into place repodata_path = os.path.join(self.content_dir, repo.id, 'repodata') prestodelta_files = glob.glob(repodata_path + '/*prestodelta*') self.assertEqual(len(prestodelta_files), 1) prestodelta_path = os.path.join(repodata_path, prestodelta_files[0]) self.assertTrue(os.path.exists(prestodelta_path))
def test_foo(self, _plugin_api, _get_db, _objects, _repo_controller): _plugin_api.get_unit_model_by_id.return_value = models.PackageGroup collection = _get_db.return_value.__getitem__.return_value collection.save.side_effect = NotUniqueError() existing_unit = _objects.filter.return_value.first.return_value repo_id = 'test-upload-unit' repo = mock.Mock(spec=Repository) repo.id = repo_id repo.working_dir = os.path.join(self.root_dir, 'working', repo_id) transfer_repo = mock.Mock(repo_obj=repo) importer = YumImporter() conduit = mock_conduits.import_unit_conduit(repo.working_dir) config = mock_conduits.plugin_call_config(copy_children=False) unit_key = dict(repo_id=repo_id, package_group_id="foo") pkgs = ['a', 'b'] now = 1234567890.123 unit_metadata = dict(mandatory_package_names=pkgs, _last_updated=now) type_id = "package_group" file_path = None importer.upload_unit(transfer_repo, type_id, unit_key, unit_metadata, file_path, conduit, config) _repo_controller.associate_single_unit.assert_called_once_with( repo, existing_unit) self.assertEquals(pkgs, existing_unit.mandatory_package_names)
def test_custom_metadata_import_units(self, mock_associate): importer = YumImporter() src_repo = self._mock_repo('test-presto-delta-metadata-source') dst_repo = self._mock_repo('test-presto-delta-metadata-destination') import_unit_conduit = mock_conduits.import_unit_conduit(dst_repo.working_dir) config = mock_conduits.plugin_call_config(copy_children=False) importer.import_units(src_repo, dst_repo, import_unit_conduit, config) mock_associate.assert_called_once_with(src_repo, dst_repo, import_unit_conduit, config, None)
def test_custom_metadata_sync(self): importer = YumImporter() repo = self._mock_repo('test-presto-delta-metadata') sync_conduit = mock_conduits.repo_sync_conduit(self.content_dir, repo_id=repo.id) config = mock_conduits.plugin_call_config( **{importer_constants.KEY_FEED:TEST_DRPM_REPO_FEED, importer_constants.KEY_MAX_DOWNLOADS:1}) importer.sync_repo(repo, sync_conduit, config) # make sure the unit was synced criteria = UnitAssociationCriteria(type_ids=[TYPE_ID_YUM_REPO_METADATA_FILE]) metadata_units = sync_conduit.get_units(criteria) self.assertEqual(len(metadata_units), 1) unit = metadata_units[0] self.assertEqual(unit.type_id, TYPE_ID_YUM_REPO_METADATA_FILE) self.assertEqual(unit.unit_key['data_type'], 'prestodelta')