Exemplo n.º 1
0
    def test_add_id(self):

        # Verify ID is added to PathStep correctly

        test_id = str(uuid4())
        step = PathStep(trigger=self.TRIGGER_NAME)
        step.add_id(step_id=test_id)

        assert_equals(step.id, test_id)
Exemplo n.º 2
0
    def build_test_case(self, test_suite: str,
                        test_name: str) -> typing.List[PathStep]:
        """
        Get the test case definition for the specified test suite & test case

        Args:
            test_suite (str): Name of test suite (ConfigParser section)
            test_name (str): Name of test case (Config Parser section option)

        Returns:
            (list[dict]) Paths for state machine with execution
            and validation parameters

        """
        test_cases = self.get_possible_test_cases(test_suite)

        # Check if test case is defined...
        if test_name not in test_cases:
            logging.error(f"The test case '{test_name}' was not found in "
                          f"specified suite: '{test_suite}'")
            return []

        # Get test suite data, get the test case steps and return list
        ts_data = [x for x in self.data if test_suite in x][0][test_suite]

        test_case = []
        for tc in ts_data[test_name].get(YamlPathConsts.STEPS, []):
            step = PathStep(trigger=list(tc.keys())[0])

            # Record the trigger's unique id (if present)
            if YamlPathConsts.ID in tc[step.trigger]:
                step.add_id(tc[step.trigger][YamlPathConsts.ID])

            # Save validation expectations (id corresponds to specific
            # validation routine associated with step and result is the
            # expectation)
            if tc[step.trigger][YamlPathConsts.EXPECTATIONS] is not None:
                for v_id, exp in \
                        tc[step.trigger][YamlPathConsts.EXPECTATIONS].items():
                    step.add_expectation(v_id, exp)

            # Save the data to passed to the trigger if provided
            if (tc[step.trigger][YamlPathConsts.DATA] is not None
                    or tc[step.trigger][YamlPathConsts.DATA] != {}):
                step.add_data(tc[step.trigger][YamlPathConsts.DATA])

            test_case.append(step)

        self.test_case = test_case

        valid_path = ValidatePaths.validate_steps(steps=self.test_case)
        if not valid_path:
            logging.error("Errors found in the path definitions. "
                          "Returning an empty list of steps.")

        return self.test_case if valid_path else []
Exemplo n.º 3
0
    def test__str__does_not_crash(self):
        test_id = str(uuid4())
        validation_ids = ['test']
        expectations = [False]

        step = PathStep(trigger=self.TRIGGER_NAME)
        step.add_id(step_id=test_id)
        self._add_and_validate_expectations(
            validation_ids=validation_ids, expectations=expectations)

        assert_true(isinstance(str(step), str))