def test_publish_to_dir(self): """Publish the repository to a directory on the Pulp server. gerify that :data:`pulp_smash.constants.RPM` is present and has a correct checksum. This test is skipped if selinux is installed and enabled on the target system an `Pulp issue 616 <https://pulp.plan.io/issues/616>`_ is open. """ export_dir = self.publish_to_dir( self.repo['_href'], self.distributor['id'], ) path = os.path.join( export_dir, self.distributor['config']['relative_url'], ) if self.cfg.pulp_version >= Version('2.12'): path = os.path.join(path, 'Packages', RPM[0], RPM) else: path = os.path.join(path, RPM) actual = cli.Client(self.cfg).run( ('sha256sum', path)).stdout.strip().split()[0] expect = utils.get_sha256_checksum(RPM_SIGNED_URL) self.assertEqual(actual, expect)
def assert_on_demand(self, repo): """Assert that on_demand download policy is properly working.""" # Assert no content units were downloaded besides metadata. metadata_unit_count = sum([ count for name, count in repo['content_unit_counts'].items() if name not in ('rpm', 'drpm', 'srpm') ]) self.assertEqual(repo['locally_stored_units'], metadata_unit_count) # Assert there is at least one content unit in the repository. total_units = sum(repo['content_unit_counts'].values()) self.assertEqual(repo['total_repository_units'], total_units) # Download the same RPM twice. rpm = get_unit(self.cfg, repo['distributors'][0], RPM) same_rpm = get_unit(self.cfg, repo['distributors'][0], RPM) # Assert the initial request received a 302 Redirect. self.assertTrue(rpm.history[0].is_redirect) # Assert the checksum of the downloaded RPM matches the metadata. actual = hashlib.sha256(rpm.content).hexdigest() expect = utils.get_sha256_checksum(RPM_UNSIGNED_URL) self.assertEqual(actual, expect) # Assert the first request resulted in a cache miss from Squid. self.assertIn('MISS', rpm.headers['X-Cache-Lookup'], rpm.headers) # Assert the checksum of the second RPM matches the metadata. actual = hashlib.sha256(same_rpm.content).hexdigest() expect = utils.get_sha256_checksum(RPM_UNSIGNED_URL) self.assertEqual(actual, expect) # Assert the second request resulted in a cache hit from Squid.""" self.assertIn( 'HIT', same_rpm.headers['X-Cache-Lookup'], same_rpm.headers, )
def test_publish_to_dir(self): """Publish the repository to a directory on the Pulp server. gerify that :data:`pulp_smash.constants.RPM` is present and has a correct checksum. This test is skipped if selinux is installed and enabled on the target system an `Pulp issue 616 <https://pulp.plan.io/issues/616>`_ is open. """ export_dir = self.publish_to_dir( self.repo['_href'], self.distributor['id'], ) actual = cli.Client(self.cfg).run(('sha256sum', os.path.join( export_dir, self.distributor['config']['relative_url'], RPM, ))).stdout.strip().split()[0] expect = utils.get_sha256_checksum(RPM_SIGNED_URL) self.assertEqual(actual, expect)
def _assert_background_immediate(self, repo): """Make assertions about background and immediate download policies.""" # Download an RPM. rpm = get_unit(self.cfg, repo['distributors'][0], RPM) # Assert that all content is downloaded for the repository. self.assertEqual( repo['locally_stored_units'], sum(repo['content_unit_counts'].values()), repo['content_unit_counts'], ) # Assert that the request was serviced directly by Pulp. # HTTP 302 responses should have a "Location" header. history_headers = [response.headers for response in rpm.history] self.assertEqual(0, len(rpm.history), history_headers) # Assert the checksum of the downloaded RPM matches the metadata. actual = hashlib.sha256(rpm.content).hexdigest() expect = utils.get_sha256_checksum(RPM_UNSIGNED_URL) self.assertEqual(actual, expect)
def test_all(self): """Call the function three times, with two URLs. Call the function with the first URL, the second URL and the first URL again. Verify that: * No download is attempted during the third call. * The first and second calls return different checksums. * The first and third calls return identical checksums. """ urls_blobs = ( ('http://example.com', b'abc'), ('http://example.org', b'123'), ('HTTP://example.com', b'abc'), ) checksums = [] with mock.patch.object(utils, 'http_get') as http_get: for url, blob in urls_blobs: http_get.return_value = blob checksums.append(utils.get_sha256_checksum(url)) self.assertEqual(http_get.call_count, 2) self.assertNotEqual(checksums[0], checksums[1]) self.assertEqual(checksums[0], checksums[2])
def test_same_rpm_checksum(self): """Assert the checksum of the second RPM matches the metadata.""" actual = hashlib.sha256(self.same_rpm.content).hexdigest() expect = utils.get_sha256_checksum(RPM_SIGNED_URL) self.assertEqual(actual, expect)