From c1281cbe1517b729eef84b2ac1b31aac6c42c056 Mon Sep 17 00:00:00 2001 From: Elijah DeLee Date: Thu, 6 Jul 2017 16:04:11 -0400 Subject: [PATCH] Add tests that specify checksumtype in drpm upload Includes tests in both API and CLI Closes #585 --- .../tests/rpm/api_v2/test_upload_publish.py | 51 ++++++++++++++++ pulp_smash/tests/rpm/cli/test_upload.py | 59 ++++++++++++++++++- 2 files changed, 109 insertions(+), 1 deletion(-) diff --git a/pulp_smash/tests/rpm/api_v2/test_upload_publish.py b/pulp_smash/tests/rpm/api_v2/test_upload_publish.py index 3db093ba5..021155e38 100644 --- a/pulp_smash/tests/rpm/api_v2/test_upload_publish.py +++ b/pulp_smash/tests/rpm/api_v2/test_upload_publish.py @@ -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 `_ caused + uploading to fail when "checksumtype" was specified. + + This test case targets `Pulp Smash #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. diff --git a/pulp_smash/tests/rpm/cli/test_upload.py b/pulp_smash/tests/rpm/cli/test_upload.py index 360945279..588d25f27 100644 --- a/pulp_smash/tests/rpm/cli/test_upload.py +++ b/pulp_smash/tests/rpm/cli/test_upload.py @@ -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 - `_ + `_ and + `Pulp Smash #585 `_ """ def test_upload(self): @@ -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)