Skip to content

Commit

Permalink
Merge pull request #132 from daviddavis/issue4720
Browse files Browse the repository at this point in the history
Update tests since file publishers were removed
  • Loading branch information
daviddavis committed May 14, 2019
2 parents 15e28bf + d4d5828 commit c71ec98
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 107 deletions.
8 changes: 2 additions & 6 deletions docs/workflows/exposing-content.rst
Expand Up @@ -124,13 +124,9 @@ content in it::
http POST ':24817'$REMOTE_HREF'sync/' repository=$REPO_HREF
sleep 3 # wait for the sync to happen

# Create a FilePublisher
http POST :24817/pulp/api/v3/publishers/file/file/ name=bar
export PUBLISHER_HREF=$(http :24817/pulp/api/v3/publishers/file/file/ | jq -r '.results[] | select(.name == "bar") | ._href')

# Create a Publication
http POST :24817/pulp/api/v3/publications/file/file/ repository=$REPO_HREF publisher=$PUBLISHER_HREF
export PUBLICATION_HREF=$(http :24817/pulp/api/v3/publications/file/file/ | jq -r --arg PUBLISHER_HREF "$PUBLISHER_HREF" '.results[] | select(.publisher==$PUBLISHER_HREF) | ._href')
http POST :24817/pulp/api/v3/publications/file/file/ repository=$REPO_HREF
export PUBLICATION_HREF=$(http :24817/pulp/api/v3/publications/file/file/ | jq -r '.results[0] | ._href')

Now with your :term:`Publication` saved as ``PUBLICATION_HREF`` you can have the
:term:`Distribution` serve it at base_path ``bar``::
Expand Down
3 changes: 0 additions & 3 deletions pulpcore/tests/functional/api/using_plugin/constants.py
Expand Up @@ -6,7 +6,6 @@
from pulp_smash.pulp3.constants import (
BASE_DISTRIBUTION_PATH,
BASE_PUBLICATION_PATH,
BASE_PUBLISHER_PATH,
BASE_REMOTE_PATH,
CONTENT_PATH
)
Expand All @@ -22,8 +21,6 @@

FILE_PUBLICATION_PATH = urljoin(BASE_PUBLICATION_PATH, 'file/file/')

FILE_PUBLISHER_PATH = urljoin(BASE_PUBLISHER_PATH, 'file/file/')

FILE_FIXTURE_URL = urljoin(PULP_FIXTURES_BASE_URL, 'file/')
"""The URL to a file repository."""

