Skip to content

Commit

Permalink
Add tests for vendor data in uploaded files.
Browse files Browse the repository at this point in the history
Closes pulp#680

Includes a refactor of existing test in pulp_smash.tests.rpm.cli.test_upload
  • Loading branch information
kdelee committed Jul 10, 2017
1 parent c1281cb commit bd032d7
Show file tree
Hide file tree
Showing 3 changed files with 322 additions and 63 deletions.
38 changes: 36 additions & 2 deletions pulp_smash/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,6 @@
'version': '4.1',
'release': '1',
'arch': 'noarch',
'vendor': None,
'metadata': {
'release': '1',
'license': 'GPLv2',
Expand All @@ -361,6 +360,7 @@
'size': '42',
'sourcerpm': 'bear-4.1-1.src.rpm',
'summary': 'A dummy package of bear',
'vendor': None,
},
})
"""Metadata for an RPM with an associated erratum.
Expand Down Expand Up @@ -395,7 +395,6 @@
'version': '0.1',
'release': '1',
'arch': 'noarch',
'vendor': None,
'metadata': {
'release': '1',
'license': 'GPLv2',
Expand All @@ -405,6 +404,7 @@
'size': '42',
'sourcerpm': 'camel-0.1-1.src.rpm',
'summary': 'A dummy package of camel',
'vendor': None,
},
})

Expand All @@ -417,6 +417,34 @@
)
"""The name of an RPM. See :data:`pulp_smash.constants.RPM2_UNSIGNED_URL`."""

RPM_WITH_VENDOR_DATA = MappingProxyType({
'name': 'rpm-with-vendor',
'epoch': '0',
'version': '1',
'release': '1.fc25',
'arch': 'noarch',
'metadata': {
'release': '1',
'license': 'Public Domain',
'description': 'This RPM has a vendor',
'files': {'dir': [], 'file': []},
'group': None,
'size': None,
'sourcerpm': None,
'summary': None,
'vendor': 'Pulp Fixtures',
},
})

RPM_WITH_VENDOR = '{}-{}{}-{}.{}.rpm'.format(
RPM_WITH_VENDOR_DATA['name'],
RPM_WITH_VENDOR_DATA['epoch'] + '!' if RPM_DATA['epoch'] != '0' else '',
RPM_WITH_VENDOR_DATA['version'],
RPM_WITH_VENDOR_DATA['release'],
RPM_WITH_VENDOR_DATA['arch'],
)
"""The name of an RPM. See :data:`pulp_smash.constants.RPM_WITH_VENDOR_URL`."""

RPM_ALT_LAYOUT_FEED_URL = urljoin(PULP_FIXTURES_BASE_URL, 'rpm-alt-layout/')
"""The URL to a signed RPM repository. See :data:`RPM_SIGNED_URL`."""

Expand Down Expand Up @@ -564,6 +592,12 @@
)
"""The URL to an RPM with non-UTF-8 metadata in its header."""

RPM_WITH_VENDOR_URL = urljoin(
PULP_FIXTURES_BASE_URL,
'rpm-with-vendor/rpm-with-vendor-1-1.fc25.noarch.rpm'
)
"""The URL of an RPM with a specified vendor in its header."""

SRPM = 'test-srpm02-1.0-1.src.rpm'
"""An SRPM file at :data:`pulp_smash.constants.SRPM_SIGNED_FEED_URL`."""

Expand Down
85 changes: 84 additions & 1 deletion pulp_smash/tests/rpm/api_v2/test_upload_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
REPOSITORY_PATH,
RPM,
RPM_DATA,
RPM_WITH_VENDOR_URL,
RPM_WITH_VENDOR_DATA,
RPM_WITH_VENDOR,
RPM_UNSIGNED_URL,
SRPM,
SRPM_UNSIGNED_URL,
Expand Down Expand Up @@ -254,7 +257,8 @@ def verify_repo_search(self, repo):
Verify that only one content unit is in ``repo``, and that several of
its metadata attributes are correct. This test targets `Pulp #2365
<https://pulp.plan.io/issues/2365>`_ and `Pulp #2754
<https://pulp.plan.io/issues/2754>`_
<https://pulp.plan.io/issues/2754>`_ and `Pulp #2781
<https://pulp.plan.io/issues/2781>`_
"""
units = utils.search_units(self.cfg, repo)
self.assertEqual(len(units), 1)
Expand Down Expand Up @@ -332,3 +336,82 @@ def verify_repo_download(self, repo):
)
with self.subTest():
self.assertEqual(self.rpm, response.content)


class UploadRetainsVendorData(utils.BaseAPITestCase):
"""Test whether one can upload, associate and publish RPMs.
The test procedure is as follows:
1. Create a repository.
2. Upload an RPM to the first repository, and publish it.
3. Test that RPM metadata includes all available fields, including vendor.
"""

def test_all(self):
"""Create a pair of RPM repositories."""
if selectors.bug_is_untestable(2781):
raise unittest.SkipTest('https://pulp.plan.io/issues/2781')
rpm = utils.http_get(RPM_WITH_VENDOR_URL)
client = api.Client(self.cfg, api.json_handler)
body = gen_repo()
body['distributors'] = [gen_distributor()]
repo = client.post(REPOSITORY_PATH, body)

# Info about repo distributors is needed when publishing.
repo = client.get(repo['_href'], params={'details': True})
self.addCleanup(client.delete, repo['_href'])
self.addCleanup(client.delete, ORPHANS_PATH)
utils.upload_import_unit(
self.cfg,
rpm,
{'unit_type_id': 'rpm'},
repo,
)
utils.publish_repo(self.cfg, repo)
units = utils.search_units(self.cfg, repo)
with self.subTest(comment='Vendor info present and correct'):
self.assertEqual(
units[0]['metadata']['vendor'],
RPM_WITH_VENDOR_DATA['metadata']['vendor'],
)
# filename and derived attributes
with self.subTest(comment='Filename present and correct'):
self.assertEqual(units[0]['metadata']['filename'], RPM_WITH_VENDOR)
with self.subTest(comment='Epoch present and correct'):
self.assertEqual(
units[0]['metadata']['epoch'],
RPM_WITH_VENDOR_DATA['epoch']
)
with self.subTest(comment='Name present and correct'):
self.assertEqual(
units[0]['metadata']['name'],
RPM_WITH_VENDOR_DATA['name']
)
with self.subTest(comment='Version present and correct'):
self.assertEqual(
units[0]['metadata']['version'],
RPM_WITH_VENDOR_DATA['version']
)
with self.subTest(comment='Release present and correct'):
self.assertEqual(
units[0]['metadata']['release'],
RPM_WITH_VENDOR_DATA['release']
)

# other attributes
with self.subTest(comment='License present and correct'):
self.assertEqual(
units[0]['metadata']['license'],
RPM_WITH_VENDOR_DATA['metadata']['license']
)
with self.subTest(comment='Description present and correct'):
self.assertEqual(
units[0]['metadata']['description'],
RPM_WITH_VENDOR_DATA['metadata']['description'],
)
with self.subTest(comment='File info present and correct'):
self.assertEqual(
units[0]['metadata']['files'],
RPM_WITH_VENDOR_DATA['metadata']['files'],
)
Loading

0 comments on commit bd032d7

Please sign in to comment.