11# ruff: noqa: E402
22
3+ import json
34import re
45from copy import deepcopy
56import csv
@@ -400,6 +401,98 @@ def test_can_update_score_set_data_before_publication(
400401
401402 assert expected_response_data == response_data [camelize (attribute )]
402403
404+ @pytest .mark .parametrize (
405+ "attribute,updated_data,expected_response_data" ,
406+ [
407+ ("title" , "Updated Title" , "Updated Title" ),
408+ ("method_text" , "Updated Method Text" , "Updated Method Text" ),
409+ ("abstract_text" , "Updated Abstract Text" , "Updated Abstract Text" ),
410+ ("short_description" , "Updated Abstract Text" , "Updated Abstract Text" ),
411+ ("extra_metadata" , {"updated" : "metadata" }, {"updated" : "metadata" }),
412+ ("data_usage_policy" , "data_usage_policy" , "data_usage_policy" ),
413+ ("contributors" , [{"orcid_id" : EXTRA_USER ["username" ]}], [SAVED_EXTRA_CONTRIBUTOR ]),
414+ ("primary_publication_identifiers" , [{"identifier" : TEST_PUBMED_IDENTIFIER }], [SAVED_PUBMED_PUBLICATION ]),
415+ ("secondary_publication_identifiers" , [{"identifier" : TEST_PUBMED_IDENTIFIER }], [SAVED_PUBMED_PUBLICATION ]),
416+ ("doi_identifiers" , [{"identifier" : TEST_CROSSREF_IDENTIFIER }], [SAVED_DOI_IDENTIFIER ]),
417+ ("license_id" , EXTRA_LICENSE ["id" ], SAVED_SHORT_EXTRA_LICENSE ),
418+ ("target_genes" , TEST_MINIMAL_ACC_SCORESET ["targetGenes" ], TEST_MINIMAL_ACC_SCORESET_RESPONSE ["targetGenes" ]),
419+ ("score_ranges" , TEST_SCORE_SET_RANGES_ALL_SCHEMAS_PRESENT , TEST_SAVED_SCORE_SET_RANGES_ALL_SCHEMAS_PRESENT ),
420+ ],
421+ )
422+ @pytest .mark .parametrize (
423+ "mock_publication_fetch" ,
424+ [({"dbName" : "PubMed" , "identifier" : f"{ TEST_PUBMED_IDENTIFIER } " })],
425+ indirect = ["mock_publication_fetch" ],
426+ )
427+ def test_can_patch_score_set_data_before_publication (
428+ client , setup_router_db , attribute , updated_data , expected_response_data , mock_publication_fetch
429+ ):
430+ experiment = create_experiment (client )
431+ score_set = create_seq_score_set (client , experiment ["urn" ])
432+ expected_response = update_expected_response_for_created_resources (
433+ deepcopy (TEST_MINIMAL_SEQ_SCORESET_RESPONSE ), experiment , score_set
434+ )
435+ expected_response ["experiment" ].update ({"numScoreSets" : 1 })
436+
437+ response = client .get (f"/api/v1/score-sets/{ score_set ['urn' ]} " )
438+ assert response .status_code == 200
439+ response_data = response .json ()
440+
441+ assert sorted (expected_response .keys ()) == sorted (response_data .keys ())
442+ for key in expected_response :
443+ assert (key , expected_response [key ]) == (key , response_data [key ])
444+
445+ data = {}
446+ if isinstance (updated_data , (dict , list )):
447+ form_value = json .dumps (updated_data )
448+ else :
449+ form_value = str (updated_data )
450+ data [attribute ] = form_value
451+
452+ response = client .patch (f"/api/v1/score-sets-with-variants/{ score_set ['urn' ]} " , data = data )
453+ assert response .status_code == 200
454+
455+ response = client .get (f"/api/v1/score-sets/{ score_set ['urn' ]} " )
456+ assert response .status_code == 200
457+ response_data = response .json ()
458+
459+ # Although the client provides the license id, the response includes the full license.
460+ if attribute == "license_id" :
461+ attribute = "license"
462+
463+ assert expected_response_data == response_data [camelize (attribute )]
464+
465+ @pytest .mark .parametrize (
466+ "form_field,filename,mime_type" ,
467+ [
468+ ("scores_file" , "scores.csv" , "text/csv" ),
469+ ("counts_file" , "counts.csv" , "text/csv" ),
470+ ("score_columns_metadata_file" , "score_columns_metadata.json" , "application/json" ),
471+ ("count_columns_metadata_file" , "count_columns_metadata.json" , "application/json" ),
472+ ]
473+ )
474+ @pytest .mark .parametrize (
475+ "mock_publication_fetch" ,
476+ [({"dbName" : "PubMed" , "identifier" : f"{ TEST_PUBMED_IDENTIFIER } " })],
477+ indirect = ["mock_publication_fetch" ],
478+ )
479+ def test_can_patch_score_set_data_with_files_before_publication (
480+ client , setup_router_db , form_field , filename , mime_type ,data_files , mock_publication_fetch
481+ ):
482+ experiment = create_experiment (client )
483+ score_set = create_seq_score_set (client , experiment ["urn" ])
484+ expected_response = update_expected_response_for_created_resources (
485+ deepcopy (TEST_MINIMAL_SEQ_SCORESET_RESPONSE ), experiment , score_set
486+ )
487+ expected_response ["experiment" ].update ({"numScoreSets" : 1 })
488+
489+ data_file_path = data_files / filename
490+ files = {form_field : (filename , open (data_file_path , "rb" ), mime_type )}
491+ with patch .object (arq .ArqRedis , "enqueue_job" , return_value = None ) as worker_queue :
492+ response = client .patch (f"/api/v1/score-sets-with-variants/{ score_set ['urn' ]} " , files = files )
493+ worker_queue .assert_called_once ()
494+ assert response .status_code == 200
495+
403496
404497@pytest .mark .parametrize (
405498 "attribute,updated_data,expected_response_data" ,
@@ -415,7 +508,7 @@ def test_can_update_score_set_data_before_publication(
415508 ("secondary_publication_identifiers" , [{"identifier" : TEST_PUBMED_IDENTIFIER }], [SAVED_PUBMED_PUBLICATION ]),
416509 ("doi_identifiers" , [{"identifier" : TEST_CROSSREF_IDENTIFIER }], [SAVED_DOI_IDENTIFIER ]),
417510 ("license_id" , EXTRA_LICENSE ["id" ], SAVED_SHORT_EXTRA_LICENSE ),
418- ("dataset_columns" , { "countColumns" : [], "scoreColumns" : [ "score" ]} , SAVED_MINIMAL_DATASET_COLUMNS )
511+ ("dataset_columns" , None , SAVED_MINIMAL_DATASET_COLUMNS )
419512 ],
420513)
421514@pytest .mark .parametrize (
0 commit comments