Skip to content

Commit 27748f0

Browse files
committed
Use Murfey database fixture and add entries to it
1 parent 3076af2 commit 27748f0

File tree

1 file changed

+66
-9
lines changed

1 file changed

+66
-9
lines changed

tests/server/api/test_movies.py

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@
77
from murfey.server.main import app
88
from murfey.server.murfey_db import murfey_db
99
from murfey.util.api import url_path_for
10-
from murfey.util.db import Movie
10+
from murfey.util.db import (
11+
AutoProcProgram,
12+
DataCollection,
13+
DataCollectionGroup,
14+
Movie,
15+
MurfeyLedger,
16+
ProcessingJob,
17+
)
18+
from murfey.util.db import Session as MurfeySession
19+
from tests.conftest import ExampleVisit, get_or_create_db_entry
1120

1221
# @pytest.fixture(scope="module")
1322
# def test_user():
@@ -42,19 +51,67 @@ def test_movie_count(
4251
murfey_db_session: Session,
4352
):
4453

45-
# Insert test movies into Murfey DB
54+
# Insert table dependencies
55+
session_entry: MurfeySession = get_or_create_db_entry(
56+
murfey_db_session,
57+
MurfeySession,
58+
lookup_kwargs={"id": ExampleVisit.murfey_session_id},
59+
)
60+
dcg_entry: DataCollectionGroup = get_or_create_db_entry(
61+
murfey_db_session,
62+
DataCollectionGroup,
63+
lookup_kwargs={
64+
"id": 0,
65+
"session_id": session_entry.id,
66+
"tag": "test_dcg",
67+
},
68+
)
69+
dc_entry: DataCollection = get_or_create_db_entry(
70+
murfey_db_session,
71+
DataCollection,
72+
lookup_kwargs={"id": 0, "tag": "test_dc", "dcg_id": dcg_entry.id},
73+
)
74+
processing_job_entry: ProcessingJob = get_or_create_db_entry(
75+
murfey_db_session,
76+
ProcessingJob,
77+
lookup_kwargs={
78+
"id": 0,
79+
"recipe": "test_recipe",
80+
"dc_id": dc_entry.id,
81+
},
82+
)
83+
autoproc_entry: AutoProcProgram = get_or_create_db_entry(
84+
murfey_db_session,
85+
AutoProcProgram,
86+
lookup_kwargs={
87+
"id": 0,
88+
"pj_id": processing_job_entry.id,
89+
},
90+
)
91+
92+
# Insert test movies and one-to-one dependencies into Murfey DB
4693
tag = "test_movie"
4794
num_movies = 5
4895
murfey_db_session
4996
for i in range(num_movies):
50-
movie_db_entry = Movie(
51-
murfey_id=i,
52-
path="/some/path",
53-
image_number=i,
54-
tag=tag,
97+
murfey_ledger_entry: MurfeyLedger = get_or_create_db_entry(
98+
murfey_db_session,
99+
MurfeyLedger,
100+
lookup_kwargs={
101+
"id": i,
102+
"app_id": autoproc_entry.id,
103+
},
104+
)
105+
_: Movie = get_or_create_db_entry(
106+
murfey_db_session,
107+
Movie,
108+
lookup_kwargs={
109+
"murfey_id": murfey_ledger_entry.id,
110+
"path": "/some/path",
111+
"image_number": i,
112+
"tag": tag,
113+
},
55114
)
56-
murfey_db_session.add(movie_db_entry)
57-
murfey_db_session.commit()
58115

59116
# Replace the murfey_db instance in endpoint with properly initialised pytest one
60117
app.dependency_overrides[murfey_db] = murfey_db_session

0 commit comments

Comments
 (0)