def test_report_when_duplication_allowed(self, export_with_set): export_with_set.return_value = "exported_duplicate_element" element = mock.MagicMock() element.tag = "constraint_type" report_processor = MockLibraryReportProcessor() constraint.check_is_without_duplication( report_processor, fixture_constraint_section(["duplicate_element"]), element, are_duplicate=lambda e1, e2: True, export_element=constraint.export_with_set, duplication_alowed=True, ) assert_report_item_list_equal( report_processor.report_item_list, [ ( severities.WARNING, report_codes.DUPLICATE_CONSTRAINTS_EXIST, { 'constraint_info_list': ['exported_duplicate_element'], 'constraint_type': 'constraint_type' }, ) ] )
def create_with_set( tag_name, prepare_options, env, resource_set_list, constraint_options, resource_in_clone_alowed=False, duplication_alowed=False, duplicate_check=None, ): """ string tag_name is constraint tag name callable prepare_options takes cib(Element), options(dict), resource_set_list and return corrected options or if options not usable raises error env is library environment list resource_set_list is description of resource set, for example: {"ids": ["A", "B"], "options": {"sequential": "true"}}, dict constraint_options is base for building attributes of constraint tag bool resource_in_clone_alowed flag for allowing to reference id which is in tag clone or master bool duplication_alowed flag for allowing create duplicate element callable duplicate_check takes two elements and decide if they are duplicates """ cib = env.get_cib() find_valid_resource_id = partial( constraint.find_valid_resource_id, env.report_processor, cib, resource_in_clone_alowed, ) constraint_section = get_constraints(cib) constraint_element = constraint.create_with_set( constraint_section, tag_name, options=prepare_options(cib, constraint_options, resource_set_list), resource_set_list=[ resource_set.prepare_set( find_valid_resource_id, resource_set_item, env.report_processor ) for resource_set_item in resource_set_list ], ) if not duplicate_check: duplicate_check = constraint.have_duplicate_resource_sets constraint.check_is_without_duplication( env.report_processor, constraint_section, constraint_element, are_duplicate=duplicate_check, export_element=constraint.export_with_set, duplication_alowed=duplication_alowed, ) env.push_cib()
def test_success_when_no_duplication_found(self, export_with_set): export_with_set.return_value = "exported_duplicate_element" element = mock.MagicMock() element.tag = "constraint_type" #no exception raised report_processor = MockLibraryReportProcessor() constraint.check_is_without_duplication( report_processor, fixture_constraint_section([]), element, are_duplicate=lambda e1, e2: True, export_element=constraint.export_with_set, )
def create_with_set( tag_name, prepare_options, env, resource_set_list, constraint_options, can_repair_to_clone=False, resource_in_clone_alowed=False, duplication_alowed=False, duplicate_check=None, ): """ string tag_name is constraint tag name callable prepare_options takes cib(Element), options(dict), resource_set_list and return corrected options or if options not usable raises error env is library environment list resource_set_list is description of resource set, for example: {"ids": ["A", "B"], "options": {"sequential": "true"}}, dict constraint_options is base for building attributes of constraint tag bool resource_in_clone_alowed flag for allowing to reference id which is in tag clone or master bool duplication_alowed flag for allowing create duplicate element callable duplicate_check takes two elements and decide if they are duplicates """ cib = env.get_cib() find_valid_resource_id = partial( constraint.find_valid_resource_id, env.report_processor, cib, can_repair_to_clone, resource_in_clone_alowed ) constraint_section = get_constraints(cib) constraint_element = constraint.create_with_set( constraint_section, tag_name, options=prepare_options(cib, constraint_options, resource_set_list), resource_set_list=[ resource_set.prepare_set(find_valid_resource_id, resource_set_item) for resource_set_item in resource_set_list ] ) if not duplicate_check: duplicate_check = constraint.have_duplicate_resource_sets constraint.check_is_without_duplication( env.report_processor, constraint_section, constraint_element, are_duplicate=duplicate_check, export_element=constraint.export_with_set, duplication_alowed=duplication_alowed, ) env.push_cib(cib)
def create( env, ticket_key, resource_id, options, resource_in_clone_alowed=False, duplication_alowed=False, ): """ create ticket constraint string ticket_key ticket for constraining resource dict options desired constraint attributes bool resource_in_clone_alowed flag for allowing to reference id which is in tag clone or master bool duplication_alowed flag for allowing create duplicate element callable duplicate_check takes two elements and decide if they are duplicates """ cib = env.get_cib() options = ticket.prepare_options_plain( cib, env.report_processor, options, ticket_key, constraint.find_valid_resource_id(env.report_processor, cib, resource_in_clone_alowed, resource_id), ) constraint_section = get_constraints(cib) constraint_element = ticket.create_plain(constraint_section, options) constraint.check_is_without_duplication( env.report_processor, constraint_section, constraint_element, are_duplicate=ticket.get_duplicit_checker_callback( are_new_role_names_supported(constraint_section)), export_element=constraint.export_plain, duplication_alowed=duplication_alowed, ) env.push_cib()
def create( env, ticket_key, resource_id, options, autocorrection_allowed=False, resource_in_clone_alowed=False, duplication_alowed=False, ): """ create ticket constraint string ticket_key ticket for constraining resource dict options desired constraint attributes bool resource_in_clone_alowed flag for allowing to reference id which is in tag clone or master bool duplication_alowed flag for allowing create duplicate element callable duplicate_check takes two elements and decide if they are duplicates """ cib = env.get_cib() options = ticket.prepare_options_plain( cib, options, ticket_key, constraint.find_valid_resource_id( env.report_processor, cib, autocorrection_allowed, resource_in_clone_alowed, resource_id ), ) constraint_section = get_constraints(cib) constraint_element = ticket.create_plain(constraint_section, options) constraint.check_is_without_duplication( env.report_processor, constraint_section, constraint_element, are_duplicate=ticket.are_duplicate_plain, export_element=constraint.export_plain, duplication_alowed=duplication_alowed, ) env.push_cib(cib)
def test_report_when_duplication_allowed(self): element = mock.MagicMock() element.tag = "constraint_type" report_processor = MockLibraryReportProcessor() constraint.check_is_without_duplication( report_processor, fixture_constraint_section( [etree.Element("tag", {"id": "duplicate_element"})]), element, are_duplicate=lambda e1, e2: True, export_element=constraint.export_with_set, duplication_alowed=True, ) assert_report_item_list_equal( report_processor.report_item_list, [ ( severities.INFO, report_codes.DUPLICATE_CONSTRAINTS_LIST, { "constraint_info_list": [{ "resource_sets": [], "options": { "id": "duplicate_element" }, }], "constraint_type": "constraint_type", }, ), ( severities.WARNING, report_codes.DUPLICATE_CONSTRAINTS_EXIST, { "constraint_ids": ["duplicate_element"], }, ), ], )
def test_raises_when_duplicate_element_found(self, export_with_set): export_with_set.return_value = "exported_duplicate_element" element = mock.MagicMock() element.tag = "constraint_type" report_processor = MockLibraryReportProcessor() assert_raise_library_error( lambda: constraint.check_is_without_duplication( report_processor, fixture_constraint_section(["duplicate_element"]), element, are_duplicate=lambda e1, e2: True, export_element=constraint.export_with_set, ), (severities.ERROR, report_codes.DUPLICATE_CONSTRAINTS_EXIST, { 'constraint_info_list': ['exported_duplicate_element'], 'constraint_type': 'constraint_type' }, report_codes.FORCE_CONSTRAINT_DUPLICATE), )
def test_raises_when_duplicate_element_found(self, export_with_set): export_with_set.return_value = "exported_duplicate_element" element = mock.MagicMock() element.tag = "constraint_type" report_processor = MockLibraryReportProcessor() assert_raise_library_error( lambda: constraint.check_is_without_duplication( report_processor, fixture_constraint_section(["duplicate_element"]), element, are_duplicate=lambda e1, e2: True, export_element=constraint.export_with_set, ), ( severities.ERROR, report_codes.DUPLICATE_CONSTRAINTS_EXIST, { 'constraint_info_list': ['exported_duplicate_element'], 'constraint_type': 'constraint_type' }, report_codes.FORCE_CONSTRAINT_DUPLICATE ), )