Skip to content

Commit

Permalink
Add tests that specify checksumtype in drpm upload
Browse files Browse the repository at this point in the history
Includes tests in both API and CLI

Closes pulp#585
  • Loading branch information
kdelee committed Jul 7, 2017
1 parent ef3cbb5 commit c1281cb
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 1 deletion.
51 changes: 51 additions & 0 deletions pulp_smash/tests/rpm/api_v2/test_upload_publish.py
Expand Up @@ -76,6 +76,57 @@ def test_drpm_file_name_is_correct(self):
)


class UploadDrpmTestCaseWithCheckSumType(utils.BaseAPITestCase):
"""Test whether one can upload a DRPM into a repository.
`Pulp issue #2627 <https://https://pulp.plan.io/issues/2627>`_ caused
uploading to fail when "checksumtype" was specified.
This test case targets `Pulp Smash #585
<https://github.com/PulpQE/pulp-smash/issues/585>`_
"""

@classmethod
def setUpClass(cls):
"""Import a DRPM into a repository and search it for content units.
Specifically, this method does the following:
1. Create a yum repository.
2. Upload a DRPM into the repository with "checksumtype" set to
"sha256"
3. Search for all content units in the repository.
"""
super(UploadDrpmTestCaseWithCheckSumType, cls).setUpClass()

def test_all(self):
"""Test that uploading DRPM with checksumtype specified works."""
if selectors.bug_is_untestable(1806, self.cfg.version):
raise unittest.SkipTest('https://pulp.plan.io/issues/1806')
if selectors.bug_is_untestable(2627, self.cfg.version):
raise unittest.SkipTest('https://pulp.plan.io/issues/2627')
client = api.Client(self.cfg)
repo = client.post(REPOSITORY_PATH, gen_repo()).json()
self.addCleanup(client.delete, repo['_href'])
drpm = utils.http_get(DRPM_UNSIGNED_URL)
utils.upload_import_unit(
self.cfg,
drpm,
{
'unit_type_id': 'drpm',
'unit_metadata': {'checksumtype': 'sha256'},
},
repo,
)
units = utils.search_units(self.cfg, repo, {})
self.assertEqual(len(units), 1, units)
# Test if DRPM extracted correct metadata for creating filename.
self.assertEqual(
units[0]['metadata']['filename'],
DRPM,
)


class UploadSrpmTestCase(utils.BaseAPITestCase):
"""Test whether one can upload a SRPM into a repository.
Expand Down
59 changes: 58 additions & 1 deletion pulp_smash/tests/rpm/cli/test_upload.py
Expand Up @@ -18,7 +18,8 @@ class UploadDrpmTestCase(unittest.TestCase):
"""Test whether one can upload a DRPM into a repository.
This test case targets `Pulp Smash #336
<https://github.com/PulpQE/pulp-smash/issues/336>`_
<https://github.com/PulpQE/pulp-smash/issues/336>`_ and
`Pulp Smash #585 <https://github.com/PulpQE/pulp-smash/issues/585>`_
"""

def test_upload(self):
Expand Down Expand Up @@ -75,3 +76,59 @@ def test_upload(self):
.format(repo_id, drpm_file).split()
)
self.assertIn('No files eligible for upload', proc.stdout)

def test_upload_with_checksumtype(self):
"""Create a repository and upload DRPMs into it.
Specifically, do the following:
1. Create a yum repository.
2. Download a DRPM file.
3. Upload the DRPM into it specifying the checksumtype
4. Use ``pulp-admin`` to verify its presence
in the repository.
5. Upload the same DRPM into the same repository, and use the
``--skip-existing`` flag during the upload. Verify that Pulp skips
the upload.
"""
if selectors.bug_is_untestable(2627, config.get_config().version):
self.skipTest('https://pulp.plan.io/issues/2627')

# Create a repository
client = cli.Client(config.get_config())
repo_id = utils.uuid4()
client.run(
'pulp-admin rpm repo create --repo-id {}'.format(repo_id).split()
)
self.addCleanup(
client.run,
'pulp-admin rpm repo delete --repo-id {}'.format(repo_id).split()
)

# Create a temporary directory, and download a DRPM file into it
temp_dir = client.run('mktemp --directory'.split()).stdout.strip()
self.addCleanup(client.run, 'rm -rf {}'.format(temp_dir).split())
drpm_file = os.path.join(temp_dir, os.path.split(DRPM)[-1])
client.run(
'curl -o {} {}'.format(drpm_file, DRPM_UNSIGNED_URL).split()
)

# Upload the DRPM into the repository using checksum-type
client.run(
'pulp-admin rpm repo uploads drpm --repo-id {} --file {} '
'--checksum-type sha256'
.format(repo_id, drpm_file).split()
)
proc = client.run(
'pulp-admin rpm repo content drpm --repo-id {} --fields filename'
.format(repo_id).split()
)
self.assertEqual(proc.stdout.split('Filename:')[1].strip(), DRPM)

# Upload the DRPM into the repository. Pass --skip-existing.
proc = client.run(
'pulp-admin rpm repo uploads drpm --repo-id {} --file {} '
'--skip-existing'
.format(repo_id, drpm_file).split()
)
self.assertIn('No files eligible for upload', proc.stdout)

0 comments on commit c1281cb

Please sign in to comment.