Skip to content

Commit a091f23

Browse files
authored
Merge pull request #5 from kbase/dev-client
Allow rerunning tests without restarting docker compose
2 parents 28ed216 + 6096294 commit a091f23

File tree

4 files changed

+97
-4
lines changed

4 files changed

+97
-4
lines changed

docker-compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ services:
77
- 50001:8080
88
environment:
99
mongo_host: "mongodb:27017"
10+
mongo_db: "auth2_python_client_test"
1011
test_mode_enabled: "true"
1112
identity_providers: ""
1213
command:

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ classifiers = [
1212
"Operating System :: OS Independent",
1313
]
1414
dependencies = [
15+
"cacheout==0.16.0",
1516
"httpx==0.28.1",
1617
]
1718

@@ -25,6 +26,7 @@ packages = ["src/kbase"]
2526
[dependency-groups]
2627
dev = [
2728
"ipython==9.5.0",
29+
"pymongo==4.15.2",
2830
"pytest==8.4.2",
2931
"pytest-asyncio==1.2.0",
3032
"pytest-cov==7.0.0",

test/conftest.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import os
3+
from pymongo.mongo_client import MongoClient
34
import pytest
45
import requests
56
import subprocess
@@ -8,6 +9,9 @@
89

910
# settings come from the docker-compose file
1011

12+
MONGO_HOST = "localhost:27017"
13+
MONGO_DB = 'auth2_python_client_test'
14+
1115
_COMPOSE_FILE = "docker-compose.yaml"
1216
_COMPOSE_PROJECT_NAME = "auth_client_tests"
1317
_AUTH_SERVICE_NAME = "auth"
@@ -61,13 +65,24 @@ def _run_dc(env, *args):
6165
)
6266

6367

68+
def _clear_auth_db():
69+
mc = MongoClient(MONGO_HOST)
70+
db = mc[MONGO_DB]
71+
# don't drop db since that drops indexes
72+
for name in db.list_collection_names():
73+
if not name.startswith("system."):
74+
# don't drop collection since that drops indexes
75+
db.get_collection(name).delete_many({})
76+
77+
6478
@pytest.fixture(scope="session", autouse=True)
6579
def docker_compose():
6680
env = os.environ.copy()
6781
print("Starting docker-compose...")
6882
try:
6983
_run_dc(env, "up", "-d", "--build")
7084
_wait_for_services()
85+
_clear_auth_db() # in case the compose was left up
7186
yield # run the tests
7287
logarg = os.environ.get("AUTH_TEST_DUMP_LOGS")
7388
if logarg:
@@ -76,9 +91,9 @@ def docker_compose():
7691
else:
7792
_run_dc(env, "logs")
7893
finally:
79-
print("Stopping docker-compose...")
80-
# TODO TEST add a way to keep things running and be able to rerun tests
81-
_run_dc(env, "down")
94+
if not os.environ.get("AUTH_TEST_LEAVE_COMPOSE_UP"):
95+
print("Stopping docker-compose...")
96+
_run_dc(env, "down")
8297

8398

8499
@pytest.fixture(scope="session", autouse=True)

uv.lock

Lines changed: 76 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)