Expand Down
Expand Up @@ -16,7 +16,6 @@
delete_orphans,
download_content_unit,
gen_distribution,
gen_publisher,
gen_repo,
get_content,
sync,
Expand All @@ -26,7 +25,6 @@
FILE_CONTENT_NAME,
FILE_DISTRIBUTION_PATH,
FILE_FIXTURE_URL,
FILE_PUBLISHER_PATH,
FILE_REMOTE_PATH,
)
from pulpcore.tests.functional.api.using_plugin.utils import (
Expand Down Expand Up @@ -72,10 +70,7 @@ def test_content_remote_delete(self):
sync(cfg, remote, repo)
repo = client.get(repo['_href'])

publisher = client.post(FILE_PUBLISHER_PATH, gen_publisher())
self.addCleanup(client.delete, publisher['_href'])

publication = create_file_publication(cfg, repo, publisher=publisher)
publication = create_file_publication(cfg, repo)
self.addCleanup(client.delete, publication['_href'])

# Delete the remote.
Expand Down
Expand Up @@ -6,15 +6,13 @@
from pulp_smash.pulp3.constants import REPO_PATH
from pulp_smash.pulp3.utils import (
delete_orphans,
gen_publisher,
gen_remote,
gen_repo,
sync,
)

from pulpcore.tests.functional.api.using_plugin.constants import (
FILE_FIXTURE_MANIFEST_URL,
FILE_PUBLISHER_PATH,
FILE_REMOTE_PATH,
)
from pulpcore.tests.functional.api.using_plugin.utils import ( # noqa:F401
Expand Down Expand Up @@ -64,10 +62,7 @@ def test_all(self):
repo = client.post(REPO_PATH, gen_repo())
self.addCleanup(client.delete, repo['_href'])

publisher = client.post(FILE_PUBLISHER_PATH, gen_publisher())
self.addCleanup(client.delete, publisher['_href'])

for _ in range(2):
sync(cfg, remote, repo)
repo = client.get(repo['_href'])
create_file_publication(cfg, repo, publisher=publisher)
create_file_publication(cfg, repo)
Expand Up @@ -8,7 +8,6 @@
from pulp_smash.pulp3.constants import REPO_PATH
from pulp_smash.pulp3.utils import (
gen_distribution,
gen_publisher,
gen_remote,
gen_repo,
get_added_content,
Expand All @@ -19,7 +18,6 @@
FILE_CONTENT_NAME,
FILE_DISTRIBUTION_PATH,
FILE_FIXTURE_MANIFEST_URL,
FILE_PUBLISHER_PATH,
FILE_REMOTE_PATH
)
from pulpcore.tests.functional.api.using_plugin.utils import ( # noqa:F401
Expand All @@ -41,7 +39,7 @@ def test_all(self):
Do the following:
1. Create a repository that has at least one repository version.
2. Create a publisher, and publication.
2. Create a publication.
3. Create 2 distributions - using the same publication. Those
distributions will have different ``base_path``.
4. Assert that distributions have the same publication.
Expand All @@ -65,10 +63,7 @@ def test_all(self):
sync(cfg, remote, repo)
repo = client.get(repo['_href'])

publisher = client.post(FILE_PUBLISHER_PATH, gen_publisher())
self.addCleanup(client.delete, publisher['_href'])

publication = create_file_publication(cfg, repo, publisher=publisher)
publication = create_file_publication(cfg, repo)
self.addCleanup(client.delete, publication['_href'])

distributions = []
Expand Down
Expand Up @@ -9,7 +9,6 @@
from pulp_smash.pulp3.constants import REPO_PATH
from pulp_smash.pulp3.utils import (
gen_distribution,
gen_publisher,
gen_repo,
sync
)
Expand All @@ -18,7 +17,6 @@
from pulpcore.tests.functional.api.using_plugin.constants import (
FILE_DISTRIBUTION_PATH,
FILE_PUBLICATION_PATH,
FILE_PUBLISHER_PATH,
FILE_REMOTE_PATH
)
from pulpcore.tests.functional.api.using_plugin.utils import (
Expand All @@ -39,15 +37,11 @@ def setUpClass(cls):
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_file_remote()
cls.remote.update(cls.client.post(FILE_REMOTE_PATH, body))
cls.publisher.update(
cls.client.post(FILE_PUBLISHER_PATH, gen_publisher())
)
sync(cls.cfg, cls.remote, cls.repo)
except Exception:
cls.tearDownClass()
Expand All @@ -56,14 +50,14 @@ def setUpClass(cls):
@classmethod
def tearDownClass(cls):
"""Clean class-wide variables."""
for resource in (cls.remote, cls.publisher, cls.repo):
for resource in (cls.remote, cls.repo):
if resource:
cls.client.delete(resource['_href'])

def test_01_create_file_publication(self):
"""Create a publication."""
self.publication.update(
create_file_publication(self.cfg, self.repo, publisher=self.publisher)
create_file_publication(self.cfg, self.repo)
)

@skip_if(bool, 'publication', False)
Expand All @@ -80,7 +74,7 @@ def test_02_read_publication_with_specific_fields(self):
Permutate field list to ensure different combinations on result.
"""
fields = ('_href', '_created', 'distributions', 'publisher')
fields = ('_href', '_created', 'distributions')
for field_pair in permutations(fields, 2):
# ex: field_pair = ('_href', '_created)
with self.subTest(field_pair=field_pair):
Expand Down Expand Up @@ -111,17 +105,6 @@ def test_02_read_publications(self):
with self.subTest(key=key):
self.assertEqual(publications[0][key], val)

@skip_if(bool, 'publication', False)
def test_03_read_publications(self):
"""Read a publication by its publisher."""
publications = self.client.get(FILE_PUBLICATION_PATH, params={
'publisher': self.publisher['_href']
})
self.assertEqual(len(publications), 1, publications)
for key, val in self.publication.items():
with self.subTest(key=key):
self.assertEqual(publications[0][key], val)

@skip_if(bool, 'publication', False)
def test_04_read_publications(self):
"""Read a publication by its created time."""
Expand Down Expand Up @@ -163,12 +146,11 @@ def test_06_publication_create_order(self):
"""
# Create more 2 publications for the same repo
for _ in range(2):
create_file_publication(self.cfg, self.repo, publisher=self.publisher)
create_file_publication(self.cfg, self.repo)

# Read publications
publications = self.client.get(
FILE_PUBLICATION_PATH,
params={'publisher': self.publisher['_href']}
FILE_PUBLICATION_PATH
)
self.assertEqual(len(publications), 3)

Expand Down Expand Up @@ -196,14 +178,3 @@ def test_negative_create_file_remote_with_invalid_parameter(self):
)
assert response.status_code == 400
assert response.json()['foo'] == ['Unexpected field']

def test_negative_create_file_publisher_with_invalid_parameter(self):
"""Attempt to create file publisher passing invalid parameter.
Assert response returns an error 400 including ["Unexpected field"].
"""
response = api.Client(self.cfg, api.echo_handler).post(
FILE_PUBLISHER_PATH, gen_publisher(foo='bar')
)
assert response.status_code == 400
assert response.json()['foo'] == ['Unexpected field']
Expand Up @@ -12,7 +12,6 @@
from pulp_smash.pulp3.utils import (
delete_orphans,
delete_version,
gen_publisher,
gen_repo,
get_added_content,
get_added_content_summary,
Expand All @@ -32,7 +31,6 @@
FILE_FIXTURE_MANIFEST_URL,
FILE_FIXTURE_SUMMARY,
FILE_LARGE_FIXTURE_MANIFEST_URL,
FILE_PUBLISHER_PATH,
FILE_REMOTE_PATH,
)
from pulpcore.tests.functional.api.using_plugin.utils import (
Expand Down Expand Up @@ -367,11 +365,7 @@ def test_delete_publication(self):
Delete a repository version, and verify the associated publication is
also deleted.
"""
publisher = self.client.post(FILE_PUBLISHER_PATH, gen_publisher())
self.addCleanup(self.client.delete, publisher['_href'])

publication = create_file_publication(
self.cfg, self.repo, publisher=publisher)
publication = create_file_publication(self.cfg, self.repo)
delete_version(self.repo)

with self.assertRaises(HTTPError):
Expand Down
42 changes: 9 additions & 33 deletions pulpcore/tests/functional/api/using_plugin/test_unlinking_repo.py
@@ -1,12 +1,11 @@
# coding=utf-8
"""Tests that perform action over remotes and publishers."""
"""Tests that perform action over remotes"""

import unittest

from pulp_smash import api, config
from pulp_smash.pulp3.constants import REPO_PATH
from pulp_smash.pulp3.utils import (
gen_publisher,
gen_repo,
get_content,
sync,
Expand All @@ -15,49 +14,39 @@
from pulpcore.tests.functional.api.using_plugin.constants import (
FILE_CONTENT_NAME,
FILE_REMOTE_PATH,
FILE_PUBLISHER_PATH
)
from pulpcore.tests.functional.api.using_plugin.utils import (
create_file_publication,
gen_file_remote
)
from pulpcore.tests.functional.api.using_plugin.utils import gen_file_remote
from pulpcore.tests.functional.api.using_plugin.utils import set_up_module as setUpModule # noqa


class RemotesPublishersTestCase(unittest.TestCase):
"""Verify publisher and remote can be used with different repos."""
class RemotesTestCase(unittest.TestCase):
"""Verify remotes can be used with different repos."""

def test_all(self):
"""Verify publisher and remote can be used with different repos.
"""Verify remotes can be used with different repos.
This test explores the design choice stated in `Pulp #3341`_ that
remove the FK from publishers and remotes to repository.
Allowing remotes and publishers to be used with different
remove the FK from remotes to repository.
Allowing remotes to be used with different
repositories.
.. _Pulp #3341: https://pulp.plan.io/issues/3341
Do the following:
1. Create a remote, and a publisher.
1. Create a remote.
2. Create 2 repositories.
3. Sync both repositories using the same remote.
4. Assert that the two repositories have the same contents.
5. Publish both repositories using the same publisher.
6. Assert that each generated publication has the same publisher, but
are associated with different repositories.
"""
cfg = config.get_config()

# Create a remote and publisher.
# Create a remote.
client = api.Client(cfg, api.json_handler)
body = gen_file_remote()
remote = client.post(FILE_REMOTE_PATH, body)
self.addCleanup(client.delete, remote['_href'])

publisher = client.post(FILE_PUBLISHER_PATH, gen_publisher())
self.addCleanup(client.delete, publisher['_href'])

# Create and sync repos.
repos = []
for _ in range(2):
Expand All @@ -74,16 +63,3 @@ def test_all(self):
{content['_href'] for content in contents[0]},
{content['_href'] for content in contents[1]},
)

# Publish repositories.
publications = []
for repo in repos:
publications.append(create_file_publication(cfg, repo, publisher=publisher))
self.assertEqual(
publications[0]['publisher'],
publications[1]['publisher']
)
self.assertNotEqual(
publications[0]['repository_version'],
publications[1]['repository_version']
)
6 changes: 1 addition & 5 deletions pulpcore/tests/functional/api/using_plugin/utils.py
Expand Up @@ -72,14 +72,13 @@ def gen_file_remote(url=None, **kwargs):
return gen_remote(url, **kwargs)


def create_file_publication(cfg, repo, version_href=None, publisher=None):
def create_file_publication(cfg, repo, version_href=None):
"""Create a file publication
:param pulp_smash.config.PulpSmashConfig cfg: Information about the Pulp
host.
:param repo: A dict of information about the repository.
:param version_href: A href for the repo version to be published.
:param publisher: A dict of publisher info to use to publish.
:returns: A publication. A dict of information about the just created
publication.
"""
Expand All @@ -88,9 +87,6 @@ def create_file_publication(cfg, repo, version_href=None, publisher=None):
else:
body = {"repository": repo["_href"]}

if publisher:
body['publisher'] = publisher['_href']

client = api.Client(cfg, api.json_handler)
call_report = client.post(FILE_PUBLICATION_PATH, body)
tasks = tuple(api.poll_spawned_tasks(cfg, call_report))
Expand Down

0 comments on commit c71ec98

Please sign in to comment.