new functional_tests.container_commands file discerns local from server containers; .base calls now calls reset_database() therefrom; .test_my_lists also discerns test server location for different session keys; functional_tests restored as app in core.settings
This commit is contained in:
56
src/functional_tests/container_commands.py
Normal file
56
src/functional_tests/container_commands.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import subprocess
|
||||
|
||||
USER = "discoman"
|
||||
|
||||
|
||||
def reset_database(host):
|
||||
return _exec_in_container(
|
||||
host, ["/.venv/bin/python", "/src/manage.py", "flush", "--noinput"]
|
||||
)
|
||||
|
||||
def create_session_on_server(host, email):
|
||||
return _exec_in_container(
|
||||
host, ["/.venv/bin/python", "/src/manage.py", "create_session", email]
|
||||
)
|
||||
|
||||
def _exec_in_container(host, commands):
|
||||
if "localhost" in host:
|
||||
return _exec_in_container_locally(commands)
|
||||
else:
|
||||
return _exec_in_container_on_server(host, commands)
|
||||
|
||||
def _exec_in_container_locally(commands):
|
||||
print(f"Running {commands} on inside local docker container")
|
||||
return _run_commands(["docker", "exec", _get_container_id()] + commands)
|
||||
|
||||
def _exec_in_container_on_server(host, commands):
|
||||
print(f"Running {commands!r} on {host} inside docker container")
|
||||
return _run_commands(
|
||||
[
|
||||
"ssh",
|
||||
"-i",
|
||||
"c:/Users/adamc/.ssh/digitalocean_keys/id_ed25519_wsl_python-tdd",
|
||||
f"{USER}@{host}",
|
||||
"docker",
|
||||
"exec",
|
||||
"gamearray",
|
||||
] + commands
|
||||
)
|
||||
|
||||
def _get_container_id():
|
||||
return subprocess.check_output(
|
||||
["docker", "ps", "-q", "--filter", "ancestor=gamearray"]
|
||||
).strip()
|
||||
|
||||
def _run_commands(commands):
|
||||
process = subprocess.run(
|
||||
commands,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
check=False,
|
||||
)
|
||||
result = process.stdout.decode()
|
||||
if process.returncode != 0:
|
||||
raise Exception(result)
|
||||
print(f"Result: {result!r}")
|
||||
return result.strip()
|
||||
Reference in New Issue
Block a user