Exemplo n.º 1
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.º 2
0
    def _add_and_validate_expectations(
            self, validation_ids: List[str],
            expectations: List[bool]) -> NoReturn:

        # Add requested expectations
        step = PathStep(trigger=self.TRIGGER_NAME)
        for id_, expect in zip(validation_ids, expectations):
            step.add_expectation(
                validation_id=id_, expectation=expect)

        # Verify the expectations were added correctly (format and value)
        assert_equals(len(step.expectations), len(validation_ids))
        for index in range(len(validation_ids)):
            assert_equals(
                step.expectations[index][PathStep.ID],
                validation_ids[index])
            assert_equals(
                step.expectations[index][PathStep.EXPECTATION],
                expectations[index])
Exemplo n.º 3
0
    def test_get_expectations(self):

        # Verify requested expectation value is returned

        validation_ids = ['test_1', 'test_2']
        expectations = [False, True]
        target_index = choice(range(len(expectations)))

        logging.info(f"Selecting expectation element: {target_index}")

        # Add expectations
        step = PathStep(trigger=self.TRIGGER_NAME)
        for id_, expect in zip(validation_ids, expectations):
            step.add_expectation(
                validation_id=id_, expectation=expect)

        # Get randomly selected expectation (selected from expectations added)
        expectation = step.get_expectation(validation_ids[target_index])

        # Verify return value matches the expectation
        assert_equals(expectation, expectations[target_index])
Exemplo n.º 4
0
    def _define_path_step(self,
                          trigger_name: str = None,
                          trigger_id: str = None) -> PathStep:
        """
        Builds a simple path step with a name, id, expectations,
        and data

        Args:
            trigger_name (str): Name of trigger/step
            trigger_id (str): Unique id for trigger/step

        Returns:
            Instantiated and populated PathStep object
        """

        trigger_name = trigger_name or self.TRIGGER_NAME
        trigger_id = trigger_id or self.TRIGGER_ID

        step = PathStep(trigger=trigger_name, trigger_id=trigger_id)
        step.add_data(self.STEP_DATA)
        for validation_id, expectation in self.EXPECTATIONS.items():
            step.add_expectation(validation_id, expectation)
        return step