Esempio n. 1
0
def load_dynamodb_resource(resource_name: str,
                           additional_replacements: Dict[str, Any] = {}):
    """ Overrides the default `load_resource_file` to access the specific resources
    directory for the current service.
    """
    return load_resource_file(resource_directory,
                              resource_name,
                              additional_replacements=additional_replacements)
def load_resource(
        resource_name: str,
        additional_replacements: Dict[str, Any] = {},
):
    """Calls acktest.resources.load_resource_file to access the specific
    resources directory for the current service.
    """
    return load_resource_file(
        resource_directory,
        resource_name,
        additional_replacements=additional_replacements,
    )
    def __init__(self, resource_directory: Path, config: StepDict, custom_resource_details: dict, replacements: dict = {}):
        self.config = config
        self.custom_resource_details = custom_resource_details
        self.replacements = replacements

        self.verb = None
        self.input_data = {}
        self.expectations: ExpectDict = None

        # (k8s.CustomResourceReference, ko) to teardown
        self.teardown_list = []

        # validate: only one verb per step
        step_verb = None
        for verb in list(Verb):
            if verb.name in self.config:
                if not step_verb:
                    step_verb = verb
                else:
                    raise ValueError(f"Multiple verbs specified for step: {self.id}."
                                     f" Please specify only one verb from"
                                     f" supported verbs: { {verb.name for verb in list(Verb)} }.")

        # a step with no verb can be used to assert preconditions
        # thus, verb is optional.
        if step_verb:
            self.verb = step_verb
            self.input_data = self.config.get(step_verb.name)
            if type(self.input_data) is str:
                if self.input_data.endswith(".yaml"):
                    # load input data from resource file
                    resource_file_name = self.input_data
                    resource_file_path = Path(join(resource_directory, resource_file_name))
                    self.input_data = load_resource_file(
                        resource_file_path.parent, resource_file_path.stem, additional_replacements=replacements)
                else:
                    # consider the input as resource name string
                    # confirm that self.custom_resource_details must be provided with same name
                    if self.custom_resource_details["metadata"]["name"] != self.input_data:
                        raise ValueError(f"Unable to determine input data for '{self.verb}' at step: {self.id}")
                    # self.custom_resource_details will be mixed in into self.input_data
                    self.input_data = {}

        if len(self.input_data) == 0 and not self.custom_resource_details:
            raise ValueError(f"Unable to determine custom resource at step: {self.id}")

        if self.custom_resource_details:
            self.input_data = {**self.custom_resource_details, **self.input_data}

        self.wait = self.config.get("wait")
        self.expectations = self.config.get("expect")
def load_scenario(scenario_file: Path, resource_directory: Path = None, replacements: dict = {}) -> model.Scenario:
    """Loads scenario from given scenario_file

    Args:
        scenario_file: yaml file containing scenario
        resource_directory: Path to custom resources directory
        replacements: input replacements

    Returns:
        Scenario reference
    """

    scenario_name = scenario_file.stem
    replacements = replacements.copy()
    replacements["RANDOM_SUFFIX"] = random_suffix_name("", 16)
    scenario = model.Scenario(resource_directory, load_resource_file(
        scenario_file.parent, scenario_name, additional_replacements=replacements), replacements)
    return scenario
def marks(scenario_file_path: Path) -> List:
    """Provides pytest markers for the given scenario

    Args:
        scenario_file_path: test scenario file path

    Returns:
        pytest markers for the scenario
    """

    scenario_config = load_resource_file(
        scenario_file_path.parent, scenario_file_path.stem)

    markers = []
    for mark in scenario_config.get("marks", []):
        if mark == "canary":
            markers.append(pytest.mark.canary)
        elif mark == "slow":
            markers.append(pytest.mark.slow)
        elif mark == "blocked":
            markers.append(pytest.mark.blocked)
    return markers