Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ services:
- 50001:8080
environment:
mongo_host: "mongodb:27017"
mongo_db: "auth2_python_client_test"
test_mode_enabled: "true"
identity_providers: ""
command:
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ classifiers = [
"Operating System :: OS Independent",
]
dependencies = [
"cacheout==0.16.0",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be used in the next PR

"httpx==0.28.1",
]

Expand All @@ -25,6 +26,7 @@ packages = ["src/kbase"]
[dependency-groups]
dev = [
"ipython==9.5.0",
"pymongo==4.15.2",
"pytest==8.4.2",
"pytest-asyncio==1.2.0",
"pytest-cov==7.0.0",
Expand Down
21 changes: 18 additions & 3 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
from pymongo.mongo_client import MongoClient
import pytest
import requests
import subprocess
Expand All @@ -8,6 +9,9 @@

# settings come from the docker-compose file

MONGO_HOST = "localhost:27017"
MONGO_DB = 'auth2_python_client_test'

_COMPOSE_FILE = "docker-compose.yaml"
_COMPOSE_PROJECT_NAME = "auth_client_tests"
_AUTH_SERVICE_NAME = "auth"
Expand Down Expand Up @@ -61,13 +65,24 @@ def _run_dc(env, *args):
)


def _clear_auth_db():
mc = MongoClient(MONGO_HOST)
db = mc[MONGO_DB]
# don't drop db since that drops indexes
for name in db.list_collection_names():
if not name.startswith("system."):
# don't drop collection since that drops indexes
db.get_collection(name).delete_many({})


@pytest.fixture(scope="session", autouse=True)
def docker_compose():
env = os.environ.copy()
print("Starting docker-compose...")
try:
_run_dc(env, "up", "-d", "--build")
_wait_for_services()
_clear_auth_db() # in case the compose was left up
yield # run the tests
logarg = os.environ.get("AUTH_TEST_DUMP_LOGS")
if logarg:
Expand All @@ -76,9 +91,9 @@ def docker_compose():
else:
_run_dc(env, "logs")
finally:
print("Stopping docker-compose...")
# TODO TEST add a way to keep things running and be able to rerun tests
_run_dc(env, "down")
if not os.environ.get("AUTH_TEST_LEAVE_COMPOSE_UP"):
print("Stopping docker-compose...")
_run_dc(env, "down")


@pytest.fixture(scope="session", autouse=True)
Expand Down
77 changes: 76 additions & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.