Commit 67a4e0d0 authored by Samuel GAIST's avatar Samuel GAIST

[test] Refactor initialization to make it more reusable

beat/beat.cmdline re-implements similar parts so
make them reusable
parent 1492e907
Pipeline #45200 passed with stage
in 25 minutes and 14 seconds
......@@ -59,8 +59,6 @@ else:
prefix = os.path.join(prefix_folder, "prefix")
BC_DATABASE_ROOT_FOLDER = os.path.join(prefix_folder, "beat_core_test")
DOCKER_NETWORK_TEST_ENABLED = (
os.environ.get("DOCKER_NETWORK_TEST_ENABLED", False) == "True"
)
......@@ -87,18 +85,15 @@ if VERBOSE_TEST_LOGGING:
logger.addHandler(handler)
def setup_package():
prefixes = [
pkg_resources.resource_filename("beat.backend.python.test", "prefix"),
pkg_resources.resource_filename("beat.core.test", "prefix"),
]
def sync_prefixes(source_prefixes, target_prefix):
for path in source_prefixes:
sp.check_call(["rsync", "-arz", path, target_prefix])
for path in prefixes:
sp.check_call(["rsync", "-arz", path, prefix_folder])
os.makedirs(BC_DATABASE_ROOT_FOLDER, exist_ok=True)
def initialize_db_root_folder(database_root_folder, databases_path):
os.makedirs(database_root_folder, exist_ok=True)
for root, dirs, files in os.walk(os.path.join(prefix, "databases"), topdown=False):
for root, dirs, files in os.walk(databases_path, topdown=False):
for file_ in files:
if file_.endswith(".json"):
path = os.path.join(root, file_)
......@@ -109,10 +104,24 @@ def setup_package():
# some are explicitly invalid.
continue
else:
declaration["root_folder"] = BC_DATABASE_ROOT_FOLDER
declaration["root_folder"] = database_root_folder
with open(path, "wt") as db_file:
json.dump(declaration, db_file, indent=4)
def setup_package():
sync_prefixes(
[
pkg_resources.resource_filename("beat.backend.python.test", "prefix"),
pkg_resources.resource_filename("beat.core.test", "prefix"),
],
prefix_folder,
)
initialize_db_root_folder(
os.path.join(prefix_folder, "beat_core_test"), os.path.join(prefix, "databases")
)
if DOCKER_NETWORK_TEST_ENABLED:
import docker
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment