1
- from typing import Generator
2
-
3
1
import pytest
4
2
import sqlalchemy
5
3
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
27
5
28
6
29
- @pytest .mark .usefixtures ("sample_bin" )
7
+ @pytest .mark .usefixtures ("db_session" , " sample_bin" )
30
8
def test_catalog_adds_bin (db_session , sample_bin ) -> None :
31
9
catalog = SqlalchemyCatalog (db_session )
32
10
with db_session .begin ():
@@ -44,7 +22,7 @@ def test_catalog_adds_bin(db_session, sample_bin) -> None:
44
22
assert str (rows [0 ].identifier ) == "00000000-0000-0000-0000-000000000001"
45
23
46
24
47
- @pytest .mark .usefixtures ("sample_bin" )
25
+ @pytest .mark .usefixtures ("db_session" , " sample_bin" )
48
26
def test_catalog_gets_bin (db_session , sample_bin ) -> None :
49
27
catalog = SqlalchemyCatalog (db_session )
50
28
with db_session .begin ():
@@ -55,7 +33,7 @@ def test_catalog_gets_bin(db_session, sample_bin) -> None:
55
33
assert bin == sample_bin
56
34
57
35
58
- @pytest .mark .usefixtures ("sample_bin" )
36
+ @pytest .mark .usefixtures ("db_session" , " sample_bin" )
59
37
def test_catalog_gets_by_alternate_identifier (db_session , sample_bin ) -> None :
60
38
catalog = SqlalchemyCatalog (db_session )
61
39
with db_session .begin ():
@@ -66,7 +44,7 @@ def test_catalog_gets_by_alternate_identifier(db_session, sample_bin) -> None:
66
44
assert bin == sample_bin
67
45
68
46
69
- @pytest .mark .usefixtures ("sample_bin" )
47
+ @pytest .mark .usefixtures ("db_session" , " sample_bin" )
70
48
def test_catalog_returns_none_when_no_alternate_identifier_matches (db_session , sample_bin ) -> None :
71
49
catalog = SqlalchemyCatalog (db_session )
72
50
with db_session .begin ():
0 commit comments