removed usage of testcontainers

This commit is contained in:
brian
2025-03-06 22:02:06 +00:00
parent 31be0d7aac
commit 4bcfbbed0a
@@ -10,8 +10,6 @@ import minio
import pytest
from PIL import Image
from pymongo import MongoClient
from testcontainers.minio import MinioContainer
from testcontainers.mongodb import MongoDbContainer
from model.src.models import VisualCommunicationModel
from shared.repositories import (
@@ -48,58 +46,24 @@ env_var_map = {
'MINIO_OBJECT_NAME': 'test-object',
'MINIO_IMAGE_NAME': 'test-image',
'MONGO_ENDPOINT': (
f'mongodb://{MONGO_USERNAME}:{MONGO_PASSWORD}' f'@localhost:{MONGO_PORT}/'
f'mongodb://{MONGO_USERNAME}:{MONGO_PASSWORD}@localhost:{MONGO_PORT}/'
), # updated when container is running
'MONGO_DB': 'test-db',
'MONGO_COLLECTION': 'test-collection',
}
container_map = {
'minio': MinioContainer(
port=MINIO_PORT,
access_key=MINIO_ACCESS_KEY,
secret_key=MINIO_SECRET_KEY,
),
'mongo': MongoDbContainer(
port=MONGO_PORT,
username=MONGO_USERNAME,
password=MONGO_PASSWORD,
dbname=env_var_map['MONGO_DB'],
),
}
@pytest.fixture(scope='session', autouse=True)
def setup_infrastructure(request: pytest.FixtureRequest) -> None:
"""Prepare infrastructure for integration test."""
# prepare infrastructure
for container in container_map.values():
container.start()
# update env var map
minio_host = container_map['minio'].get_container_host_ip()
minio_port = container_map['minio'].get_exposed_port(MINIO_PORT)
env_var_map['MINIO_ENDPOINT'] = f'{minio_host}:{minio_port}'
mongo_host = container_map['mongo'].get_container_host_ip()
mongo_port = container_map['mongo'].get_exposed_port(MONGO_PORT)
env_var_map['MONGO_ENDPOINT'] = (
f'mongodb://{MONGO_USERNAME}:{MONGO_PASSWORD}@{mongo_host}:{mongo_port}/'
)
# ensure cleanup
def cleanup_infrastructure():
for container in container_map.values():
container.stop()
request.addfinalizer(cleanup_infrastructure)
@pytest.fixture(scope='session', autouse=True)
def populate_env(
request: pytest.FixtureRequest,
setup_infrastructure,
) -> None:
"""Populate environment with variables used for testing."""
# update env
for key, val in env_var_map.items():
# skip if already set by CI pipeline
if key in os.environ:
continue
# set env var
os.environ[key] = val
# ensure cleanup
@@ -112,7 +76,6 @@ def populate_env(
@pytest.fixture(scope='session')
def raw_minio_client(
setup_infrastructure,
populate_env,
) -> Iterator[minio.Minio]:
"""Raw Minio client fixture."""
@@ -145,7 +108,6 @@ def raw_minio_client(
@pytest.fixture
def minio_client(
setup_infrastructure,
populate_env,
) -> Iterator[MinioImplementation]:
"""MinioImplementation fixture."""
@@ -247,7 +209,6 @@ def image_data_in_minio(
@pytest.fixture(scope='session')
def image_repo(
setup_infrastructure,
populate_env,
) -> Iterator[ImageRepository]:
"""Image repository fixture."""
@@ -308,7 +269,6 @@ def model_data_in_minio(
@pytest.fixture(scope='session')
def model_repo(
setup_infrastructure,
populate_env,
) -> Iterator[ModelRepository]:
"""Model repository fixture."""
@@ -320,7 +280,6 @@ def model_repo(
@pytest.fixture
def raw_mongo_client(
setup_infrastructure,
populate_env,
) -> Iterator[MongoClient]:
"""Raw mongo client fixture."""
@@ -338,7 +297,6 @@ def raw_mongo_client(
@pytest.fixture
def mongo_client(
setup_infrastructure,
populate_env,
) -> Iterator[MongoImplementation]:
"""MongoImplementation fixture."""
@@ -434,7 +392,6 @@ def visual_communication_data_in_mongo(
@pytest.fixture(scope='session')
def visual_communication_repo(
setup_infrastructure,
populate_env,
) -> Iterator[VisualCommunicationRepository]:
"""Visual communication repository fixture."""