def _validate_reference_ids_are_resources( resources_section: Element, idref_list: Iterable[str], ) -> ReportItemList: """ Validate that ids are resources. resources_section -- element resources idref_list -- reference ids to validate """ report_list: ReportItemList = [] find_resources_and_report( resources_section, idref_list, report_list, ) return report_list
def test_more_existing(self): report_list = [] resource_list = common.find_resources_and_report( self.cib, ["R1", "R2"], report_list) self.assertEqual( ["R1", "R2"], [resource.attrib.get("id") for resource in resource_list]) assert_report_item_list_equal(report_list, [])
def test_more_some_missing(self): report_list = [] resource_list = common.find_resources_and_report( self.cib, ["R1", "R2", "RY1", "RY2"], report_list) self.assertEqual( ["R1", "R2"], [resource.attrib.get("id") for resource in resource_list]) assert_report_item_list_equal(report_list, [ fixture.report_not_found("RY1", context_type="resources"), fixture.report_not_found("RY2", context_type="resources"), ])
def test_more_additional_search(self): report_list = [] resource_list = common.find_resources_and_report( self.cib, ["R1", "R2"], report_list, additional_search=self.additional_search, ) self.assertEqual( ["R1x", "R2x"], [resource.attrib.get("id") for resource in resource_list]) assert_report_item_list_equal(report_list, [])
def test_more_existing(self): report_list = [] resource_list = common.find_resources_and_report( self.cib, ["R1", "R2"], report_list ) self.assertEqual( ["R1", "R2"], [resource.attrib.get("id") for resource in resource_list] ) assert_report_item_list_equal( report_list, [] )
def test_more_additional_search(self): report_list = [] resource_list = common.find_resources_and_report( self.cib, ["R1", "R2"], report_list, additional_search=self.additional_search, ) self.assertEqual( ["R1x", "R2x"], [resource.attrib.get("id") for resource in resource_list] ) assert_report_item_list_equal( report_list, [] )
def test_more_some_missing(self): report_list = [] resource_list = common.find_resources_and_report( self.cib, ["R1", "R2", "RY1", "RY2"], report_list ) self.assertEqual( ["R1", "R2"], [resource.attrib.get("id") for resource in resource_list] ) assert_report_item_list_equal( report_list, [ fixture.report_not_found("RY1", context_type="resources"), fixture.report_not_found("RY2", context_type="resources"), ] )
def validate(self, resources_section, id_provider): """ Run the validation and return a report item list etree.Element resources_section -- resources section of a cib IdProvider id_provider -- elements' ids generator and uniqueness checker """ report_list = [] # Check that group_id either matches an existing group element or is # not occupied by any other element. group_missing_id_valid = False group_searcher = ElementSearcher(group.TAG, self._group_id, resources_section) if group_searcher.element_found(): self._group_element = group_searcher.get_element() elif group_searcher.validate_book_id(id_provider, id_description="group name"): group_missing_id_valid = True else: report_list.extend(group_searcher.get_errors()) # Get resource elements to move to the group. # Get all types of resources, so that validation can later tell for # example: 'C' is a clone, clones cannot be put into a group. If we # only searched for primitives here, we would get 'C' is not a # resource, which is not that informative. self._resource_element_list = common.find_resources_and_report( resources_section, self._resource_id_list, report_list) # Get an adjacent resource element. if self._adjacent_resource_id is not None: # If the group already exists, check the adjacent resource is in it. if self._group_element is not None: adjacent_searcher = ElementSearcher( primitive.TAG, self._adjacent_resource_id, self._group_element, ) if adjacent_searcher.element_found(): self._adjacent_resource_element = ( adjacent_searcher.get_element()) else: # pylint: disable=line-too-long report_list.append( ReportItem.error( reports.messages. CannotGroupResourceAdjacentResourceNotInGroup( self._adjacent_resource_id, self._group_id, ))) # The group will be created so there is no adjacent resource in it. elif group_missing_id_valid: # pylint: disable=line-too-long report_list.append( ReportItem.error( reports.messages. CannotGroupResourceAdjacentResourceForNewGroup( self._adjacent_resource_id, self._group_id, ))) # else: The group_id belongs to a non-group element, checking the # adjacent_reource is pointless. report_list.extend( self._validate_elements( bad_or_missing_group_specified=(self._group_element is None), bad_resources_specified=(self._resource_id_list and not self._resource_element_list), bad_adjacent_specified=( self._adjacent_resource_id and self._adjacent_resource_element is None), )) return report_list
def validate(self, resources_section, id_provider): """ Run the validation and return a report item list etree.Element resources_section -- resources section of a cib IdProvider id_provider -- elements' ids generator and uniqueness checker """ report_list = [] # Check that group_id either matches an existing group element or is # not occupied by any other element. group_missing_id_valid = False group_searcher = ElementSearcher( group.TAG, self._group_id, resources_section ) if group_searcher.element_found(): self._group_element = group_searcher.get_element() elif group_searcher.validate_book_id( id_provider, id_description="group name" ): group_missing_id_valid = True else: report_list.extend(group_searcher.get_errors()) # Get resource elements to move to the group. # Get all types of resources, so that validation can later tell for # example: 'C' is a clone, clones cannot be put into a group. If we # only searched for primitives here, we would get 'C' is not a # resource, which is not that informative. self._resource_element_list = common.find_resources_and_report( resources_section, self._resource_id_list, report_list ) # Get an adjacent resource element. if self._adjacent_resource_id is not None: # If the group already exists, check the adjacent resource is in it. if self._group_element is not None: adjacent_searcher = ElementSearcher( primitive.TAG, self._adjacent_resource_id, self._group_element, ) if adjacent_searcher.element_found(): self._adjacent_resource_element = ( adjacent_searcher.get_element() ) else: report_list.append( reports .cannot_group_resource_adjacent_resource_not_in_group( self._adjacent_resource_id, self._group_id, ) ) # The group will be created so there is no adjacent resource in it. elif group_missing_id_valid: report_list.append( reports .cannot_group_resource_adjacent_resource_for_new_group( self._adjacent_resource_id, self._group_id, ) ) # else: The group_id belongs to a non-group element, checking the # adjacent_reource is pointless. report_list.extend( self._validate_elements( bad_or_missing_group_specified=( self._group_element is None ), bad_resources_specified=( self._resource_id_list and not self._resource_element_list ), bad_adjacent_specified=( self._adjacent_resource_id and self._adjacent_resource_element is None ) ) ) return report_list