def test_generate_download_requests_subdirectory_contextpath(self, mock_mkdir): """ Test with a repository at a subdirectory of the context root. """ plugin_config = { importer_constants.KEY_FEED: 'http://pulpproject.org/foo/baz/', } self.step.config = PluginCallConfiguration({}, plugin_config) sample_unit = { 'name': 'foo', 'version': '1.5', 'architecture': 'x86_64', 'filename': 'foo.deb'} self.step.step_get_local_units.units_to_download = [sample_unit] self.step.deb_data = { sync.get_key_hash(sample_unit): { 'file_path': 'pool/p/foo.deb', 'file_name': 'foo.deb' } } requests = list(self.step.generate_download_requests()) self.assertEquals(1, len(requests)) download_request = requests[0] download_dir = os.path.join(self.working_dir, sync.generate_internal_storage_path('foo.deb')) download_url = 'http://pulpproject.org/foo/baz/pool/p/foo.deb' mock_mkdir.assert_called_once_with(os.path.dirname(download_dir)) self.assertEquals(download_request.destination, download_dir) self.assertEquals(download_request.url, download_url)
def test_generate_download_requests_root_contextpath(self, mock_mkdir): """ Test with a repository at the root context path. """ sample_unit = { 'name': 'foo', 'version': '1.5', 'architecture': 'x86_64', 'filename': 'foo.deb'} self.step.step_get_local_units.units_to_download = [sample_unit] self.step.deb_data = { sync.get_key_hash(sample_unit): { 'file_path': '/pool/p/foo.deb', 'file_name': 'foo.deb' } } requests = list(self.step.generate_download_requests()) self.assertEquals(1, len(requests)) download_request = requests[0] download_dir = os.path.join(self.working_dir, sync.generate_internal_storage_path('foo.deb')) download_url = 'http://pulpproject.org/pool/p/foo.deb' mock_mkdir.assert_called_once_with(os.path.dirname(download_dir)) self.assertEquals(download_request.destination, download_dir) self.assertEquals(download_request.url, download_url)
def test_process_main(self, mock_shutil, mock_stat): """ Test that we save properly if everything is ok """ unit_key = {'name': 'foo', 'version': '1.5', 'architecture': 'x86_64'} unit_key_hash = sync.get_key_hash(unit_key) deb_data = { unit_key_hash: { 'file_name': 'foo.deb', 'file_size': '5' } } self.step.parent = mock.MagicMock(deb_data=deb_data) self.step.parent.step_get_local_units.units_to_download = [unit_key] mock_stat.return_value.st_size = 5 initialized_unit = Unit(constants.DEB_TYPE_ID, unit_key, {}, 'some/directory') save_location = sync.generate_internal_storage_path('foo.deb') self.step.conduit.init_unit.return_value = initialized_unit self.step.process_main() self.step.conduit.init_unit.assert_called_once_with(constants.DEB_TYPE_ID, unit_key, {'file_name': 'foo.deb'}, save_location) source = os.path.join(self.working_dir, save_location) mock_shutil.assert_called_once_with(source, initialized_unit.storage_path)
def test_dict_to_unit(self): """ Test basic conversion of a unit dictionary to an unit object """ unit_dict = {'name': 'foo', 'version': '1.5', 'architecture': 'x86_64', '_id': 'blah'} unit_key_hash = sync.get_key_hash(unit_dict) deb_data = { unit_key_hash: { 'file_name': 'foo.deb' } } self.step.parent = mock.MagicMock(deb_data=deb_data) unit = self.step._dict_to_unit(unit_dict) self.assertTrue(unit is self.step.conduit.init_unit.return_value) unit_key = {'name': 'foo', 'version': '1.5', 'architecture': 'x86_64'} storage_path = sync.generate_internal_storage_path('foo.deb') self.step.conduit.init_unit.assert_called_once_with(constants.DEB_TYPE_ID, unit_key, {'file_name': 'foo.deb'}, storage_path)
def test_process_main_file_size_failure(self, mock_shutil, mock_stat): """ Test that we error if the file size does not match the metadata """ unit_key = {'name': 'foo', 'version': '1.5', 'architecture': 'x86_64'} unit_key_hash = sync.get_key_hash(unit_key) deb_data = { unit_key_hash: { 'file_name': 'foo.deb', 'file_size': '5' } } self.step.parent = mock.MagicMock(deb_data=deb_data) self.step.parent.step_get_local_units.units_to_download = [unit_key] mock_stat.return_value.st_size = 7 initialized_unit = Unit(constants.DEB_TYPE_ID, unit_key, {}, 'some/directory') self.step.conduit.init_unit.return_value = initialized_unit try: self.step.process_main() self.fail('This should have raised an exception') except exceptions.PulpCodedValidationException as e: self.assertEquals(e.error_code, error_codes.DEB1001)