Skip to content

Commit

Permalink
[FIX] Adapat test
Browse files Browse the repository at this point in the history
  • Loading branch information
josep-tecnativa committed Feb 13, 2025
1 parent cb0b37a commit 39d6be0
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions tests/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,33 @@

from .conftest import DBVER_PER_ODOO

try:
from python_on_whales.components.compose.models import ComposeConfig
except ImportError:
ComposeConfig = None


def _get_db_service_name(dc: DockerClient) -> str:
config_data = dc.compose.config()

# (1) In newer versions of python-on-whales:
# config_data is a ComposeConfig => config_data.services is a dict:
# { "service_name": ServiceConfig(...) }
# (2) In older versions: config_data is a "legacy" dict
# => config_data["services"] => { "service_name": {...} }

if ComposeConfig and isinstance(config_data, ComposeConfig):
services_dict = config_data.services
else:
services_dict = config_data["services"]
for svc_name in services_dict:
if svc_name.lower().endswith("-db"):
return svc_name
for svc_name in services_dict:
if "postgres" in svc_name.lower() or "db" in svc_name.lower():
return svc_name
return "db"


@pytest.mark.parametrize("dbver", ("oldest", "latest"))
def test_postgresql_client_versions(
Expand All @@ -17,18 +44,24 @@ def test_postgresql_client_versions(
dbver: str,
):
"""Test multiple postgresql-client versions in odoo, db and duplicity services"""
unique_project_name = f"test_{uuid.uuid4().hex}"
dc_prod = DockerClient(
compose_files=["prod.yaml"],
compose_project_name=unique_project_name,
)

dbver_raw = DBVER_PER_ODOO[supported_odoo_version][dbver]
dbver_mver = dbver_raw.split(".")[0]
dc_prod = DockerClient(compose_files=["prod.yaml"])

with local.cwd(tmp_path):
print(str(cloned_template))
assert True

run_copy(
str(cloned_template),
dst_path=".",
data={
"odoo_version": supported_odoo_version,
"project_name": uuid.uuid4().hex,
"project_name": unique_project_name,
"odoo_proxy": "",
"postgres_version": dbver_raw,
"backup_dst": "/tmp/dummy",
Expand All @@ -40,6 +73,7 @@ def test_postgresql_client_versions(
)
try:
dc_prod.compose.build()
db_svc = _get_db_service_name(dc_prod)
odoo_pgdump_stdout = dc_prod.compose.run(
"odoo",
command=["pg_dump", "--version"],
Expand All @@ -50,7 +84,7 @@ def test_postgresql_client_versions(
odoo_pgdump_stdout.splitlines()[-1].strip().split(" ")[2].split(".")[0]
)
db_pgdump_stdout = dc_prod.compose.run(
"db",
db_svc,
command=["pg_dump", "--version"],
remove=True,
tty=False,
Expand Down

0 comments on commit 39d6be0

Please sign in to comment.