def test_01_create_publisher(self):
     """Create a publisher."""
     body = gen_plugin_template_publisher()
     type(self).publisher = self.client.post(PLUGIN_TEMPLATE_PUBLISHER_PATH, body)
     for key, val in body.items():
         with self.subTest(key=key):
             self.assertEqual(self.publisher[key], val)
 def test_04_fully_update(self):
     """Update a publisher using HTTP PUT."""
     body = gen_plugin_template_publisher()
     self.client.put(self.publisher['_href'], body)
     type(self).publisher = self.client.get(self.publisher['_href'])
     for key, val in body.items():
         with self.subTest(key=key):
             self.assertEqual(self.publisher[key], val)
Exemplo n.º 3
0
    def test_all(self):
        """Test whether a particular repository version can be published.

        1. Create a repository with at least 2 repository versions.
        2. Create a publication by supplying the latest ``repository_version``.
        3. Assert that the publication ``repository_version`` attribute points
           to the latest repository version.
        4. Create a publication by supplying the non-latest ``repository_version``.
        5. Assert that the publication ``repository_version`` attribute points
           to the supplied repository version.
        6. Assert that an exception is raised when providing two different
           repository versions to be published at same time.
        """
        cfg = config.get_config()
        client = api.Client(cfg, api.json_handler)

        body = gen_plugin_template_remote()
        remote = client.post(PLUGIN_TEMPLATE_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote['_href'])

        repo = client.post(REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo['_href'])

        sync(cfg, remote, repo)

        publisher = client.post(PLUGIN_TEMPLATE_PUBLISHER_PATH, gen_plugin_template_publisher())
        self.addCleanup(client.delete, publisher['_href'])

        # Step 1
        repo = client.post(REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo['_href'])
        for plugin_template_content in client.get(PLUGIN_TEMPLATE_CONTENT_PATH)['results']:
            client.post(
                repo['_versions_href'],
                {'add_content_units': [plugin_template_content['_href']]}
            )
        version_hrefs = tuple(ver['_href'] for ver in get_versions(repo))
        non_latest = choice(version_hrefs[:-1])

        # Step 2
        publication = publish(cfg, publisher, repo)

        # Step 3
        self.assertEqual(publication['repository_version'], version_hrefs[-1])

        # Step 4
        publication = publish(cfg, publisher, repo, non_latest)

        # Step 5
        self.assertEqual(publication['repository_version'], non_latest)

        # Step 6
        with self.assertRaises(HTTPError):
            body = {
                'repository': repo['_href'],
                'repository_version': non_latest
            }
            client.post(urljoin(publisher['_href'], 'publish/'), body)
    def test_02_create_same_name(self):
        """Try to create a second publisher with an identical name.

        See: `Pulp Smash #1055
        <https://github.com/PulpQE/pulp-smash/issues/1055>`_.
        """
        body = gen_plugin_template_publisher()
        body['name'] = self.publisher['name']
        with self.assertRaises(HTTPError):
            self.client.post(PLUGIN_TEMPLATE_PUBLISHER_PATH, body)
 def setUpClass(cls):
     """Create class-wide variables."""
     cls.cfg = config.get_config()
     cls.client = api.Client(cls.cfg, api.page_handler)
     cls.remote = {}
     cls.publication = {}
     cls.publisher = {}
     cls.repo = {}
     try:
         cls.repo.update(cls.client.post(REPO_PATH, gen_repo()))
         body = gen_plugin_template_remote()
         cls.remote.update(
             cls.client.post(PLUGIN_TEMPLATE_REMOTE_PATH, body))
         cls.publisher.update(
             cls.client.post(PLUGIN_TEMPLATE_PUBLISHER_PATH,
                             gen_plugin_template_publisher()))
         sync(cls.cfg, cls.remote, cls.repo)
     except Exception:
         cls.tearDownClass()
         raise
Exemplo n.º 6
0
    def test_all(self):
        """Verify whether content served by pulp can be downloaded.

        The process of publishing content is more involved in Pulp 3 than it
        was under Pulp 2. Given a repository, the process is as follows:

        1. Create a publication from the repository. (The latest repository
           version is selected if no version is specified.) A publication is a
           repository version plus metadata.
        2. Create a distribution from the publication. The distribution defines
           at which URLs a publication is available, e.g.
           ``http://example.com/content/foo/`` and
           ``http://example.com/content/bar/``.

        Do the following:

        1. Create, populate, publish, and distribute a repository.
        2. Select a random content unit in the distribution. Download that
           content unit from Pulp, and verify that the content unit has the
           same checksum when fetched directly from Pulp-Fixtures.

        This test targets the following issues:

        * `Pulp #2895 <https://pulp.plan.io/issues/2895>`_
        * `Pulp Smash #872 <https://github.com/PulpQE/pulp-smash/issues/872>`_
        """
        cfg = config.get_config()
        client = api.Client(cfg, api.json_handler)

        repo = client.post(REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo['_href'])

        body = gen_plugin_template_remote()
        remote = client.post(PLUGIN_TEMPLATE_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote['_href'])

        sync(cfg, remote, repo)
        repo = client.get(repo['_href'])

        # Create a publisher.
        publisher = client.post(PLUGIN_TEMPLATE_PUBLISHER_PATH, gen_plugin_template_publisher())
        self.addCleanup(client.delete, publisher['_href'])

        # Create a publication.
        publication = publish(cfg, publisher, repo)
        self.addCleanup(client.delete, publication['_href'])

        # Create a distribution.
        body = gen_distribution()
        body['publication'] = publication['_href']
        distribution = client.post(DISTRIBUTION_PATH, body)
        self.addCleanup(client.delete, distribution['_href'])

        # Pick a content unit, and download it from both Pulp Fixtures…
        unit_path = choice(get_plugin_template_content_paths(repo))
        fixtures_hash = hashlib.sha256(
            utils.http_get(urljoin(PLUGIN_TEMPLATE_FIXTURE_URL, unit_path))
        ).hexdigest()

        # …and Pulp.
        client.response_handler = api.safe_handler

        unit_url = cfg.get_hosts('api')[0].roles['api']['scheme']
        unit_url += '://' + distribution['base_url'] + '/'
        unit_url = urljoin(unit_url, unit_path)

        pulp_hash = hashlib.sha256(client.get(unit_url).content).hexdigest()
        self.assertEqual(fixtures_hash, pulp_hash)