def test_spawned_tasks(self): result = dispatch.spawned_tasks({'spawned_tasks': ['apple']}) target_dict = { 'spawned_tasks': [dispatch.link_obj('/pulp/api/v2/tasks/apple/')] } target_dict['spawned_tasks'][0].update({'task_id': 'apple'}) compare_dict(result, target_dict)
def test_create_consumer_payload(self): local_distributor = YumHTTPDistributor() repo = Mock() repo.display_name = 'foo' repo.id = 'bar' config = {'https_ca': 'pear', 'gpgkey': 'kiwi', 'auth_cert': 'durian', 'auth_ca': True, 'http': True, 'https': True} binding_config = {} pulp_server_config.set('server', 'server_name', 'apple') cert_file = os.path.join(self.working_dir, "orange_file") with open(cert_file, 'w') as filewriter: filewriter.write("orange") pulp_server_config.set('security', 'ssl_ca_certificate', cert_file) result = local_distributor.create_consumer_payload(repo, config, binding_config) target = { 'server_name': 'apple', 'ca_cert': 'orange', 'relative_path': '/pulp/repos/bar', 'gpg_keys': {'pulp.key': 'kiwi'}, 'client_cert': 'durian', 'protocols': ['http', 'https'], 'repo_name': 'foo' } compare_dict(result, target)
def test_get_progress_report_description(self): step = PublishStep('bar_step') step.description = 'bar' step.progress_details = 'baz' step.error_details = "foo" step.state = reporting_constants.STATE_COMPLETE step.total_units = 2 step.progress_successes = 1 step.progress_failures = 1 report = step.get_progress_report() target_report = { reporting_constants.PROGRESS_STEP_TYPE_KEY: 'bar_step', reporting_constants.PROGRESS_NUM_SUCCESSES_KEY: 1, reporting_constants.PROGRESS_STATE_KEY: step.state, reporting_constants.PROGRESS_ERROR_DETAILS_KEY: step.error_details, reporting_constants.PROGRESS_NUM_PROCESSED_KEY: 2, reporting_constants.PROGRESS_NUM_FAILURES_KEY: 1, reporting_constants.PROGRESS_ITEMS_TOTAL_KEY: 2, reporting_constants.PROGRESS_DESCRIPTION_KEY: 'bar', reporting_constants.PROGRESS_DETAILS_KEY: 'baz', reporting_constants.PROGRESS_STEP_UUID: step.uuid } compare_dict(report[0], target_report)
def test_run_async(self): # Setup repo_id = 'test-repo' data = { OPTION_REPO_ID.keyword: repo_id, OPTION_NAME.keyword: 'Test Repository', OPTION_DESCRIPTION.keyword: 'Repository Description', OPTION_NOTES.keyword: { 'a': 'a', 'b': 'b' }, 'distributor_configs': { 'alpha': { 'beta': 'gamma' } }, 'importer_config': { 'delta': 'epsilon' } } result_task = Task({}) self.server_mock.request.return_value = 200, result_task self.command.poll = mock.Mock() # Test self.command.run(**data) # Verify self.assertEqual(1, self.server_mock.request.call_count) self.assertEqual('PUT', self.server_mock.request.call_args[0][0]) url = self.server_mock.request.call_args[0][1] self.assertTrue(url.endswith('/repositories/%s/' % repo_id)) body = self.server_mock.request.call_args[0][2] body = json.loads(body) body_target = { 'delta': { 'display_name': 'Test Repository', 'description': 'Repository Description', 'notes': { 'a': 'a', 'b': 'b' } }, 'distributor_configs': { 'alpha': { 'beta': 'gamma' } }, 'importer_config': { 'delta': 'epsilon' } } compare_dict(body, body_target) self.command.poll.assert_called_once_with([result_task], mock.ANY)
def test_process_dictionary_against_whitelist_global_keys(self): test_dictionary = {u'_href': u'foo', u'_id': u'bar', u'_ns': u'baz'} test_dictionary_before = copy.deepcopy(test_dictionary) JSONController.process_dictionary_against_whitelist( test_dictionary, []) util.compare_dict(test_dictionary_before, test_dictionary)
def test_run(self): # Setup repo_id = 'test-repo' data = { OPTION_REPO_ID.keyword: repo_id, OPTION_NAME.keyword: 'Test Repository', OPTION_DESCRIPTION.keyword: 'Repository Description', OPTION_NOTES.keyword: { 'a': 'a', 'b': 'b' }, 'distributor_configs': { 'alpha': { 'beta': 'gamma' } }, 'importer_config': { 'delta': 'epsilon' } } self.server_mock.request.return_value = 200, {} # Test self.command.run(**data) # Verify self.assertEqual(1, self.server_mock.request.call_count) self.assertEqual('PUT', self.server_mock.request.call_args[0][0]) url = self.server_mock.request.call_args[0][1] self.assertTrue(url.endswith('/repositories/%s/' % repo_id)) body = self.server_mock.request.call_args[0][2] body = json.loads(body) body_target = { 'delta': { 'display_name': 'Test Repository', 'description': 'Repository Description', 'notes': { 'a': 'a', 'b': 'b' } }, 'distributor_configs': { 'alpha': { 'beta': 'gamma' } }, 'importer_config': { 'delta': 'epsilon' } } compare_dict(body, body_target) self.assertEqual(1, len(self.prompt.get_write_tags())) self.assertEqual(TAG_SUCCESS, self.prompt.get_write_tags()[0])
def test_describe_distributors(self): command = TestPythonRespositoryOptions.MixinTestClass() user_input = {} result = command._describe_distributors(user_input) target_result = {'distributor_id': constants.CLI_DISTRIBUTOR_ID, 'distributor_type_id': constants.DISTRIBUTOR_TYPE_ID, 'distributor_config': {}, 'auto_publish': True} compare_dict(result[0], target_result)
def test_get_publish_tasks(self): context = mock.Mock() resource_id = "foo" export._get_publish_tasks(resource_id, context) tags = ['pulp:repository_group:foo', 'pulp:action:publish'] criteria = {'filters': {'state': {'$nin': COMPLETED_STATES}, 'tags': {'$all': tags}}} self.assertTrue(context.server.tasks_search.search.called) created_criteria = context.server.tasks_search.search.call_args[1] compare_dict(criteria, created_criteria)
def test_describe_distributors(self): command = cudl.CreateDebRepositoryCommand(Mock()) user_input = {cudl.OPT_AUTO_PUBLISH.keyword: True} result = command._describe_distributors(user_input) target_result = {'distributor_id': constants.CLI_WEB_DISTRIBUTOR_ID, 'distributor_type_id': constants.WEB_DISTRIBUTOR_TYPE_ID, 'distributor_config': {}, 'auto_publish': True} compare_dict(result[0], target_result)
def test_get_progress_report_summary(self): parent_step = publish_step.PluginStep('parent_step') step = publish_step.PluginStep('foo_step') parent_step.add_child(step) step.state = reporting_constants.STATE_COMPLETE report = parent_step.get_progress_report_summary() target_report = { 'foo_step': reporting_constants.STATE_COMPLETE } compare_dict(report, target_report)
def test_to_dict(self): test_exception = exceptions.PulpException("foo_msg") test_exception.error_data = {"foo": "bar"} result = test_exception.to_dict() compare_dict(result, {'code': test_exception.error_code.code, 'description': str(test_exception), 'data': {"foo": "bar"}, 'sub_errors': []})
def test_process_dictionary_against_whitelisty_global_and_local_keys(self): test_dictionary = { u'_href': u'foo', u'_id': u'bar', u'_ns': u'baz', u'qux': u'quux' } test_dictionary_before = copy.deepcopy(test_dictionary) JSONController.process_dictionary_against_whitelist(test_dictionary, [u'qux']) util.compare_dict(test_dictionary_before, test_dictionary)
def test_describe_distributors(self): command = TestPythonRespositoryOptions.MixinTestClass() user_input = {} result = command._describe_distributors(user_input) target_result = { 'distributor_id': constants.CLI_DISTRIBUTOR_ID, 'distributor_type_id': constants.DISTRIBUTOR_TYPE_ID, 'distributor_config': {}, 'auto_publish': True } compare_dict(result[0], target_result)
def test_describe_distributors(self): command = cudl.CreateDebRepositoryCommand(Mock()) user_input = {cudl.OPT_AUTO_PUBLISH.keyword: True} result = command._describe_distributors(user_input) target_result = { 'distributor_id': constants.CLI_WEB_DISTRIBUTOR_ID, 'distributor_type_id': constants.WEB_DISTRIBUTOR_TYPE_ID, 'distributor_config': {}, 'auto_publish': True } compare_dict(result[0], target_result)
def test_describe_distributors(self): command = cudl.CreatePythonRepositoryCommand(Mock()) user_input = {} result = command._describe_distributors(user_input) target_result = { 'distributor_id': constants.CLI_DISTRIBUTOR_ID, 'distributor_type_id': constants.DISTRIBUTOR_TYPE_ID, 'distributor_config': {}, 'auto_publish': True } compare_dict(result[0], target_result)
def test_serialize(self): async_result = AsyncResult('foo') test_exception = PulpException('foo') result = tasks.TaskResult('foo', test_exception, [{'task_id': 'baz'}, async_result, "qux"]) serialized = result.serialize() self.assertEquals(serialized.get('result'), 'foo') compare_dict(test_exception.to_dict(), serialized.get('error')) self.assertEquals(serialized.get('spawned_tasks'), [{'task_id': 'baz'}, {'task_id': 'foo'}, {'task_id': 'qux'}])
def test_describe_distributors(self): command = TestNpmRespositoryOptions.MixinTestClass() # by default the value is set to None user_input = {'auto-publish': None} result = command._describe_distributors(user_input) target_result = { 'distributor_id': constants.CLI_DISTRIBUTOR_ID, 'distributor_type_id': constants.DISTRIBUTOR_TYPE_ID, 'distributor_config': {}, 'auto_publish': True } compare_dict(result[0], target_result)
def test_describe_distributors(self): command = TestNpmRespositoryOptions.MixinTestClass() # by default the value is set to None user_input = { 'auto-publish': None } result = command._describe_distributors(user_input) target_result = {'distributor_id': constants.CLI_DISTRIBUTOR_ID, 'distributor_type_id': constants.DISTRIBUTOR_TYPE_ID, 'distributor_config': {}, 'auto_publish': True} compare_dict(result[0], target_result)
def test_post(self, mock_get_results): search_controller = dispatch_controller.SearchTaskCollection() mock_get_results.return_value = [self.get_task()] processed_tasks_json = search_controller.POST() # Mimic the processing updated_task = dispatch_controller.task_serializer(self.get_task()) processed_tasks = json.loads(processed_tasks_json) compare_dict(updated_task, processed_tasks[0]) #validate the permissions self.validate_auth(authorization.READ)
def test_get_with_association_filter(self, mock_manager_factory): step = publish_step.UnitPublishStep("foo", ['bar', 'baz']) step.association_filters = {'foo': 'bar'} find_by_criteria = mock_manager_factory.repo_unit_association_query_manager.return_value.\ find_by_criteria find_by_criteria.return_value.count.return_value = 5 total = step._get_total() criteria_object = find_by_criteria.call_args[0][0] compare_dict(criteria_object.filters, {'foo': 'bar', 'unit_type_id': {'$in': ['bar', 'baz']}}) self.assertEquals(5, total)
def test_to_dict_nested_pulp_exception(self): test_exception = exceptions.PulpException("foo_msg") test_exception.error_data = {"foo": "bar"} test_exception.add_child_exception(exceptions.PulpCodedException(error_codes.PLP0001)) result = test_exception.to_dict() child_exception = result['sub_errors'][0] compare_dict(child_exception, {'code': error_codes.PLP0001.code, 'description': error_codes.PLP0001.message, 'data': {}, 'sub_errors': []})
def test_post(self, mock_get_results): search_controller = dispatch_controller.SearchTaskCollection() mock_get_results.return_value = [self.get_task()] processed_tasks_json = search_controller.POST() # Mimic the processing updated_task = dispatch_controller.task_serializer(self.get_task()) processed_tasks = json.loads(processed_tasks_json) compare_dict(updated_task, processed_tasks[0]) # validate the permissions self.validate_auth(authorization.READ)
def test_describe_importers(self, read): command = cudl.CreateOSTreeRepositoryCommand(Mock()) read.side_effect = hash paths = ['path-1', 'path-2'] branches = ['apple', 'orange'] user_input = {'branch': branches, 'gpg-key': paths} result = command._parse_importer_config(user_input) self.assertEqual(read.call_args_list, [((p, ), {}) for p in paths]) target_result = { constants.IMPORTER_CONFIG_KEY_BRANCHES: branches, constants.IMPORTER_CONFIG_KEY_GPG_KEYS: map(hash, paths) } compare_dict(result, target_result)
def test_process_dictionary_against_whitelist_filter_key(self): test_dictionary = { u'_href': u'foo', u'_id': u'bar', u'_ns': u'baz', u'qux': u'quux' } target_result = copy.deepcopy(test_dictionary) target_result.pop(u'qux', None) JSONController.process_dictionary_against_whitelist(test_dictionary, []) util.compare_dict(target_result, test_dictionary)
def test_describe_distributors(self): command = cudl.CreateDockerRepositoryCommand(Mock()) user_input = {'redirect-url': 'foo', 'protected': False, 'repo-registry-id': 'bar'} result = command._describe_distributors(user_input) target_result = { 'distributor_type_id': constants.DISTRIBUTOR_WEB_TYPE_ID, 'distributor_config': { 'redirect-url': 'foo', 'repo-registry-id': 'bar', 'protected': False}, 'auto_publish': True, 'distributor_id': constants.CLI_WEB_DISTRIBUTOR_ID } compare_dict(result[0], target_result)
def test_describe_distributors(self): command = cudl.CreateOSTreeRepositoryCommand(Mock()) relative_path = '7/x86/standard' user_input = { cudl.OPT_RELATIVE_PATH.keyword: relative_path } result = command._describe_distributors(user_input) target_result = {'distributor_id': constants.CLI_WEB_DISTRIBUTOR_ID, 'distributor_type_id': constants.WEB_DISTRIBUTOR_TYPE_ID, 'distributor_config': { constants.DISTRIBUTOR_CONFIG_KEY_RELATIVE_PATH: relative_path }, 'auto_publish': True} compare_dict(result[0], target_result)
def test_process_dictionary_against_whitelist_filter_key(self): test_dictionary = { u'_href': u'foo', u'_id': u'bar', u'_ns': u'baz', u'qux': u'quux' } target_result = copy.deepcopy(test_dictionary) target_result.pop(u'qux', None) JSONController.process_dictionary_against_whitelist( test_dictionary, []) util.compare_dict(target_result, test_dictionary)
def test__parse_importer_config_no_input(self, parse_user_input): """ Assert correct behavior from _parse_importer_config when there is no special user input to parse. """ command = TestPythonRespositoryOptions.MixinTestClass() user_input = {} parse_user_input.return_value = {} result = command._parse_importer_config(user_input) parse_user_input.assert_called_once_with({}) expected_result = {} compare_dict(result, expected_result)
def test_describe_distributors(self): command = cudl.CreateOSTreeRepositoryCommand(Mock()) relative_path = '7/x86/standard' user_input = {cudl.OPT_RELATIVE_PATH.keyword: relative_path} result = command._describe_distributors(user_input) target_result = { 'distributor_id': constants.CLI_WEB_DISTRIBUTOR_ID, 'distributor_type_id': constants.WEB_DISTRIBUTOR_TYPE_ID, 'distributor_config': { constants.DISTRIBUTOR_CONFIG_KEY_RELATIVE_PATH: relative_path }, 'auto_publish': True } compare_dict(result[0], target_result)
def test_distributor_update_no_bindings(self, mock_dist_manager, mock_bind_manager): config = {'configvalue': 'baz'} generated_distributor = {'foo': 'bar'} mock_dist_manager.return_value.update_distributor_config.return_value = \ generated_distributor #Use None for the delta value to ensure it doesn't throw an exception result = repository.distributor_update('foo-id', 'bar-id', config, None) mock_dist_manager.return_value.update_distributor_config. \ assert_called_with('foo-id', 'bar-id', config, None) self.assertTrue(isinstance(result, TaskResult)) util.compare_dict(generated_distributor, result.return_value) self.assertEquals(None, result.error)
def test_serialize(self): async_result = AsyncResult('foo') test_exception = PulpException('foo') task_status = TaskStatus(task_id='quux') result = tasks.TaskResult('foo', test_exception, [{'task_id': 'baz'}, async_result, "qux", task_status]) serialized = result.serialize() self.assertEquals(serialized.get('result'), 'foo') compare_dict(test_exception.to_dict(), serialized.get('error')) self.assertEquals(serialized.get('spawned_tasks'), [{'task_id': 'baz'}, {'task_id': 'foo'}, {'task_id': 'qux'}, {'task_id': 'quux'}])
def test_to_dict(self): test_exception = exceptions.PulpException("foo_msg") test_exception.error_data = {"foo": "bar"} result = test_exception.to_dict() compare_dict( result, { 'code': test_exception.error_code.code, 'description': str(test_exception), 'data': { "foo": "bar" }, 'sub_errors': [] })
def test_describe_distributors_using_feed(self): command = cudl.CreateOSTreeRepositoryCommand(Mock()) relative_path = '/7/x86/standard' feed_url = 'http://planet.com%s' % relative_path user_input = { command.options_bundle.opt_feed.keyword: feed_url } result = command._describe_distributors(user_input) target_result = {'distributor_id': constants.CLI_WEB_DISTRIBUTOR_ID, 'distributor_type_id': constants.WEB_DISTRIBUTOR_TYPE_ID, 'distributor_config': { constants.DISTRIBUTOR_CONFIG_KEY_RELATIVE_PATH: relative_path }, 'auto_publish': True} compare_dict(result[0], target_result)
def test_to_dict(self): test_exception = exceptions.PulpException("foo_msg") test_exception.error_data = {"foo": "bar"} result = test_exception.to_dict() compare_dict( result, { "code": test_exception.error_code.code, "description": str(test_exception), "data": {"foo": "bar"}, "sub_errors": [], }, )
def test_describe_distributors_using_feed(self): command = cudl.CreateOSTreeRepositoryCommand(Mock()) relative_path = '/7/x86/standard' feed_url = 'http://planet.com%s' % relative_path user_input = {command.options_bundle.opt_feed.keyword: feed_url} result = command._describe_distributors(user_input) target_result = { 'distributor_id': constants.CLI_WEB_DISTRIBUTOR_ID, 'distributor_type_id': constants.WEB_DISTRIBUTOR_TYPE_ID, 'distributor_config': { constants.DISTRIBUTOR_CONFIG_KEY_RELATIVE_PATH: relative_path }, 'auto_publish': True } compare_dict(result[0], target_result)
def test__parse_importer_config_with_package_names(self, parse_user_input): """ Assert correct behavior from _parse_importer_config when there is no special user input to parse. """ command = TestPythonRespositoryOptions.MixinTestClass() user_input = {'some': 'input', cudl.OPT_PACKAGE_NAMES.keyword: 'django,numpy,scipy'} parse_user_input.return_value = {'some': 'input'} result = command._parse_importer_config(user_input) parse_user_input.assert_called_once_with(user_input) expected_result = {constants.CONFIG_KEY_PACKAGE_NAMES: 'django,numpy,scipy', 'some': 'input'} compare_dict(result, expected_result)
def test_distributor_update_no_bindings(self, mock_dist_manager, mock_bind_manager): config = {'configvalue': 'baz'} generated_distributor = {'foo': 'bar'} mock_dist_manager.return_value.update_distributor_config.return_value = \ generated_distributor # Use None for the delta value to ensure it doesn't throw an exception result = dist_controller.update('foo-id', 'bar-id', config, None) mock_dist_manager.return_value.update_distributor_config. \ assert_called_with('foo-id', 'bar-id', config, None) self.assertTrue(isinstance(result, TaskResult)) util.compare_dict(generated_distributor, result.return_value) self.assertEquals(None, result.error)
def test_create_consumer_payload_global_auth(self, mock_load_config): test_distributor = YumHTTPDistributor() repo = Mock() repo.display_name = 'foo' repo.id = 'bar' config = { 'https_ca': 'pear', 'gpgkey': 'kiwi', 'http': True, 'https': True } binding_config = {} pulp_server_config.set('server', 'server_name', 'apple') pulp_server_config.set('security', 'ssl_ca_certificate', 'orange') repo_auth_config = ConfigParser.SafeConfigParser() repo_auth_config.add_section('repos') repo_auth_config.set('repos', 'global_cert_location', self.working_dir) mock_load_config.return_value = repo_auth_config with open(os.path.join(self.working_dir, 'pulp-global-repo.cert'), 'w+') as cert_file: cert_file.write('cert') with open(os.path.join(self.working_dir, 'pulp-global-repo.key'), 'w+') as cert_file: cert_file.write('key') with open(os.path.join(self.working_dir, 'pulp-global-repo.ca'), 'w+') as cert_file: cert_file.write('ca') result = test_distributor.create_consumer_payload( repo, config, binding_config) target = { 'server_name': 'apple', 'ca_cert': 'pear', 'relative_path': '/pulp/repos/bar', 'gpg_keys': { 'pulp.key': 'kiwi' }, 'protocols': ['http', 'https'], 'repo_name': 'foo', 'client_cert': None, 'global_auth_cert': 'cert', 'global_auth_key': 'key', 'global_auth_ca': 'ca' } compare_dict(result, target)
def test_to_dict_nested_pulp_exception(self): test_exception = exceptions.PulpException("foo_msg") test_exception.error_data = {"foo": "bar"} test_exception.add_child_exception( exceptions.PulpCodedException(error_codes.PLP0001)) result = test_exception.to_dict() child_exception = result['sub_errors'][0] compare_dict( child_exception, { 'code': error_codes.PLP0001.code, 'description': error_codes.PLP0001.message, 'data': {}, 'sub_errors': [] })
def test_to_dict_nested_pulp_exception(self): test_exception = exceptions.PulpException("foo_msg") test_exception.error_data = {"foo": "bar"} test_exception.add_child_exception(exceptions.PulpCodedException(error_codes.PLP0001)) result = test_exception.to_dict() child_exception = result["sub_errors"][0] compare_dict( child_exception, { "code": error_codes.PLP0001.code, "description": error_codes.PLP0001.message, "data": {}, "sub_errors": [], }, )
def test_process_unit(self): step = publish.PublishErrataStepIncremental() self.publisher.add_child(step) unit_key = {'id': 'foo'} metadata = {'filename': 'bar.txt', '_test': 'hidden'} test_unit = Unit('foo_type', unit_key, metadata.copy(), '') step.process_main(test_unit) modified_metadata = metadata.copy() modified_metadata.pop('_test') modified_metadata[server_constants.PULP_USER_METADATA_FIELDNAME] = {} unit_file = os.path.join(self.working_dir, 'foo.json') self.assertTrue(os.path.exists(unit_file)) with open(unit_file) as file_handle: loaded = json.load(file_handle) compare_dict(loaded, {'unit_key': unit_key, 'unit_metadata': modified_metadata})
def test_create_consumer_payload_global_auth(self, mock_load_config, m_config): test_distributor = YumHTTPDistributor() repo = Mock() repo.display_name = 'foo' repo.id = 'bar' repo.repo_obj = Mock(repo_id='bar', display_name='foo') config = {'https_ca': 'pear', 'gpgkey': 'kiwi', 'http': True, 'https': True} m_config.config = ConfigParser.SafeConfigParser() m_config.config.add_section('server') m_config.config.set('server', 'server_name', 'apple') m_config.config.add_section('security') m_config.config.set('security', 'ssl_ca_certificate', 'orange') binding_config = {} repo_auth_config = ConfigParser.SafeConfigParser() repo_auth_config.add_section('repos') repo_auth_config.set('repos', 'global_cert_location', self.working_dir) mock_load_config.return_value = repo_auth_config with open(os.path.join(self.working_dir, 'pulp-global-repo.cert'), 'w+') as cert_file: cert_file.write('cert') with open(os.path.join(self.working_dir, 'pulp-global-repo.key'), 'w+') as cert_file: cert_file.write('key') with open(os.path.join(self.working_dir, 'pulp-global-repo.ca'), 'w+') as cert_file: cert_file.write('ca') result = test_distributor.create_consumer_payload(repo, config, binding_config) target = { 'server_name': 'apple', 'ca_cert': 'pear', 'relative_path': '/pulp/repos/bar', 'gpg_keys': {'pulp.key': 'kiwi'}, 'protocols': ['http', 'https'], 'repo_name': 'foo', 'client_cert': None, 'global_auth_cert': 'cert', 'global_auth_key': 'key', 'global_auth_ca': 'ca' } compare_dict(result, target)
def test_to_dict_nested_general_exception(self): test_exception = exceptions.PulpException("foo_msg") test_exception.error_data = {"foo": "bar"} test_exception.add_child_exception(Exception("Foo Message")) test_exception.add_child_exception(Exception("Bar Message")) result = test_exception.to_dict() child_exception = result['sub_errors'][0] compare_dict(child_exception, {'code': error_codes.PLP0000.code, 'description': "Foo Message", 'data': {}, 'sub_errors': []}) child_exception = result['sub_errors'][1] compare_dict(child_exception, {'code': error_codes.PLP0000.code, 'description': "Bar Message", 'data': {}, 'sub_errors': []})
def test_to_dict_nested_general_exception(self): test_exception = exceptions.PulpException("foo_msg") test_exception.error_data = {"foo": "bar"} test_exception.add_child_exception(Exception("Foo Message")) test_exception.add_child_exception(Exception("Bar Message")) result = test_exception.to_dict() child_exception = result["sub_errors"][0] compare_dict( child_exception, {"code": error_codes.PLP0000.code, "description": "Foo Message", "data": {}, "sub_errors": []}, ) child_exception = result["sub_errors"][1] compare_dict( child_exception, {"code": error_codes.PLP0000.code, "description": "Bar Message", "data": {}, "sub_errors": []}, )
def test_process_unit(self): step = publish.PublishErrataStepIncremental() self.publisher.add_child(step) unit_key = {'id': 'foo'} metadata = {'filename': 'bar.txt', '_test': 'hidden'} original_metadata = metadata.copy() test_unit = Unit('foo_type', unit_key, metadata, '') step.process_unit(test_unit) original_metadata.pop('_test') unit_file = os.path.join(self.working_dir, 'foo.json') self.assertTrue(os.path.exists(unit_file)) with open(unit_file) as file_handle: loaded = json.load(file_handle) compare_dict(loaded, { 'unit_key': unit_key, 'unit_metadata': original_metadata })
def test_describe_importers(self, read): command = cudl.CreateOSTreeRepositoryCommand(Mock()) read.side_effect = hash paths = ['path-1', 'path-2'] branches = ['apple', 'orange'] user_input = { 'branch': branches, 'gpg-key': paths } result = command._parse_importer_config(user_input) self.assertEqual( read.call_args_list, [((p,), {}) for p in paths]) target_result = { constants.IMPORTER_CONFIG_KEY_BRANCHES: branches, constants.IMPORTER_CONFIG_KEY_GPG_KEYS: map(hash, paths) } compare_dict(result, target_result)
def test_run_async(self): # Setup repo_id = 'test-repo' data = { OPTION_REPO_ID.keyword: repo_id, OPTION_NAME.keyword: 'Test Repository', OPTION_DESCRIPTION.keyword: 'Repository Description', OPTION_NOTES.keyword: {'a' : 'a', 'b' : 'b'}, 'distributor_configs': {'alpha': {'beta': 'gamma'}}, 'importer_config': {'delta': 'epsilon'} } result_task = Task({}) self.server_mock.request.return_value = 200, result_task self.command.poll = mock.Mock() # Test self.command.run(**data) # Verify self.assertEqual(1, self.server_mock.request.call_count) self.assertEqual('PUT', self.server_mock.request.call_args[0][0]) url = self.server_mock.request.call_args[0][1] self.assertTrue(url.endswith('/repositories/%s/' % repo_id)) body = self.server_mock.request.call_args[0][2] body = json.loads(body) body_target = { 'delta': { 'display_name': 'Test Repository', 'description': 'Repository Description', 'notes': {'a': 'a', 'b': 'b'} }, 'distributor_configs': {'alpha': {'beta': 'gamma'}}, 'importer_config': {'delta': 'epsilon'} } compare_dict(body, body_target) self.command.poll.assert_called_once_with([result_task], mock.ANY)
def test_create_consumer_payload(self): local_distributor = YumHTTPDistributor() repo = Mock() repo.display_name = 'foo' repo.id = 'bar' config = { 'https_ca': 'pear', 'gpgkey': 'kiwi', 'auth_cert': 'durian', 'auth_ca': True, 'http': True, 'https': True } binding_config = {} cert_file = os.path.join(self.working_dir, "orange_file") with mock_config.patch({ 'server': { 'server_name': 'apple' }, 'security': { 'ssl_ca_certificate': cert_file } }): with open(cert_file, 'w') as filewriter: filewriter.write("orange") result = local_distributor.create_consumer_payload( repo, config, binding_config) target = { 'server_name': 'apple', 'ca_cert': 'orange', 'relative_path': '/pulp/repos/bar', 'gpg_keys': { 'pulp.key': 'kiwi' }, 'client_cert': 'durian', 'protocols': ['http', 'https'], 'repo_name': 'foo' } compare_dict(result, target)
def test_process_unit(self): step = publish.PublishRpmAndDrpmStepIncremental() self.publisher.add_child(step) unit_key = {'name': 'foo', 'version': '1', 'release': '2', 'arch': 'flux'} metadata = {'filename': 'bar.txt', 'repodata': 'baz', '_test': 'hidden'} original_metadata = metadata.copy() storage_path = os.path.join(self.working_dir, 'foo') touch(storage_path) test_unit = Unit('foo_type', unit_key, metadata, storage_path) step.process_unit(test_unit) original_metadata.pop('repodata') original_metadata.pop('_test') unit_file = os.path.join(self.working_dir, 'foo-1-2.flux.json') self.assertTrue(os.path.exists(unit_file)) with open(unit_file) as file_handle: loaded = json.load(file_handle) compare_dict(loaded, { 'unit_key': unit_key, 'unit_metadata': original_metadata })
def test_process_unit(self): step = publish.PublishRpmAndDrpmStepIncremental() self.publisher.add_child(step) unit_key = {'name': 'foo', 'version': '1', 'release': '2', 'arch': 'flux'} metadata = {'filename': 'bar.txt', 'repodata': 'baz', '_test': 'hidden'} storage_path = os.path.join(self.working_dir, 'foo') touch(storage_path) test_unit = Unit('foo_type', unit_key, metadata.copy(), storage_path) step.process_main(test_unit) modified_metadata = metadata.copy() modified_metadata.pop('repodata') modified_metadata.pop('_test') modified_metadata[server_constants.PULP_USER_METADATA_FIELDNAME] = {} unit_file = os.path.join(self.working_dir, 'foo-1-2.flux.json') self.assertTrue(os.path.exists(unit_file)) with open(unit_file) as file_handle: loaded = json.load(file_handle) compare_dict(loaded, { 'unit_key': unit_key, 'unit_metadata': modified_metadata })
def test_to_dict_nested_general_exception(self): test_exception = exceptions.PulpException("foo_msg") test_exception.error_data = {"foo": "bar"} test_exception.add_child_exception(Exception("Foo Message")) test_exception.add_child_exception(Exception("Bar Message")) result = test_exception.to_dict() child_exception = result['sub_errors'][0] compare_dict( child_exception, { 'code': error_codes.PLP0000.code, 'description': "Foo Message", 'data': {}, 'sub_errors': [] }) child_exception = result['sub_errors'][1] compare_dict( child_exception, { 'code': error_codes.PLP0000.code, 'description': "Bar Message", 'data': {}, 'sub_errors': [] })
def test_run(self): # Setup user_input = { options.OPTION_REPO_ID.keyword: 'test-repo', options.OPTION_NAME.keyword: 'Test Name', options.OPTION_DESCRIPTION.keyword: 'Test Description', options.OPTION_NOTES.keyword: { 'a': 'a' }, cudl.OPTION_FEED.keyword: 'http://localhost', cudl.OPTION_HTTP.keyword: 'true', cudl.OPTION_HTTPS.keyword: 'true', cudl.OPTION_QUERY.keyword: ['q1', 'q2'], cudl.OPTION_REMOVE_MISSING.keyword: True } self.mock_repo_response = Mock(response_body={}) self.context.server.repo = Mock() self.context.server.repo.repository.return_value = self.mock_repo_response self.command.poll = Mock() self.command.run(**user_input) repo_config = { 'display_name': 'Test Name', 'description': 'Test Description', 'notes': { 'a': 'a' } } importer_config = { 'feed': 'http://localhost', 'queries': ['q1', 'q2'], 'remove_missing': True } dist_config = { 'puppet_distributor': { 'serve_https': True, 'serve_http': True } } call_details = self.context.server.repo.update.call_args[0] self.assertEquals('test-repo', call_details[0]) compare_dict(repo_config, call_details[1]) compare_dict(importer_config, call_details[2]) compare_dict(dist_config, call_details[3])