Exemplo n.º 1
0
 def test_more_existing(self):
     resource_list, report_list = common.find_resources(
         self.cib, ["R1", "R2"])
     self.assertEqual(
         ["R1", "R2"],
         [resource.attrib.get("id") for resource in resource_list],
     )
     assert_report_item_list_equal(report_list, [])
Exemplo n.º 2
0
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
    """
    dummy_resources, report_list = find_resources(resources_section, idref_list)
    return report_list
Exemplo n.º 3
0
 def test_more_some_missing(self):
     resource_list, report_list = common.find_resources(
         self.cib, ["R1", "R2", "RY1", "RY2"])
     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"),
         ],
     )
Exemplo n.º 4
0
    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, my_report_list = common.find_resources(
            resources_section, self._resource_id_list)
        report_list.extend(my_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