Skip to content

Commit 288e37a

Browse files
author
Max Azatian
committed
CI fix 11 | mongodb conn string in conftest
1 parent 9d6cc8b commit 288e37a

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

.github/workflows/tests.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,9 @@ jobs:
139139
- name: Run backend tests with coverage
140140
env:
141141
BACKEND_BASE_URL: https://127.0.0.1:443
142-
MONGODB_URL: mongodb://${{ secrets.MONGO_ROOT_USER }}:${{ secrets.MONGO_ROOT_PASSWORD }}@127.0.0.1:27017/?authSource=admin
143142
run: |
144143
cd backend
145144
echo "Using BACKEND_BASE_URL=$BACKEND_BASE_URL"
146-
echo "Using MONGODB_URL=$MONGODB_URL"
147145
python -m pytest tests/integration tests/unit -v --cov=app --cov-branch --cov-report=xml --cov-report=term --cov-report=term-missing
148146
149147
- name: Upload coverage to Codecov

backend/tests/conftest.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,20 @@
4444
os.environ.setdefault("OTEL_TRACES_EXPORTER", "none")
4545

4646
# Force localhost endpoints to avoid Docker DNS names like 'mongo'
47-
os.environ.setdefault("MONGODB_URL", "mongodb://root:rootpassword@localhost:27017/?authSource=admin")
47+
# Do not override if MONGODB_URL is already provided in the environment.
48+
if "MONGODB_URL" not in os.environ:
49+
from urllib.parse import quote_plus
50+
user = os.environ.get("MONGO_ROOT_USER", "root")
51+
pwd = os.environ.get("MONGO_ROOT_PASSWORD", "rootpassword")
52+
host = os.environ.get("MONGODB_HOST", "127.0.0.1")
53+
port = os.environ.get("MONGODB_PORT", "27017")
54+
try:
55+
u = quote_plus(user)
56+
p = quote_plus(pwd)
57+
except Exception:
58+
u = user
59+
p = pwd
60+
os.environ["MONGODB_URL"] = f"mongodb://{u}:{p}@{host}:{port}/?authSource=admin"
4861
os.environ.setdefault("KAFKA_BOOTSTRAP_SERVERS", "localhost:9092")
4962
os.environ.setdefault("REDIS_HOST", "localhost")
5063
os.environ.setdefault("REDIS_PORT", "6379")

0 commit comments

Comments
 (0)