-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #192 from dbmi-bgm/kmp_submit_data_sans_upload_sbr2
Support for SubmitCGAP in cgap-portal (C4-302)
- Loading branch information
Showing
42 changed files
with
3,399 additions
and
92 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import io | ||
import json | ||
import os | ||
|
||
from dcicutils.misc_utils import VirtualApp | ||
from pyramid.paster import get_app | ||
from ..submit import digest_xls, xls_to_json, validate_all_items, post_and_patch_all_items | ||
from ..tests.data import DBMI_INSTITUTION, TEST_PROJECT, METADATA_BUNDLE_PATH | ||
|
||
|
||
TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), "submission_test_data") | ||
|
||
TEST_FILE_TO_VALIDATE = os.path.join(TEST_DATA_DIR, "to_validate.json") | ||
TEST_FILE_TO_PATCH = os.path.join(TEST_DATA_DIR, "to_patch.json") | ||
TEST_FILE_TO_POST = os.path.join(TEST_DATA_DIR, "to_post.json") | ||
TEST_FILE_POST_OUTPUT = os.path.join(TEST_DATA_DIR, "post_output.json") | ||
TEST_FILE_PATCH_OUTPUT = os.path.join(TEST_DATA_DIR, "patch_output.json") | ||
TEST_FILE_TO_UPLOAD = os.path.join(TEST_DATA_DIR, "to_upload.json") | ||
|
||
with io.open(TEST_FILE_TO_VALIDATE, 'r') as fp: | ||
TEST_DATA_TO_VALIDATE = json.load(fp) | ||
|
||
with io.open(TEST_FILE_TO_POST, 'r') as fp: | ||
TEST_DATA_TO_POST = json.load(fp) | ||
|
||
with io.open(TEST_FILE_TO_PATCH, 'r') as fp: | ||
TEST_DATA_TO_PATCH = json.load(fp) | ||
|
||
with io.open(TEST_FILE_POST_OUTPUT, 'r') as fp: | ||
TEST_DATA_POST_OUTPUT = json.load(fp) | ||
|
||
with io.open(TEST_FILE_PATCH_OUTPUT, 'r') as fp: | ||
TEST_DATA_PATCH_OUTPUT = json.load(fp) | ||
|
||
with io.open(TEST_FILE_TO_UPLOAD, 'r') as fp: | ||
TEST_DATA_TO_UPLOAD = json.load(fp) | ||
|
||
|
||
def main(): | ||
""" | ||
This does a simple test of the data pipeline used for metadata bundle submission. | ||
This does not test the submission endpoints, but DOES call server endpoints to | ||
inquire about current state and based on that state to decide to post or patch the data. | ||
(As such, the exact action of this script is dependent on the state of the db when it is run.) | ||
The server called will be the one defined by the development environment. | ||
As such, that means we won't be using this test as part of unit tests, | ||
though perhaps variations of this will be adopted for that purpose. | ||
""" | ||
|
||
app = get_app('development.ini', 'app') | ||
environ = {'HTTP_ACCEPT': 'application/json', 'REMOTE_USER': 'TEST'} | ||
virtualapp = VirtualApp(app, environ) | ||
proj = virtualapp.get(TEST_PROJECT).json | ||
inst = virtualapp.get(DBMI_INSTITUTION).json | ||
rows = digest_xls(METADATA_BUNDLE_PATH) | ||
json_data, passing = xls_to_json(rows, proj, inst) | ||
print('JSON data (to validate):', json.dumps(json_data)) | ||
assert json_data == TEST_DATA_TO_VALIDATE | ||
print('JSON data to validate matches contents of %s' % TEST_FILE_TO_VALIDATE) | ||
final_json, validation_log, passing = validate_all_items(virtualapp, json_data) | ||
print('Validation Log:\n'.join(validation_log)) | ||
print("Passing (after validation):", passing) | ||
print("Final JSON (to post, after validation):", json.dumps(final_json, indent=4)) | ||
if final_json == TEST_DATA_TO_PATCH: | ||
# NOTE: There are more possible intermediate states than just "it's all been done" and "none has been done", | ||
# but this simple script does not anticipate those and will just fail if one of those other states is in play. | ||
# -kmp 8-Sep-2020 | ||
posting = False | ||
print("JSON data has already been posted. Light patching is expected.") | ||
print("(To test posting at this point would require wiping the database or adjusting numerous items.)") | ||
print('JSON data to patch matches contents of %s' % TEST_FILE_TO_PATCH) | ||
else: | ||
posting = True | ||
assert final_json == TEST_DATA_TO_POST | ||
print('JSON data to post matches contents of %s' % TEST_FILE_TO_POST) | ||
output, passing, files = post_and_patch_all_items(virtualapp, final_json) | ||
print('Post Output:\n', '\n'.join(output)) | ||
print('Passing (after post and patch):', passing) | ||
if posting: | ||
assert output == TEST_DATA_POST_OUTPUT | ||
print('JSON data to post matches contents of %s' % TEST_FILE_POST_OUTPUT) | ||
else: | ||
assert output == TEST_DATA_PATCH_OUTPUT | ||
print('JSON data to post matches contents of %s' % TEST_FILE_PATCH_OUTPUT) | ||
print('Files:', json.dumps(files, indent=4)) | ||
assert files == TEST_DATA_TO_UPLOAD | ||
print('JSON data to upload matches contents of %s' % TEST_FILE_TO_UPLOAD) | ||
print("SUCCESS! All done.") | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[ | ||
"file_fastq: 4 items patched successfully; 0 items not patched" | ||
] |
23 changes: 23 additions & 0 deletions
23
src/encoded/commands/submission_test_data/post_output.json
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[ | ||
"Success - sample 3464467 posted", | ||
"Success - sample 3464468 posted", | ||
"Success - sample 3464469 posted", | ||
"Success - individual 456 posted", | ||
"Success - individual 789 posted", | ||
"Success - individual 123 posted", | ||
"Success - family 333 posted", | ||
"file_fastq: 4 items posted successfully; 0 items not posted", | ||
"sample: 3 items posted successfully; 0 items not posted", | ||
"individual: 3 items posted successfully; 0 items not posted", | ||
"family: 1 items posted successfully; 0 items not posted", | ||
"sample_processing: 1 items posted successfully; 0 items not posted", | ||
"report: 1 items posted successfully; 0 items not posted", | ||
"case: 3 items posted successfully; 0 items not posted", | ||
"file_fastq: 4 items patched successfully; 0 items not patched", | ||
"sample: 3 items patched successfully; 0 items not patched", | ||
"individual: 3 items patched successfully; 0 items not patched", | ||
"family: 1 items patched successfully; 0 items not patched", | ||
"sample_processing: 1 items patched successfully; 0 items not patched", | ||
"report: 1 items patched successfully; 0 items not patched", | ||
"case: 3 items patched successfully; 0 items not patched" | ||
] |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"post": {}, | ||
"patch": { | ||
"file_fastq": { | ||
"/files-fastq/GAPFINDNNXMD/": { | ||
"filename": "f1.fastq.gz", | ||
"status": "uploading" | ||
}, | ||
"/files-fastq/GAPFI8NPRCLA/": { | ||
"filename": "f2.fastq.gz", | ||
"status": "uploading" | ||
}, | ||
"/files-fastq/GAPFIHLOD3W5/": { | ||
"filename": "f3.fastq.gz", | ||
"status": "uploading" | ||
}, | ||
"/files-fastq/GAPFI558AY9P/": { | ||
"filename": "f4.fastq.gz", | ||
"status": "uploading" | ||
} | ||
}, | ||
"sample": {}, | ||
"individual": {}, | ||
"family": {}, | ||
"sample_processing": {}, | ||
"report": {}, | ||
"case": {} | ||
}, | ||
"aliases": { | ||
"hms-dbmi:f1.fastq.gz": "/files-fastq/GAPFINDNNXMD/", | ||
"hms-dbmi:f2.fastq.gz": "/files-fastq/GAPFI8NPRCLA/", | ||
"hms-dbmi:f3.fastq.gz": "/files-fastq/GAPFIHLOD3W5/", | ||
"hms-dbmi:f4.fastq.gz": "/files-fastq/GAPFI558AY9P/", | ||
"hms-dbmi:sample-3464467": "/samples/GAPSAOZBTKEV/", | ||
"hms-dbmi:sample-3464468": "/samples/GAPSALGBXFHS/", | ||
"hms-dbmi:sample-3464469": "/samples/GAPSA4YIRPGC/", | ||
"hms-dbmi:individual-456": "/individuals/GAPIDXBYJESJ/", | ||
"hms-dbmi:individual-789": "/individuals/GAPID16TYLTK/", | ||
"hms-dbmi:individual-123": "/individuals/GAPIDF5WPST7/", | ||
"hms-dbmi:family-456": "/families/GAPFA5SLA4GB/", | ||
"hms-dbmi:analysis-55432": "/sample-processings/43a03760-4e11-41ae-81d9-a408acd29f16/", | ||
"hms-dbmi:report-55432-3464467": "/reports/ea7490cb-d480-4ecf-b913-467fc24d7294/", | ||
"hms-dbmi:case-55432-3464467": "/cases/GAPCA12VO85Q/", | ||
"hms-dbmi:case-55432-3464468": "/cases/GAPCAWSV5574/", | ||
"hms-dbmi:case-55432-3464469": "/cases/GAPCA2SA3Z84/" | ||
} | ||
} |
Oops, something went wrong.