e2e_tests/tests/test_env_resolution.py
Daniel f9c21c6e6b refactor for independent test dirs (#7)
* make it so that the actual tests can be moved anywhere, for example in abra recipe repos
-> major refactoring with pytest test discovery magic

* create RUNNER_DICT dynamically with importlib
-> none of the tests are hardcoded, more tests can be added by placing a folder

* autoload fixtures with pytest plugins

* add URL fixture to navigate on web pages. Includes url parser based on python urllib to generate correct links

* fix nextcloud setups and tests

*  add email groundwork with imbox

Reviewed-on: local-it-infrastructure/e2e_tests#7
Co-authored-by: Daniel <d.brummerloh@gmail.com>
Co-committed-by: Daniel <d.brummerloh@gmail.com>
2023-12-05 21:41:43 +01:00

104 lines
4.2 KiB
Python

from pathlib import Path
import pytest
from abratest.coordinator import Coordinator
from abratest.env_manager import DependencyRule, EnvFile, EnvManager
RECIPES_DIR = Path("./recipes").resolve()
RUNNER_DICT = Coordinator.create_runner_dict(RECIPES_DIR)
def test_complex_sorting() -> None:
demo_rules = [ # X depends on Y
DependencyRule("a", "e"),
DependencyRule("b", "e"),
DependencyRule("b", "f"),
DependencyRule("c", "e"),
DependencyRule("d", "e"),
DependencyRule("f", "e"),
]
demo_types = ["a", "b", "c", "d", "e", "f", "g"]
env_files = [EnvFile(env_type=t, env_path=Path(), config=dict()) for t in demo_types]
EnvManager.sort_env_files_by_rule
sorted_env_files = EnvManager.sort_env_files_by_rule(env_files, demo_rules)
assert sorted_env_files[0].env_type == "e"
def test_circular_import() -> None:
"""This test will raise ValueError because the example input cannot be correctly ordered"""
demo_rules = [
DependencyRule("a", "b"),
DependencyRule("b", "c"),
DependencyRule("c", "a"),
]
demo_types = ["a", "b", "c"]
env_files = [EnvFile(env_type=t, env_path=Path(), config=dict()) for t in demo_types]
with pytest.raises(ValueError):
EnvManager.sort_env_files_by_rule(env_files, demo_rules)
def test_real_env_files() -> None:
"""authentik should be first"""
ENV_FILES = [
Path("envfiles/blog.test.dev.local-it.cloud.env"), # wordpress
Path("envfiles/login.test.dev.local-it.cloud.env"), # authentik
]
env_files: list[EnvFile] = EnvManager._get_env_files(ENV_FILES)
dependency_rules: list[DependencyRule] = EnvManager._get_dependency_rules(env_files, RUNNER_DICT)
sorted_env_files = EnvManager.sort_env_files_by_rule(env_files, dependency_rules)
assert sorted_env_files[0].env_type == "authentik"
def test_real_env_files_duplicate() -> None:
"""authentik should be first"""
ENV_FILES = [
Path("envfiles/blog.test.dev.local-it.cloud.env"), # wordpress
Path("envfiles/login.test.dev.local-it.cloud.env"), # authentik
Path("envfiles/login.test.dev.local-it.cloud.env"), # authentik
]
env_files: list[EnvFile] = EnvManager._get_env_files(ENV_FILES)
dependency_rules: list[DependencyRule] = EnvManager._get_dependency_rules(env_files, RUNNER_DICT)
sorted_env_files = EnvManager.sort_env_files_by_rule(env_files, dependency_rules)
assert sorted_env_files[0].env_type == "authentik"
assert sorted_env_files[1].env_type == "authentik"
assert sorted_env_files[2].env_type == "wordpress"
def test_real_env_files_duplicate_six() -> None:
"""authentik should be first"""
ENV_FILES = [
Path("envfiles/blog.test.dev.local-it.cloud.env"), # wordpress
Path("envfiles/login.test.dev.local-it.cloud.env"), # authentik
Path("envfiles/blog.test.dev.local-it.cloud.env"), # wordpress
Path("envfiles/login.test.dev.local-it.cloud.env"), # authentik
Path("envfiles/login.test.dev.local-it.cloud.env"), # authentik
Path("envfiles/blog.test.dev.local-it.cloud.env"), # wordpress
]
env_files: list[EnvFile] = EnvManager._get_env_files(ENV_FILES)
dependency_rules: list[DependencyRule] = EnvManager._get_dependency_rules(env_files, RUNNER_DICT)
sorted_env_files = EnvManager.sort_env_files_by_rule(env_files, dependency_rules)
assert sorted_env_files[0].env_type == "authentik"
assert sorted_env_files[1].env_type == "authentik"
assert sorted_env_files[2].env_type == "authentik"
assert sorted_env_files[3].env_type == "wordpress"
assert sorted_env_files[4].env_type == "wordpress"
assert sorted_env_files[5].env_type == "wordpress"
def test_env_manager() -> None:
env_paths_list = [
Path("envfiles/blog.test.dev.local-it.cloud.env"), # wordpress
Path("envfiles/login.test.dev.local-it.cloud.env"), # authentik
Path("envfiles/login.test.dev.local-it.cloud.env"), # authentik
]
ENV = EnvManager(env_paths_list, RUNNER_DICT)
assert ENV.env_files[0].env_type == "authentik"
assert ENV.env_files[1].env_type == "authentik"
assert ENV.env_files[2].env_type == "wordpress"