def test_create_upload_list_no_skip_existing(self): # Setup # Filename in the bundle doesn't matter since the file itself isn't checked # for any data. orig_file_bundles = [FileBundle('a'), FileBundle('b')] user_args = { FLAG_SKIP_EXISTING.keyword: False, OPTION_REPO_ID.keyword: 'repo-1' } self.bindings.repo_unit.search = mock.MagicMock() # Test upload_file_bundles = self.command.create_upload_list( orig_file_bundles, **user_args) # Verify self.assertEqual(orig_file_bundles, upload_file_bundles) self.assertEqual(0, self.bindings.repo_unit.search.call_count)
def test_create_upload_list_rpm_only_drpm(self, mock__generate_unit_key): """Test upload of RPM only DRPM.""" self.command.prompt = mock.Mock() self.command.type_id = TYPE_ID_DRPM msg = _('The given file is not a valid RPM') mock__generate_unit_key.side_effect = MetadataException(msg) bundle = FileBundle('a') user_args = { FLAG_SKIP_EXISTING.keyword: True, OPTION_REPO_ID.keyword: 'repo-1' } self.command.create_upload_list([bundle], **user_args) w_msg = _('%s: RPM only DRPMs are not supported.') % bundle.filename self.command.prompt.warning.assert_called_once_with(w_msg)
def test_create_upload_list_skip_existing(self): # Setup # The bundle needs to point to a real file since the unit key is derived from it # when the existing check needs to occur. filename = os.path.join(RPM_DIR, RPM_FILENAME) orig_file_bundles = [FileBundle(filename)] user_args = { FLAG_SKIP_EXISTING.keyword: True, OPTION_REPO_ID.keyword: 'repo-1' } # The format doesn't matter, it's just that the server doesn't return None. # This will indicate that the first file already exists but after that, None # will be returned indicating the second doesn't exist and should be present # in the returned upload list. search_results = [{}] def search_simulator(repo_id, **criteria): response = Response(200, copy.copy(search_results)) if len(search_results): search_results.pop(0) return response mock_search = mock.MagicMock() mock_search.side_effect = search_simulator self.bindings.repo_unit.search = mock_search # Test upload_file_bundles = self.command.create_upload_list( orig_file_bundles, **user_args) # Verify self.assertEqual(0, len(upload_file_bundles)) self.assertEqual(1, mock_search.call_count) for file_bundle_index in range(0, 1): call_args = mock_search.call_args_list[file_bundle_index] self.assertEqual(call_args[0][0], 'repo-1') expected_filters = { 'name': 'pulp-test-package', 'epoch': '0', 'version': '0.3.1', 'release': '1.fc11', 'arch': 'x86_64', 'checksumtype': 'sha256', 'checksum': '6bce3f26e1fc0fc52ac996f39c0d0e14fc26fb8077081d5b4dbfb6431b08aa9f', } expected_filters.update( orig_file_bundles[file_bundle_index].unit_key) expected_criteria_args = { 'type_ids': [TYPE_ID_RPM], 'filters': expected_filters, } self.assertEqual(expected_criteria_args, call_args[1])