-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't actually modify the database in tests
- Loading branch information
1 parent
dc147bf
commit ab8b96c
Showing
3 changed files
with
22 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,39 @@ | ||
from unittest.mock import MagicMock | ||
|
||
from cidc_api.models import UploadJobs | ||
|
||
from tests.util import make_pubsub_event, with_app_context | ||
from functions.uploads import ingest_upload | ||
|
||
|
||
@with_app_context | ||
def test_ingest_upload(db_session): | ||
def test_ingest_upload(db_session, monkeypatch): | ||
"""Test upload data transfer functionality""" | ||
|
||
EMAIL = "[email protected]" | ||
JOB_ID = 1 | ||
URI1 = "/path/to/file1" | ||
URI2 = "/path/to/deeper/file2" | ||
TS_AND_PATH = "/1234/local_path1.txt" | ||
FILE_URIS = [URI1 + TS_AND_PATH, URI2 + TS_AND_PATH] | ||
METADATA_PATCH = {"lead_organization_study_id": "CIMAC-12345"} | ||
|
||
# Add a test job to the database | ||
job = UploadJobs.create(EMAIL, FILE_URIS, METADATA_PATCH, session=db_session) | ||
job = UploadJobs( | ||
id=JOB_ID, | ||
uploader_email="[email protected]", | ||
gcs_file_uris=FILE_URIS, | ||
metadata_json_patch={"lead_organization_study_id": "CIMAC-12345"}, | ||
status="completed", | ||
) | ||
|
||
# Since the test database isn't yet set up with migrations, | ||
# it won't have the correct relations in it, so we can't actually | ||
# store or retrieve data from it. | ||
find_by_id = MagicMock() | ||
find_by_id.return_value = job | ||
monkeypatch.setattr(UploadJobs, "find_by_id", find_by_id) | ||
|
||
successful_upload_event = make_pubsub_event(str(job.id)) | ||
response = ingest_upload(successful_upload_event, None) | ||
|
||
assert response.json[URI1 + TS_AND_PATH] == URI1 | ||
assert response.json[URI2 + TS_AND_PATH] == URI2 | ||
find_by_id.assert_called_once_with(JOB_ID, session=db_session) |