Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jin-Sun-tts committed Mar 19, 2024
1 parent 83dcfd0 commit 3bb736e
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

from sqlalchemy import create_engine, text
from sqlalchemy.orm import sessionmaker, scoped_session
from app.models import Base
from app.interface import HarvesterDBInterface
# from app.models import Base
# from app.interface import HarvesterDBInterface

from harvester.utils import open_json

Expand All @@ -16,34 +16,34 @@
HARVEST_SOURCES = Path(__file__).parents[0] / "harvest-sources"


@pytest.fixture(scope="session")
def db_session():
DATABASE_SERVER = os.getenv("DATABASE_SERVER")
DATABASE_URI = os.getenv("DATABASE_URI")
TEST_SCHEMA = "test_schema"
modified_uri = DATABASE_URI.replace("@" + DATABASE_SERVER, "@localhost")
engine = create_engine(modified_uri)
# @pytest.fixture(scope="session")
# def db_session():
# DATABASE_SERVER = os.getenv("DATABASE_SERVER")
# DATABASE_URI = os.getenv("DATABASE_URI")
# TEST_SCHEMA = "test_schema"
# modified_uri = DATABASE_URI.replace("@" + DATABASE_SERVER, "@localhost")
# engine = create_engine(modified_uri)

with engine.connect() as connection:
connection.execute(text(f"CREATE SCHEMA IF NOT EXISTS {TEST_SCHEMA};"))
connection.execute(text(f"SET search_path TO {TEST_SCHEMA};"))
# with engine.connect() as connection:
# connection.execute(text(f"CREATE SCHEMA IF NOT EXISTS {TEST_SCHEMA};"))
# connection.execute(text(f"SET search_path TO {TEST_SCHEMA};"))

Base.metadata.create_all(engine)
SessionLocal = sessionmaker(bind=engine)
# Base.metadata.create_all(engine)
# SessionLocal = sessionmaker(bind=engine)

session = scoped_session(SessionLocal)
yield session
# session = scoped_session(SessionLocal)
# yield session

session.remove()
engine.dispose()
# session.remove()
# engine.dispose()

with engine.begin() as connection:
connection.execute(text(f"DROP SCHEMA IF EXISTS {TEST_SCHEMA} CASCADE;"))
# with engine.begin() as connection:
# connection.execute(text(f"DROP SCHEMA IF EXISTS {TEST_SCHEMA} CASCADE;"))


@pytest.fixture(scope="session")
def db_interface(db_session):
return HarvesterDBInterface(db_session)
# @pytest.fixture(scope="session")
# def db_interface(db_session):
# return HarvesterDBInterface(db_session)


@pytest.fixture
Expand Down

0 comments on commit 3bb736e

Please sign in to comment.