def setUpClass(cls): """Create repos, remotes, and api-clients for all tests.""" cls.cfg = config.get_config() cls.client = ApiClient(configuration=cls.cfg.get_bindings_config()) file_client = gen_file_client() cls.admin_info = { "task_api": TasksApi(cls.client), "file_client": file_client, "remote_api": RemotesFileApi(file_client), "repo_api": RepositoriesFileApi(file_client), } cls.admin_info["a_remote"] = cls.admin_info["remote_api"].create( gen_file_remote(policy="on_demand") ) cls.admin_info["a_repo"] = cls.admin_info["repo_api"].create(gen_repo()) cls.admin_info["sync_data"] = RepositorySyncURL(remote=cls.admin_info["a_remote"].pulp_href) cls.new_user = gen_user() file_client = gen_file_client() cls.user_info = { "task_api": TasksApi(cls.client), "file_client": file_client, "remote_api": RemotesFileApi(file_client), "repo_api": RepositoriesFileApi(file_client), } cls.user_info["a_remote"] = cls.user_info["remote_api"].create( gen_file_remote(policy="on_demand") ) cls.user_info["a_repo"] = cls.user_info["repo_api"].create(gen_repo()) cls.user_info["sync_data"] = RepositorySyncURL(remote=cls.user_info["a_remote"].pulp_href)
def test_on_demand_pypi_full_sync(self): """This test syncs all of PyPi""" repo_api = RepositoriesPythonApi(self.client) remote_api = RemotesPythonApi(self.client) tasks_api = TasksApi(self.core_client) repo = repo_api.create(gen_repo()) self.addCleanup(repo_api.delete, repo.pulp_href) body = gen_python_remote("https://pypi.org", includes=[], policy="on_demand") remote = remote_api.create(body) self.addCleanup(remote_api.delete, remote.pulp_href) # Sync the repository. self.assertEqual(repo.latest_version_href, f"{repo.pulp_href}versions/0/") repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) sync_response = repo_api.sync(repo.pulp_href, repository_sync_data) monitor_task(sync_response.task) repo = repo_api.read(repo.pulp_href) sync_task = tasks_api.read(sync_response.task) time_diff = sync_task.finished_at - sync_task.started_at print("Delete time: {} seconds".format(time_diff.seconds)) self.assertIsNotNone(repo.latest_version_href) # As of August 11 2020, all_packages() returns 253,587 packages, # only 248,677 of them were downloadable self.assertTrue(get_content_summary(repo.to_dict())[PYTHON_CONTENT_NAME] > 245000)
def setUpClass(cls): """Create class-wide variable.""" delete_orphans() rpm_client = gen_rpm_client() cls.tasks_api = TasksApi(core_client) cls.content_api = ContentPackagesApi(rpm_client) cls.file_to_use = os.path.join(RPM_UNSIGNED_FIXTURE_URL, RPM_PACKAGE_FILENAME)
def setUpClass(cls): """Create class-wide variable.""" cls.cfg = config.get_config() cls.client = api.Client(cls.cfg) delete_orphans() cls.rpm_client = gen_rpm_client() cls.tasks_api = TasksApi(core_client) cls.content_api = ContentAdvisoriesApi(cls.rpm_client) cls.bad_file_to_use = os.path.join(RPM_UNSIGNED_FIXTURE_URL, RPM_PACKAGE_FILENAME)
def setUpClass(cls): """Set up class variables.""" cls.cid = str(uuid.uuid4()) cls.cfg = config.get_config() cls.client = api.Client(cls.cfg, api.json_handler) cls.client = ApiClient( configuration=cls.cfg.get_bindings_config(), header_name="Correlation-ID", header_value=cls.cid, ) cls.cli_client = cli.Client(cls.cfg) cls.orphan_api = OrphansApi(cls.client) cls.task_api = TasksApi(cls.client)
def setUpClass(cls): """ Create all the client instances needed to communicate with Pulp. """ configuration = Configuration(**BINDINGS_CONFIGURATION) core_client = CoreApiClient(configuration) file_client = FileApiClient(configuration) migration_client = MigrationApiClient(configuration) # Create api clients for all resource types cls.file_repo_api = RepositoriesFileApi(file_client) cls.file_repo_versions_api = RepositoriesFileVersionsApi(file_client) cls.file_content_api = ContentFilesApi(file_client) cls.tasks_api = TasksApi(core_client) cls.migration_plans_api = MigrationPlansApi(migration_client) set_pulp2_snapshot(name='file_base_4repos')
def setUpClass(cls): """ Create all the client instances needed to communicate with Pulp. """ configuration = Configuration() configuration.username = '******' configuration.password = '******' configuration.host = 'http://pulp' configuration.safe_chars_for_path_param = '/' core_client = CoreApiClient(configuration) file_client = FileApiClient(configuration) migration_client = MigrationApiClient(configuration) # Create api clients for all resource types cls.file_repo_api = RepositoriesFileApi(file_client) cls.file_repo_versions_api = RepositoriesFileVersionsApi(file_client) cls.file_content_api = ContentFilesApi(file_client) cls.tasks_api = TasksApi(core_client) cls.migration_plans_api = MigrationPlansApi(migration_client)
def setUpClass(cls): """Create repos, remotes, and api-clients for all tests.""" cls.cfg = config.get_config() cls.client = ApiClient(configuration=cls.cfg.get_bindings_config()) cls.task_api = TasksApi(cls.client) cls.file_client = gen_file_client() cls.remote_api = RemotesFileApi(cls.file_client) cls.repo_api = RepositoriesFileApi(cls.file_client) cls.good_remote = cls.remote_api.create(gen_file_remote(policy="on_demand")) cls.good_repo = cls.repo_api.create(gen_repo()) cls.good_sync_data = RepositorySyncURL(remote=cls.good_remote.pulp_href) cls.bad_remote = cls.remote_api.create( gen_file_remote( "https://fixtures.pulpproject.org/THEREISNOFILEREPOHERE/", policy="on_demand" ) ) cls.bad_repo = cls.repo_api.create(gen_repo()) cls.bad_sync_data = RepositorySyncURL(remote=cls.bad_remote.pulp_href)
if remote: client.delete(remote["pulp_href"]) if repo: client.delete(repo["pulp_href"]) return client.get(ANSIBLE_ROLE_CONTENT_PATH)["results"] skip_if = partial(selectors.skip_if, exc=unittest.SkipTest) """The ``@skip_if`` decorator, customized for unittest. :func:`pulp_smash.selectors.skip_if` is test runner agnostic. This function is identical, except that ``exc`` has been set to ``unittest.SkipTest``. """ core_client = CoreApiClient(configuration) tasks = TasksApi(core_client) def wait_tasks(): """Polls the Task API until all tasks are in a completed state.""" running_tasks = tasks.list(state="running") while running_tasks.count: sleep(1) running_tasks = tasks.list(state="running") class TestCaseUsingBindings(unittest.TestCase): """A parent TestCase that instantiates the various bindings used throughout tests.""" @classmethod def setUpClass(cls): """Create class-wide variables."""
RepositoriesAptApi, ) skip_if = partial(selectors.skip_if, exc=SkipTest) # pylint:disable=invalid-name """The ``@skip_if`` decorator, customized for unittest. :func:`pulp_smash.selectors.skip_if` is test runner agnostic. This function is identical, except that ``exc`` has been set to ``unittest.SkipTest``. """ cfg = config.get_config() configuration = cfg.get_bindings_config() core_client = CoreApiClient(configuration) artifact_api = ArtifactsApi(core_client) task_api = TasksApi(core_client) signing_service_api = SigningServicesApi(core_client) deb_client = DebApiClient(configuration) deb_generic_content_api = ContentGenericContentsApi(deb_client) deb_package_api = ContentPackagesApi(deb_client) deb_remote_api = RemotesAptApi(deb_client) deb_repository_api = RepositoriesAptApi(deb_client) deb_apt_publication_api = PublicationsAptApi(deb_client) deb_verbatim_publication_api = PublicationsVerbatimApi(deb_client) deb_distribution_api = DistributionsAptApi(deb_client) def set_up_module(): """Skip tests Pulp 3 isn't under test or if pulp_deb isn't installed.""" require_pulp_3(SkipTest)
from unittest import TestCase from time import sleep from pulpcore.client.pulpcore import ApiClient, TasksApi from pulp_smash.api import _get_sleep_time from pulp_smash.config import get_config cfg = get_config() SLEEP_TIME = _get_sleep_time(cfg) configuration = cfg.get_bindings_config() pulpcore_client = ApiClient(configuration) tasks = TasksApi(pulpcore_client) class PulpTestCase(TestCase): """Pulp customized test case.""" def doCleanups(self): """ Execute all cleanup functions and waits the deletion tasks. Normally called for you after tearDown. """ output = super().doCleanups() running_tasks = tasks.list(state="running", name__contains="delete") while running_tasks.count: sleep(SLEEP_TIME) running_tasks = tasks.list(state="running", name__contains="delete") return output