def setUp(self): super(Migration0004Tests, self).setUp() # Special way to import modules that start with a number self.migration = _import_all_the_way( 'pulp_rpm.plugins.migrations.0004_pkg_group_category_repoid') factory.initialize() types_db.update_database([TYPE_DEF_GROUP, TYPE_DEF_CATEGORY]) # Create the repositories necessary for the tests self.source_repo_id = 'source-repo' # where units were copied from with the bad code self.dest_repo_id = 'dest-repo' # where bad units were copied to source_repo = Repo(self.source_repo_id, '') Repo.get_collection().insert(source_repo, safe=True) dest_repo = Repo(self.dest_repo_id, '') Repo.get_collection().insert(dest_repo, safe=True) source_importer = RepoImporter(self.source_repo_id, 'yum_importer', 'yum_importer', {}) RepoImporter.get_collection().insert(source_importer, safe=True) dest_importer = RepoImporter(self.dest_repo_id, 'yum_importer', 'yum_importer', {}) RepoImporter.get_collection().insert(dest_importer, safe=True)
def create_repo(self, repo_id, display_name=None, description=None, notes=None): """ Creates a new Pulp repository that is not associated with any importers or distributors (those are added later through separate calls). :param repo_id: unique identifier for the repo :type repo_id: str :param display_name: user-friendly name for the repo :type display_name: str :param description: user-friendly text describing the repo's contents :type description: str :param notes: key-value pairs to programmatically tag the repo :type notes: dict :raise DuplicateResource: if there is already a repo with the requested ID :raise InvalidValue: if any of the fields are unacceptable """ existing_repo = Repo.get_collection().find_one({'id': repo_id}) if existing_repo is not None: raise DuplicateResource(repo_id) if repo_id is None or not is_repo_id_valid(repo_id): raise InvalidValue(['repo_id']) if notes is not None and not isinstance(notes, dict): raise InvalidValue(['notes']) # Use the ID for the display name if one was not specified display_name = display_name or repo_id # Creation create_me = Repo(repo_id, display_name, description, notes) Repo.get_collection().save(create_me, safe=True) # Retrieve the repo to return the SON object created = Repo.get_collection().find_one({'id': repo_id}) return created
def _generate_repo(self, repo_id): repo_model = Repo(repo_id, repo_id) self.repos_collection.insert(repo_model) return self.repos_collection.find_one({'id': repo_id})