Beispiel #1
0
    def test_get_traversal_path_with_test_case_def(self):
        # Determine expected results
        test_suite_name = 'EXAMPLE_1'

        num_test_cases = 2
        test_case_name = 'test_{num}'.format(
            num=choice([x + 1 for x in range(num_test_cases)]))

        num_steps_in_test_case = 4
        step_names = [f"STEP_{x + 1}" for x in range(num_steps_in_test_case)]

        # Determine data file path
        data_file = get_data_file(filename=self.SAMPLE_PATH,
                                  test_dir_name=self.TEST_DIR_NAME,
                                  data_dir_name=self.DATA_DIR_NAME)

        # Execute routine
        state_path_obj = StatePathsYaml(data_file)
        tc_def = state_path_obj.build_test_case(test_suite=test_suite_name,
                                                test_name=test_case_name)
        traversal_path = state_path_obj.get_traversal_path(
            test_case_def=tc_def)

        assert_equals(len(traversal_path), num_steps_in_test_case)
        for trigger in traversal_path:
            assert_in(trigger, step_names)
Beispiel #2
0
    def test_build_test_case_with_invalid_info(self, mock_inv_resp: str):

        test_suite_name = "EXAMPLE_1"
        test_case_name = "test_1"

        # Determine data file path
        data_file = get_data_file(filename=self.SAMPLE_PATH,
                                  test_dir_name=self.TEST_DIR_NAME,
                                  data_dir_name=self.DATA_DIR_NAME)

        # Execute routine (with mocked response in build_test_case)
        state_path_obj = StatePathsYaml(data_file)
        tc_def = state_path_obj.build_test_case(test_suite=test_suite_name,
                                                test_name=test_case_name)

        assert_equals(tc_def, [])
Beispiel #3
0
    def test_build_test_case_without_params(self):
        # Determine expected results
        test_suite_name = None
        test_case_name = None

        # Determine data file path
        data_file = get_data_file(filename=self.SAMPLE_PATH,
                                  test_dir_name=self.TEST_DIR_NAME,
                                  data_dir_name=self.DATA_DIR_NAME)

        # Execute routine
        state_path_obj = StatePathsYaml(data_file)
        tc_def = state_path_obj.build_test_case(test_suite=test_suite_name,
                                                test_name=test_case_name)

        assert_equals(len(tc_def), 0)
Beispiel #4
0
    def test_get_path_validation_expectations_with_test_def(self):
        # Test the StatePathYaml.get_test_validation_expectations() with a
        # valid testcase and testsuite

        expected_test_suite = 'EXAMPLE_1'
        expected_test_case = 'test_1'
        num_expectations = 2
        expectation_ids = [
            f"expectation_{x + 1}" for x in range(num_expectations)
        ]

        # Determine data file path
        data_file = get_data_file(filename=self.SAMPLE_PATH,
                                  test_dir_name=self.TEST_DIR_NAME,
                                  data_dir_name=self.DATA_DIR_NAME)

        # Execute routine
        state_path_obj = StatePathsYaml(data_file)
        test_def = state_path_obj.build_test_case(
            test_suite=expected_test_suite, test_name=expected_test_case)
        expectations = state_path_obj.get_path_validation_expectations(
            test_case_def=test_def)

        # Verify expectations is a non-empty list
        assert_true(isinstance(expectations, list))
        assert_not_equals(expectations, [])

        # Verify each entry in the list (dictionary of dictionaries) has the
        # expected keys and the values are the correct data type (bool)
        for step in expectations:
            step_name = list(step.keys())[0]
            logging.info(f"STEP NAME: {step_name}")
            expectation_dict = list(step.values())[0]

            # Verify the keys are correct
            for exp_id in expectation_ids:
                assert_in(
                    exp_id, list(expectation_dict.keys()),
                    f"{step_name}: Expected key ({exp_id}) was not found "
                    f"in the list of defined keys.")

                # Verify the values are booleans
                for key, exp in list(expectation_dict.items()):
                    assert_true(
                        isinstance(exp, bool),
                        f"{step_name}: Expected value {str(exp)} for "
                        f"{key} was not a boolean")
Beispiel #5
0
    def test_build_test_case_with_correct_params(self):
        # Determine expected results
        test_suite_name = "EXAMPLE_1"
        test_case_name = "test_1"
        test_case_steps = 4
        step_names = [f"STEP_{x + 1}" for x in range(test_case_steps)]

        # Determine data file path
        data_file = get_data_file(filename=self.SAMPLE_PATH,
                                  test_dir_name=self.TEST_DIR_NAME,
                                  data_dir_name=self.DATA_DIR_NAME)

        # Execute routine
        state_path_obj = StatePathsYaml(data_file)
        tc_def = state_path_obj.build_test_case(test_suite=test_suite_name,
                                                test_name=test_case_name)
        tc_step_names = [x.trigger for x in tc_def]

        assert_equals(len(tc_def), test_case_steps)
        for step in tc_step_names:
            assert_in(step, step_names)
Beispiel #6
0
    # Instantiate the Object model
    server_model = VmModel()

    # Instantiate and build the state machine
    machine = StateMachine(data_model=model_data, object_model=server_model)
    machine.BORDER_LEN = step_log_border_num_stars
    machine.NUM_ELEMS_PER_GRAPH_LINE = graph_steps_per_line
    machine.configure_state_machine()

    # Show a table with all of the state machine state definitions in the
    # specified state machine configuration file
    model_data.describe_model()

    # Get the requested test case
    test_case = tests.build_test_case(test_suite=test_suite_name,
                                      test_name=test_case_name)
    if not test_case:
        logging.error('Test path does not have any triggers defined.')
        exit()

    # Validate that the test case contains valid transitions
    # (all transitions exist in the state machine)
    if model_data.validate_path(tests.get_traversal_path()):
        logging.info(f"Traversal Path: {tests.get_traversal_path()}")

        # Execute the state machine
        machine.execute_state_machine(
            input_data=test_case,
            description=f"({test_suite_name}:{test_case_name})")

        # Log the results