|
7 | 7 | from murfey.server.main import app |
8 | 8 | from murfey.server.murfey_db import murfey_db |
9 | 9 | 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 |
11 | 20 |
|
12 | 21 | # @pytest.fixture(scope="module") |
13 | 22 | # def test_user(): |
@@ -42,19 +51,67 @@ def test_movie_count( |
42 | 51 | murfey_db_session: Session, |
43 | 52 | ): |
44 | 53 |
|
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 |
46 | 93 | tag = "test_movie" |
47 | 94 | num_movies = 5 |
48 | 95 | murfey_db_session |
49 | 96 | 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 | + }, |
55 | 114 | ) |
56 | | - murfey_db_session.add(movie_db_entry) |
57 | | - murfey_db_session.commit() |
58 | 115 |
|
59 | 116 | # Replace the murfey_db instance in endpoint with properly initialised pytest one |
60 | 117 | app.dependency_overrides[murfey_db] = murfey_db_session |
|
0 commit comments