1- from typing import Generator
2-
31import pytest
42import sqlalchemy
53
6- from dor .adapters .catalog import Base , SqlalchemyCatalog , _custom_json_serializer
7- from dor .config import config
8-
9-
10- @pytest .fixture
11- def db_session () -> Generator [sqlalchemy .orm .Session , None , None ]:
12- engine_url = config .get_test_database_engine_url ()
13- engine = sqlalchemy .create_engine (
14- engine_url , echo = True , json_serializer = _custom_json_serializer
15- )
16-
17- Base .metadata .drop_all (engine )
18- Base .metadata .create_all (engine )
19-
20- connection = engine .connect ()
21- session = sqlalchemy .orm .Session (bind = connection )
22-
23- yield session
24-
25- session .close ()
26- connection .close ()
4+ from dor .adapters .catalog import SqlalchemyCatalog
275
286
29- @pytest .mark .usefixtures ("sample_bin" )
7+ @pytest .mark .usefixtures ("db_session" , " sample_bin" )
308def test_catalog_adds_bin (db_session , sample_bin ) -> None :
319 catalog = SqlalchemyCatalog (db_session )
3210 with db_session .begin ():
@@ -44,7 +22,7 @@ def test_catalog_adds_bin(db_session, sample_bin) -> None:
4422 assert str (rows [0 ].identifier ) == "00000000-0000-0000-0000-000000000001"
4523
4624
47- @pytest .mark .usefixtures ("sample_bin" )
25+ @pytest .mark .usefixtures ("db_session" , " sample_bin" )
4826def test_catalog_gets_bin (db_session , sample_bin ) -> None :
4927 catalog = SqlalchemyCatalog (db_session )
5028 with db_session .begin ():
@@ -55,7 +33,7 @@ def test_catalog_gets_bin(db_session, sample_bin) -> None:
5533 assert bin == sample_bin
5634
5735
58- @pytest .mark .usefixtures ("sample_bin" )
36+ @pytest .mark .usefixtures ("db_session" , " sample_bin" )
5937def test_catalog_gets_by_alternate_identifier (db_session , sample_bin ) -> None :
6038 catalog = SqlalchemyCatalog (db_session )
6139 with db_session .begin ():
@@ -66,7 +44,7 @@ def test_catalog_gets_by_alternate_identifier(db_session, sample_bin) -> None:
6644 assert bin == sample_bin
6745
6846
69- @pytest .mark .usefixtures ("sample_bin" )
47+ @pytest .mark .usefixtures ("db_session" , " sample_bin" )
7048def test_catalog_returns_none_when_no_alternate_identifier_matches (db_session , sample_bin ) -> None :
7149 catalog = SqlalchemyCatalog (db_session )
7250 with db_session .begin ():
0 commit comments