-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_import_data.py
1591 lines (1331 loc) · 71.1 KB
/
test_import_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import wranglertools.import_data as imp
import pytest
import pathlib as pp
# test data is in conftest.py
# @pytest.mark.file_operation
@pytest.mark.ftp
def test_attachment_from_ftp():
attach = imp.attachment("ftp://speedtest.tele2.net/1KB.zip")
assert attach
@pytest.mark.ftp
def test_attachment_ftp_to_nowhere():
with pytest.raises(Exception) as e:
imp.attachment("ftp://on/a/road/to/nowhere/blah.txt")
assert "urlopen error" in str(e.value)
def convert_to_path_with_tilde(string_path):
"""Somehow the inverse of pathlib.Path.expanduser(). Helper function used
to generate valid paths containing ~ """
path = pp.Path(string_path)
absolute_path = path.resolve()
home = absolute_path.home()
string_path_with_tilde = str(absolute_path).replace(str(home), '~')
return string_path_with_tilde
@pytest.mark.file_operation
def test_md5():
path = convert_to_path_with_tilde('./tests/data_files/keypairs.json')
md5_keypairs = imp.md5(path)
assert md5_keypairs == "19d43267b642fe1868e3c136a2ee06f2"
@pytest.mark.file_operation
def test_attachment_image():
attach = imp.attachment("./tests/data_files/test.jpg")
assert attach['download'] == 'test.jpg'
assert attach['type'] == 'image/jpeg'
assert attach['href'].startswith('data:image/jpeg;base64')
@pytest.mark.file_operation
def test_attachment_pdf():
attach = imp.attachment("./tests/data_files/test.pdf")
assert attach['download'] == 'test.pdf'
assert attach['type'] == 'application/pdf'
assert attach['href'].startswith('data:application/pdf;base64')
@pytest.mark.file_operation
def test_attachment_expanduser_path():
path = convert_to_path_with_tilde("./tests/data_files/test.pdf")
attach = imp.attachment(path)
assert attach['download'] == 'test.pdf'
assert attach['type'] == 'application/pdf'
assert attach['href'].startswith('data:application/pdf;base64')
@pytest.mark.file_operation
def test_attachment_image_wrong_extension():
with pytest.raises(ValueError) as excinfo:
imp.attachment("./tests/data_files/test_jpeg.tiff")
assert str(excinfo.value) == 'Wrong extension for image/jpeg: test_jpeg.tiff'
@pytest.mark.file_operation
def test_attachment_wrong_path():
with pytest.raises(Exception) as e:
imp.attachment("./tests/data_files/dontexisit.txt")
assert "ERROR : The 'attachment' field has INVALID FILE PATH or URL" in str(e.value)
@pytest.mark.webtest
def test_attachment_url():
attach = imp.attachment("http://example.com/index.html")
assert attach['download'] == 'index.html'
assert attach['type'] == 'text/html'
assert attach['href'].startswith('data:text/html;base64')
@pytest.mark.webtest
def test_attachment_bad_url():
with pytest.raises(Exception) as e:
imp.attachment("https://some/unknown/url.html")
assert "ERROR : The 'attachment' field has INVALID FILE PATH or URL" in str(e.value)
@pytest.mark.file_operation
def test_attachment_not_accepted():
with pytest.raises(ValueError) as excinfo:
imp.attachment("./tests/data_files/test.mp3")
assert str(excinfo.value) == 'Unallowed file type for test.mp3'
@pytest.mark.file_operation
def test_reader_no_sheet_name(vendor_raw_xls_fields, workbooks):
sheet = 'Vendor'
sheetkey = "{}.xlsx".format(sheet)
readxls = imp.reader(workbooks.get(sheetkey))
for n, row in enumerate(readxls):
# reader deletes the trailing space in description (at index 3.8)
if n == 2:
assert row[8] + " " == vendor_raw_xls_fields[n][8]
else:
assert row == vendor_raw_xls_fields[n]
@pytest.mark.file_operation
def test_reader_with_sheetname(vendor_raw_xls_fields, workbooks):
sheet = 'Vendor'
sheetkey = "{}.xlsx".format(sheet)
readxls = imp.reader(workbooks.get(sheetkey), sheet)
for n, row in enumerate(readxls):
# reader deletes the trailing space in description (at index 3.8)
if n == 2:
assert row[8] + " " == vendor_raw_xls_fields[n][8]
else:
assert row == vendor_raw_xls_fields[n]
@pytest.mark.file_operation
def test_reader_wrong_sheetname(capsys):
msg = "string indices must be integers\nEnzyme\nERROR: Can not find the collection sheet in excel file (openpyxl error)\n"
sheet = 'Vendor'
sheetkey = "{}.xlsx".format(sheet)
readxls = imp.reader(sheetkey, 'Enzyme')
assert readxls is None
out = capsys.readouterr()[0]
assert out == msg
def test_cell_value(workbooks):
readxls = imp.reader(workbooks.get('test_cell_values.xlsx'))
list_readxls = list(readxls)
assert list_readxls == [
['BOOLEAN', True], ['INT', 10100], ['FLOAT', 5.5], ['DATE', '2016-09-02'],
['STRDATE', '2022-01-01'], ['STRING', 'testing']
]
def test_formatter_gets_ints_correctly():
assert 6 == imp.data_formatter('6', 'int')
assert 6 == imp.data_formatter(6, 'integer')
def test_formatter_gets_ints_correctly_with_gap():
assert 6 == imp.data_formatter('6 ', 'int')
assert 6 == imp.data_formatter(6, 'integer')
def test_formatter_gets_floats_correctly():
assert 6.0 == imp.data_formatter('6', 'num')
assert 7.2456 == imp.data_formatter(7.2456, 'number')
def test_formatter_gets_lists_correctly():
assert ['1', '2', '3'] == imp.data_formatter('[1, 2 ,3]', 'list')
assert ['1', '2', '3'] == imp.data_formatter("'[1,2,3]'", 'array')
def test_formatter_gets_strings_correctly():
assert "test \t string" == imp.data_formatter("\n\t test \t string\t", 'string')
def test_build_field_empty_is_skipped():
assert imp.build_field('some_field', '', 'string') is None
assert imp.build_field('', 'some_data', 'string') is None
def test_build_field_old_stype_field():
old_style = imp.build_field('some_field:int', "5", None)
assert old_style == {'some_field': 5}
def test_build_patch_json_removes_empty_fields(file_metadata, file_metadata_type):
post_json = imp.build_patch_json(file_metadata, file_metadata_type)
# All the below values exist in file_metadatadd
assert post_json.get('filesets', None) is None
assert post_json.get('paired_end', None) is None
def test_build_patch_json_keeps_valid_fields(file_metadata, file_metadata_type):
post_json = imp.build_patch_json(file_metadata, file_metadata_type)
assert '/awards/OD008540-01/' == post_json.get('award', None)
assert 'fastq' == post_json.get('file_format', None)
def test_build_patch_json_embeds_fields(file_metadata, file_metadata_type):
post_json = imp.build_patch_json(file_metadata, file_metadata_type)
expected = [{'file': 'testfile.fastq', 'relationship_type': 'related_to'}]
assert expected == post_json.get('related_files', None)
def test_build_patch_json_join_multiple_embeds_fields(file_metadata, file_metadata_type):
post_json = imp.build_patch_json(file_metadata, file_metadata_type)
expected1 = {'experiment': 'test:exp002', 'relationship_type': 'controlled by'}
expected2 = {'experiment': 'test:exp003', 'relationship_type': 'source for'}
expected3 = {'experiment': 'test:exp004', 'relationship_type': 'source for'}
exp_rel = post_json.get('experiment_relation', None)
assert expected1 in exp_rel
assert expected2 in exp_rel
assert expected3 in exp_rel
def test_get_fields_type():
test_case = ["name", "number:num", "integer:int", "list:array"]
expected_result = ["string", "num", "int", "array"]
for i, ix in enumerate(test_case):
assert imp.get_field_type(ix) == expected_result[i]
def test_get_existing_uuid(connection_mock, mocker, returned_vendor_existing_item):
post_jsons = [{'uuid': 'some_uuid'},
{'accession': 'some_accession'},
{'aliases': ['some_acc']},
{'@id': 'some_@id'}]
for post_json in post_jsons:
mocker.patch('dcicutils.ff_utils.get_metadata', return_value=returned_vendor_existing_item.json())
response = imp.get_existing(post_json, connection_mock)
assert response == returned_vendor_existing_item.json()
def test_combine_set_expsets():
post_json = {"aliases": "sample_expset", "description": "sample description"}
existing_data = {}
dict_expsets = {'sample_expset': ['awesome_uuid1', 'awesome_uuid4', 'awesome_uuid5']}
post_json2, dict_expsets2 = imp.combine_set(post_json, existing_data, "ExperimentSet", dict_expsets)
response = {'experiments_in_set': ['awesome_uuid4', 'awesome_uuid5', 'awesome_uuid1'],
'description': 'sample description',
'aliases': 'sample_expset'}
assert sorted(post_json2) == sorted(response)
assert dict_expsets2 == {}
def test_combine_set_replicates_with_existing():
post_json = {"aliases": "sample_repset", "description": "sample description"}
existing_data = {"uuid": "sampleuuid", "accession": "sample_accession",
'replicate_exps': [{'replicate_exp': 'awesome_uuid', 'bio_rep_no': 1.0, 'tec_rep_no': 6.0},
{'replicate_exp': 'awesome_uuid2', 'bio_rep_no': 2.0, 'tec_rep_no': 1.0}]}
dict_replicates = {'sample_repset': [{'replicate_exp': 'awesome_uuid1', 'bio_rep_no': 1.0, 'tec_rep_no': 1.0},
{'replicate_exp': 'awesome_uuid3', 'bio_rep_no': 1.0, 'tec_rep_no': 2.0}]}
post_json2, dict_replicates2 = imp.combine_set(post_json, existing_data, "ExperimentSetReplicate", dict_replicates)
response = {'replicate_exps': [{'replicate_exp': 'awesome_uuid1', 'bio_rep_no': 1.0, 'tec_rep_no': 1.0},
{'replicate_exp': 'awesome_uuid3', 'bio_rep_no': 1.0, 'tec_rep_no': 2.0},
{'replicate_exp': 'awesome_uuid', 'bio_rep_no': 1.0, 'tec_rep_no': 6.0},
{'replicate_exp': 'awesome_uuid2', 'bio_rep_no': 2.0, 'tec_rep_no': 1.0}],
'description': 'sample description',
'aliases': 'sample_repset'}
assert post_json2 == response
assert dict_replicates2 == {}
def test_combine_set_expsets_with_existing():
post_json = {"aliases": "sample_expset", "description": "sample description"}
existing_data = {"uuid": "sampleuuid", "accession": "sample_accession",
"experiments_in_set": ['awesome_uuid1', 'awesome_uuid2']}
dict_expsets = {'sample_expset': ['awesome_uuid1', 'awesome_uuid4', 'awesome_uuid5']}
post_json2, dict_expsets2 = imp.combine_set(post_json, existing_data, "ExperimentSet", dict_expsets)
response = {'experiments_in_set': ['awesome_uuid4', 'awesome_uuid5', 'awesome_uuid2', 'awesome_uuid1'],
'description': 'sample description',
'aliases': 'sample_expset'}
assert sorted(post_json2) == sorted(response)
assert dict_expsets2 == {}
def test_error_report(connection_mock):
# There are 3 errors, 2 of them are legit, one needs to be checked afains the all aliases list, and excluded
err_dict = {"title": "Unprocessable Entity",
"status": "error",
"errors": [
{"name": "protocol_documents",
"description": "'dcic:insituhicagar' not found", "location": "body"},
{"name": "age",
"description": "'at' is not of type 'number'", "location": "body"},
{"name": "sex",
"description": "'green' is not one of ['male', 'female', 'unknown', 'mixed']", "location": "body"}],
"code": 422,
"@type": ["ValidationFailure", "Error"],
"description": "Failed validation"}
rep = imp.error_report(err_dict, "Vendor", ['dcic:insituhicagar'], connection_mock)
message = '''
ERROR vendor Field 'age': 'at' is not of type 'number'
ERROR vendor Field 'sex': 'green' is not one of ['male', 'female', 'unknown', 'mixed']
'''
assert rep.strip() == message.strip()
def test_error_conflict_report(connection_mock):
# There is one conflict error
err_dict = {"title": "Conflict",
"status": "error",
"description": "There was a conflict when trying to complete your request.",
"code": 409,
"detail": "Keys conflict: [('award:name', '1U54DK107981-01')]",
"@type": ["HTTPConflict", "Error"]}
rep = imp.error_report(err_dict, "Vendor", ['dcic:insituhicagar'], connection_mock)
message = "ERROR vendor Field 'name': '1U54DK107981-01' already exists, please contact DCIC"
assert rep.strip() == message.strip()
def test_error_access_denied_report(connection_mock):
# There are 3 errors, 2 of them are legit, one needs to be checked afains the all aliases list, and excluded
err_dict = {'code': 403,
'status': 'error',
'description': 'Access was denied to this resource.',
'title': 'Forbidden',
'@type': ['HTTPForbidden', 'Error'],
'detail': 'Unauthorized: item_edit failed permission check'}
rep = imp.error_report(err_dict, "Vendor", [], connection_mock, 'dcic:released vendor')
message = '''
ERROR vendor dcic:released vendor: Access was denied to this resource.
'''
assert rep.strip() == message.strip()
def test_fix_attribution(connection_mock):
post_json = {'field': 'value', 'field2': 'value2'}
result_json = imp.fix_attribution('some_sheet', post_json, connection_mock)
assert result_json['lab'] == 'test_lab'
assert result_json['award'] == 'test_award'
@pytest.mark.file_operation
def test_digest_xlsx(workbooks):
WORKBOOK_DIR = './tests/data_files/workbooks/'
for fn, workbook in workbooks.items():
book, sheets = imp.digest_xlsx(WORKBOOK_DIR + fn)
assert sheets == workbook.sheetnames
for sheet in sheets:
assert book[sheet].max_row == workbook[sheet].max_row
assert book[sheet].max_column == workbook[sheet].max_column
def test_workbooks_reader_no_update_no_patchall_new_doc_with_attachment(capsys, mocker, connection_mock, workbooks):
# test new item submission without patchall update tags and check the return message
test_insert = 'Document_insert.xlsx'
dict_load = {}
dict_rep = {}
dict_set = {}
all_aliases = {}
# mock fetching existing info, return None
mocker.patch('wranglertools.import_data.get_existing', return_value={})
mocker.patch('wranglertools.import_data.remove_deleted', return_value={})
# mocking the test post line
mocker.patch('dcicutils.ff_utils.post_metadata', return_value={'status': 'success'})
imp.workbook_reader(workbooks.get(test_insert), 'Document', False, connection_mock, False,
all_aliases, dict_load, dict_rep, dict_set, True, ['attachment'])
args = imp.remove_deleted.call_args
attach = args[0][0]['attachment']
assert attach['href'].startswith('data:image/jpeg;base64')
def test_workbook_reader_no_update_no_patchall_existing_item(capsys, mocker, connection_mock, workbooks):
# test exisiting item submission without patchall update tags and check the return message
test_insert = "Vendor_insert.xlsx"
dict_load = {}
dict_rep = {}
dict_set = {}
message = "VENDOR(1) : 0 posted / 0 not posted 0 patched / 1 not patched, 0 errors\n"
post_json = {'lab': 'sample-lab',
'description': 'Sample description',
'award': 'SampleAward',
'title': 'Sample Vendor',
'url': 'https://www.sample_vendor.com/',
'aliases': ['dcic:sample_vendor']}
existing_vendor = {'uuid': 'sample_uuid'}
mocker.patch('wranglertools.import_data.get_existing', return_value=existing_vendor)
mocker.patch('wranglertools.import_data.ff_utils.patch_metadata',
return_value={'status': 'success', '@graph': [{'uuid': 'uid1', '@id': '/vendor/test'}]})
imp.workbook_reader(workbooks.get(test_insert), 'Vendor', False, connection_mock, False, {}, dict_load, dict_rep, dict_set, True, [])
out = capsys.readouterr()
args = imp.get_existing.call_args
assert args[0][0] == post_json
assert out[0] == message
def test_workbook_reader_post_ftp_file_upload(capsys, mocker, connection_mock, workbooks):
test_insert = 'Ftp_file_test_md5.xlsx'
dict_load = {}
dict_rep = {}
dict_set = {}
all_aliases = {}
message1 = "FILECALIBRATION(1) : 1 posted / 0 not posted 0 patched / 0 not patched, 0 errors\n"
e = {'status': 'success', '@graph': [{'uuid': 'some_uuid', '@id': 'some_uuid'}]}
# mock fetching existing info, return None
mocker.patch('wranglertools.import_data.get_existing', return_value={})
# mock upload file and skip
mocker.patch('wranglertools.import_data.upload_file_item', return_value={})
# mock the ftp copy - this should get it's own tests
mocker.patch('wranglertools.import_data.ftp_copy', return_value=(True, {'md5sum': '0f343b0931126a20f133d67c2b018a3b'}, '1KB.zip'))
# mock file deletion
mocker.patch('wranglertools.import_data.pp.Path.unlink')
# mock posting new items
mocker.patch('dcicutils.ff_utils.post_metadata', return_value=e)
imp.workbook_reader(workbooks.get(test_insert), 'FileCalibration', True, connection_mock, False,
all_aliases, dict_load, dict_rep, dict_set, True, [])
args = imp.ff_utils.post_metadata.call_args
out = capsys.readouterr()[0]
post_json_arg = args[0][0]
assert post_json_arg['md5sum'] == '0f343b0931126a20f133d67c2b018a3b'
assert message1 == out
def test_workbook_reader_post_ftp_file_upload_no_md5(capsys, mocker, connection_mock, workbooks):
""" This appears to actually mainly be testing the ftp_copy function - confirming that
the correct error messages are generated when you try to copy an ftp file without
including an md5sum in the post and subsequently that the workbook_reader function
will still post the metadata without uploading a file
"""
test_insert = 'Ftp_file_test.xlsx'
dict_load = {}
dict_rep = {}
dict_set = {}
all_aliases = {}
message0 = "WARNING: File not uploaded"
message1 = "Please add original md5 values of the files"
message2 = "FILECALIBRATION(1) : 1 posted / 0 not posted 0 patched / 0 not patched, 0 errors"
e = {'status': 'success', '@graph': [{'uuid': 'some_uuid', '@id': 'some_uuid'}]}
# mock fetching existing info, return None
mocker.patch('wranglertools.import_data.get_existing', return_value={})
# mock upload file and skip
mocker.patch('wranglertools.import_data.upload_file_item', return_value={})
# mock posting new items
mocker.patch('dcicutils.ff_utils.post_metadata', return_value=e)
imp.workbook_reader(workbooks.get(test_insert), 'FileCalibration', True, connection_mock, False,
all_aliases, dict_load, dict_rep, dict_set, True, [])
out = capsys.readouterr()[0]
outlist = [i.strip() for i in out.split('\n') if i.strip()]
assert message0 == outlist[0]
assert message1 == outlist[1]
assert message2 == outlist[2]
@pytest.mark.file_operation
def test_workbook_reader_update_new_file_fastq_post_and_file_upload(capsys, mocker, connection_mock, workbooks):
""" This appears to actually mainly be testing the md5 function - confirming that
the correct output is generated when and that the md5sum is as expected
and that the workbook_reader function posts the metadata with expected output
"""
test_insert = 'File_fastq_upload.xlsx'
dict_load = {}
dict_rep = {}
dict_set = {}
all_aliases = {}
message0 = "calculating md5 sum for file ./tests/data_files/example.fastq.gz"
message1 = "FILEFASTQ(1) : 1 posted / 0 not posted 0 patched / 0 not patched, 0 errors"
e = {'status': 'success', '@graph': [{'uuid': 'some_uuid', '@id': 'some_uuid'}]}
# mock fetching existing info, return None
mocker.patch('wranglertools.import_data.get_existing', return_value={})
# mock upload file and skip
mocker.patch('wranglertools.import_data.upload_file_item', return_value={})
# mock posting new items
mocker.patch('dcicutils.ff_utils.post_metadata', return_value=e)
imp.workbook_reader(workbooks.get(test_insert), 'FileFastq', True, connection_mock, False,
all_aliases, dict_load, dict_rep, dict_set, True, [])
args = imp.ff_utils.post_metadata.call_args
out = capsys.readouterr()[0]
outlist = [i.strip() for i in out.split('\n') if i is not ""]
post_json_arg = args[0][0]
assert post_json_arg['md5sum'] == '8f8cc612e5b2d25c52b1d29017e38f2b'
assert message0 == outlist[0]
assert message1 == outlist[1]
# a weird test that has filename in an experiment
# needs to change
@pytest.mark.file_operation
def test_workbook_reader_patch_file_meta_and_file_upload(capsys, mocker, connection_mock, workbooks):
""" This appears to actually mainly be testing the md5 function - confirming that
the correct output is generated when and that the md5sum is as expected
and that the workbook_reader function patches the metadata with expected output
"""
test_insert = 'File_fastq_upload.xlsx'
dict_load = {}
dict_rep = {}
dict_set = {}
all_aliases = {}
message0 = "calculating md5 sum for file ./tests/data_files/example.fastq.gz"
message1 = "FILEFASTQ(1) : 0 posted / 0 not posted 1 patched / 0 not patched, 0 errors"
existing_exp = {'uuid': 'sample_uuid', 'status': "uploading"}
e = {'status': 'success',
'@graph': [{'uuid': 'some_uuid',
'@id': 'some_uuid',
'upload_credentials': 'old_creds',
'accession': 'some_accession'}]}
# mock fetching existing info, return None
mocker.patch('wranglertools.import_data.get_existing', return_value=existing_exp)
# mock upload file and skip
mocker.patch('wranglertools.import_data.upload_file_item', return_value={})
# mock posting new items
mocker.patch('dcicutils.ff_utils.patch_metadata', return_value=e)
# mock get upload creds
mocker.patch('wranglertools.import_data.get_upload_creds', return_value="new_creds")
imp.workbook_reader(workbooks.get(test_insert), 'FileFastq', False, connection_mock, True,
all_aliases, dict_load, dict_rep, dict_set, True, [])
# check for md5sum
args = imp.ff_utils.patch_metadata.call_args
post_json_arg = args[0][0]
assert post_json_arg['md5sum'] == '8f8cc612e5b2d25c52b1d29017e38f2b'
# check for cred getting updated (from old_creds to new_creds)
args_upload = imp.upload_file_item.call_args
updated_post = args_upload[0][0]
assert updated_post['@graph'][0]['upload_credentials'] == 'new_creds'
# check for output message
out = capsys.readouterr()[0]
outlist = [i.strip() for i in out.split('\n') if i is not ""]
assert message0 == outlist[0]
assert message1 == outlist[1]
def test_workbook_reader_update_new_filefastq_meta_post(capsys, mocker, connection_mock, workbooks):
test_insert = 'File_fastq_insert.xlsx'
dict_load = {}
dict_rep = {}
dict_set = {}
all_aliases = {}
message = "FILEFASTQ(1) : 1 posted / 0 not posted 0 patched / 0 not patched, 0 errors"
e = {'status': 'success', '@graph': [{'uuid': 'some_uuid', '@id': 'some_uuid'}]}
final_post = {'aliases': ['dcic:test_alias'],
'lab': 'test-lab',
'award': 'test-award',
'file_format': 'fastq'}
# mock fetching existing info, return None
mocker.patch('wranglertools.import_data.get_existing', return_value={})
# mock posting new items
mocker.patch('dcicutils.ff_utils.post_metadata', return_value=e)
imp.workbook_reader(workbooks.get(test_insert), 'FileFastq', True, connection_mock, False,
all_aliases, dict_load, dict_rep, dict_set, True, [])
args = imp.ff_utils.post_metadata.call_args
out = capsys.readouterr()[0]
print([i for i in args])
assert message == out.strip()
assert args[0][0] == final_post
def test_workbook_reader_update_new_replicate_set_post(capsys, mocker, connection_mock, workbooks):
test_insert = 'Exp_Set_Replicate_insert.xlsx'
dict_load = {}
dict_rep = {'sample_repset': [{'replicate_exp': 'awesome_uuid', 'bio_rep_no': 1.0, 'tec_rep_no': 1.0}]}
dict_set = {}
all_aliases = {}
message = "EXPERIMENTSETREPLICATE(1) : 1 posted / 0 not posted 0 patched / 0 not patched, 0 errors"
e = {'status': 'success', '@graph': [{'uuid': 'sample_repset', '@id': 'sample_repset'}]}
final_post = {'aliases': ['sample_repset'],
'replicate_exps': [{'bio_rep_no': 1.0, 'tec_rep_no': 1.0, 'replicate_exp': 'awesome_uuid'}],
'award': 'test_award', 'lab': 'test_lab'}
# mock fetching existing info, return None
mocker.patch('wranglertools.import_data.get_existing', return_value={})
# mock upload file and skip
mocker.patch('dcicutils.ff_utils.post_metadata', return_value=e)
imp.workbook_reader(workbooks.get(test_insert), 'ExperimentSetReplicate', True, connection_mock,
False, all_aliases, dict_load, dict_rep, dict_set, True, [])
args = imp.ff_utils.post_metadata.call_args
out = capsys.readouterr()[0]
assert message == out.strip()
assert args[0][0] == final_post
def test_workbook_reader_update_new_experiment_set_post(capsys, mocker, connection_mock, workbooks):
test_insert = 'Exp_Set_insert.xlsx'
dict_load = {}
dict_rep = {}
dict_set = {'sample_expset': ['awesome_uuid']}
all_aliases = {}
message = "EXPERIMENTSET(1) : 1 posted / 0 not posted 0 patched / 0 not patched, 0 errors"
e = {'status': 'success', '@graph': [{'uuid': 'sample_expset', '@id': 'sample_expset'}]}
final_post = {'aliases': ['sample_expset'], 'experiments_in_set': ['awesome_uuid'],
'award': 'test_award', 'lab': 'test_lab'}
# mock fetching existing info, return None
mocker.patch('wranglertools.import_data.get_existing', return_value={})
# mock upload file and skip
mocker.patch('dcicutils.ff_utils.post_metadata', return_value=e)
imp.workbook_reader(workbooks.get(test_insert), 'ExperimentSet', True, connection_mock, False,
all_aliases, dict_load, dict_rep, dict_set, True, [])
args = imp.ff_utils.post_metadata.call_args
out = capsys.readouterr()[0]
assert message == out.strip()
assert args[0][0] == final_post
def test_user_workflow_reader_wfr_post(capsys, mocker, connection_mock, workbooks):
test_insert = 'Pseudo_wfr_insert.xlsx'
sheet_name = 'user_workflow_1'
message = "USER_WORKFLOW_1(1) : 1 posted / 0 not posted - patched / - not patched, 0 errors"
e = {'status': 'SUCCEEDED'}
final_post = {'wfr_meta':
{'lab': 'test_lab',
'submitted_by': 'test_user',
'description': 'testing testing',
'award': 'test_award',
'aliases': [u'dcic:test_wfrs0004']},
'parameters': {},
'args': {},
'app_name': None,
'metadata_only': True,
'output_files': [
{'uuid': 'b0aaf32c-58de-475a-a222-3f16d3cb68f4',
'bucket_name': 'elasticbeanstalk-fourfront-webdev-wfoutput',
'workflow_argument_name': 'annotated_bam',
'object_key': '4DNFIVQPE4WT.bam'},
{'uuid': '0292e08e-facf-4a16-a94e-59606f2bfc71',
'bucket_name': 'elasticbeanstalk-fourfront-webdev-wfoutput',
'workflow_argument_name':
'filtered_pairs',
'object_key': '4DNFIGOJW3XZ.pairs.gz'}],
'config': {},
'workflow_uuid': '023bfb3e-9a8b-42b9-a9d4-216079526f68',
'input_files': [{'uuid': '4a6d10ee-2edb-4402-a98f-0edb1d58f5e9',
'bucket_name': 'elasticbeanstalk-fourfront-webdev-files',
'workflow_argument_name': 'chromsize',
'object_key': '4DNFI823LSII.chrom.sizes'},
{'uuid': ['11c12207-6684-4346-9038-e7819dfde4e5',
'4d55623a-1698-44c2-b111-1aa1379edc57'],
'bucket_name': 'elasticbeanstalk-fourfront-webdev-wfoutput',
'workflow_argument_name': 'input_bams',
'object_key': ['4DNFIYI7YMVU.bam', '4DNFIPMZQNF5.bam']}]}
# mock fetching existing info, return None
mocker.patch('wranglertools.import_data.get_existing', return_value={})
# mock getting workflow information
mocker.patch('dcicutils.ff_utils.get_metadata', return_value={})
# mock formating files
mocker.patch('wranglertools.import_data.format_file', side_effect=[
{'bucket_name': 'elasticbeanstalk-fourfront-webdev-files', 'workflow_argument_name': 'chromsize',
'object_key': '4DNFI823LSII.chrom.sizes','uuid': '4a6d10ee-2edb-4402-a98f-0edb1d58f5e9'},
{'bucket_name': 'elasticbeanstalk-fourfront-webdev-wfoutput', 'workflow_argument_name': 'input_bams',
'object_key': ['4DNFIYI7YMVU.bam', '4DNFIPMZQNF5.bam'], 'uuid': [
'11c12207-6684-4346-9038-e7819dfde4e5', '4d55623a-1698-44c2-b111-1aa1379edc57'
]},
{'bucket_name': 'elasticbeanstalk-fourfront-webdev-wfoutput', 'workflow_argument_name': 'annotated_bam',
'object_key': '4DNFIVQPE4WT.bam', 'uuid': 'b0aaf32c-58de-475a-a222-3f16d3cb68f4'},
{'bucket_name': 'elasticbeanstalk-fourfront-webdev-wfoutput', 'workflow_argument_name': 'filtered_pairs',
'object_key': '4DNFIGOJW3XZ.pairs.gz', 'uuid': '0292e08e-facf-4a16-a94e-59606f2bfc71'}
])
mocker.patch('dcicutils.ff_utils.post_metadata', return_value=e)
imp.user_workflow_reader(workbooks.get(test_insert), sheet_name, connection_mock)
args = imp.ff_utils.post_metadata.call_args
out = capsys.readouterr()[0]
print([i for i in args])
assert message == out.strip()
for a_key in args[0][0]:
assert args[0][0][a_key] == final_post[a_key]
def test_order_sorter(capsys):
test_list = ["ExperimentHiC", "BiosampleCellCulture", "Biosource", "Document", "Modification",
"IndividualMouse", "Biosample", "Lab", "User", "Trouble"]
ordered_list = ['User', 'Lab', 'Document', 'IndividualMouse', 'Modification', 'Biosource',
'BiosampleCellCulture', 'Biosample', 'ExperimentHiC']
message0 = "WARNING! Trouble sheet(s) are not loaded"
message1 = '''WARNING! Check the sheet names and the reference list "sheet_order"'''
assert ordered_list == imp.order_sorter(test_list)
out = capsys.readouterr()[0]
outlist = [i.strip() for i in out.split('\n') if i is not ""]
import sys
if (sys.version_info > (3, 0)):
assert message0 in outlist[0]
assert message1 in outlist[1]
@pytest.mark.file_operation
def test_loadxl_cycle(capsys, mocker, connection_mock):
patch_list = {'Experiment': [{"uuid": "some_uuid"}]}
e = {'status': 'success', '@graph': [{'uuid': 'some_uuid'}]}
message = "EXPERIMENT(phase2): 1 items patched."
mocker.patch('dcicutils.ff_utils.patch_metadata', return_value=e)
imp.loadxl_cycle(patch_list, connection_mock, [])
out = capsys.readouterr()[0]
assert message == out.strip()
def test_verify_and_return_item_good_item(mocker, connection_mock, returned_award_objframe):
mocker.patch('dcicutils.ff_utils.get_metadata', return_value=returned_award_objframe.json())
res = imp._verify_and_return_item('/awards/1U01ES017166-01/', connection_mock)
assert res == returned_award_objframe.json()
def test_verify_and_return_item_bad_item(mocker, connection_mock):
mocker.patch('dcicutils.ff_utils.get_metadata', return_value=None)
res = imp._verify_and_return_item('blah', connection_mock)
assert res is None
@pytest.mark.file_operation
def test_cabin_cross_check_dryrun(mocker, connection_mock, capsys):
""" checks that the filename passed in is a file and otherwise treats as normal dryrun
"""
mocker.patch('wranglertools.import_data._verify_and_return_item', side_effect=[
{'awards': '/awards/test_award/'}, {'@id': '/awards/test_award/'}
])
imp.cabin_cross_check(connection_mock, False, False, './tests/data_files/workbooks/Exp_Set_insert.xlsx', False, None, None)
out = capsys.readouterr()[0]
message = '''
Running on: https://data.4dnucleome.org/
Submitting User: test@test.test
Submitting Lab: test_lab
Submitting Award: test_award
############## DRY-RUN MODE ################
Since there are no '--update' and/or '--patchall' arguments, you are running the DRY-RUN validation
The validation will only check for schema rules, but not for object relations
############## DRY-RUN MODE ################
'''
assert out.strip() == message.strip()
def test_cabin_cross_check_remote_w_single_lab_award(mocker, connection_mock, capsys):
mocker.patch('wranglertools.import_data.pp.Path.is_file', return_value=True)
mocker.patch('wranglertools.import_data._verify_and_return_item', side_effect=[
{'awards': '/awards/test_award/'}, {'@id': '/awards/test_award/'}
])
imp.cabin_cross_check(connection_mock, False, False, 'blah', True, None, None)
out = capsys.readouterr()[0]
message = '''
Running on: https://data.4dnucleome.org/
Submitting User: test@test.test
Submitting Lab: test_lab
Submitting Award: test_award
############## DRY-RUN MODE ################
Since there are no '--update' and/or '--patchall' arguments, you are running the DRY-RUN validation
The validation will only check for schema rules, but not for object relations
############## DRY-RUN MODE ################
'''
assert out.strip() == message.strip()
def test_cabin_cross_check_not_remote_w_lab_award_options(mocker, connection_mock, capsys):
mocker.patch('wranglertools.import_data.pp.Path.is_file', return_value=True)
mocker.patch.object(connection_mock, 'prompt_for_lab_award', return_value='blah')
mocker.patch('wranglertools.import_data._verify_and_return_item', side_effect=[
{'awards': '/awards/test_award/'}, {'@id': '/awards/test_award/'}
])
connection_mock.labs = ['test_lab', 'other_lab']
imp.cabin_cross_check(connection_mock, False, False, 'blah', False,
'795847de-20b6-4f8c-ba8d-185215469cbf', 'c55dd1f0-433b-4714-bfce-8b3ae09f071c')
out = capsys.readouterr()[0]
print(out)
message = '''
Running on: https://data.4dnucleome.org/
Submitting User: test@test.test
Submitting Lab: 795847de-20b6-4f8c-ba8d-185215469cbf
Submitting Award: c55dd1f0-433b-4714-bfce-8b3ae09f071c
############## DRY-RUN MODE ################
Since there are no '--update' and/or '--patchall' arguments, you are running the DRY-RUN validation
The validation will only check for schema rules, but not for object relations
############## DRY-RUN MODE ################
'''
assert out.strip() == message.strip()
def test_cabin_cross_check_remote_w_lab_award_options(mocker, connection_mock, capsys):
mocker.patch('wranglertools.import_data.pp.Path.is_file', return_value=True)
mocker.patch('wranglertools.import_data._verify_and_return_item', side_effect=[
{'awards': '/awards/test_award/'}, {'@id': '/awards/test_award/'}
])
connection_mock.labs = ['test_lab', 'other_lab']
imp.cabin_cross_check(connection_mock, False, False, 'blah', True,
'795847de-20b6-4f8c-ba8d-185215469cbf', 'c55dd1f0-433b-4714-bfce-8b3ae09f071c')
out = capsys.readouterr()[0]
print(out)
message = '''
Running on: https://data.4dnucleome.org/
Submitting User: test@test.test
Submitting Lab: 795847de-20b6-4f8c-ba8d-185215469cbf
Submitting Award: c55dd1f0-433b-4714-bfce-8b3ae09f071c
############## DRY-RUN MODE ################
Since there are no '--update' and/or '--patchall' arguments, you are running the DRY-RUN validation
The validation will only check for schema rules, but not for object relations
############## DRY-RUN MODE ################
'''
assert out.strip() == message.strip()
def test_cabin_cross_check_remote_w_ok_award_and_no_lab_options(
mocker, connection_mock, capsys, returned_lab_w_two_awards_objframe, returned_award_objframe):
mocker.patch('wranglertools.import_data.pp.Path.is_file', return_value=True)
mocker.patch('wranglertools.import_data._verify_and_return_item', side_effect=[
{'awards': ['/awards/1U54DK107977-01/', '/awards/1U01ES017166-01/']}, {'@id': '/awards/1U54DK107977-01/'}
])
connection_mock.lab = '/labs/bing-ren-lab/'
connection_mock.labs = ['/labs/bing-ren-lab/']
imp.cabin_cross_check(connection_mock, False, False, 'blah', True, None, '/awards/1U54DK107977-01/')
out = capsys.readouterr()[0]
print(out)
message = '''
Running on: https://data.4dnucleome.org/
Submitting User: test@test.test
Submitting Lab: /labs/bing-ren-lab/
Submitting Award: /awards/1U54DK107977-01/
############## DRY-RUN MODE ################
Since there are no '--update' and/or '--patchall' arguments, you are running the DRY-RUN validation
The validation will only check for schema rules, but not for object relations
############## DRY-RUN MODE ################
'''
assert out.strip() == message.strip()
def test_cabin_cross_check_remote_w_multilabs_no_options(mocker, connection_mock, capsys):
mocker.patch('wranglertools.import_data.pp.Path.is_file', return_value=True)
mocker.patch('wranglertools.import_data._verify_and_return_item', side_effect=[None, None])
connection_mock.labs = ['/labs/bing-ren-lab/', '/labs/test-lab/']
connection_mock.award = None
connection_mock.set_award = lambda x, y: None
imp.cabin_cross_check(connection_mock, False, False, 'blah', True, None, None)
out = capsys.readouterr()[0]
print(out)
message = '''
Running on: https://data.4dnucleome.org/
Submitting Lab NOT FOUND: None
Submitting award NOT FOUND: None
Submitting User: test@test.test
WARNING: Submitting Lab and Award Unspecified
Lab and Award info must be included for all items or submission will fail
Submitting Lab: None
Submitting Award: None
############## DRY-RUN MODE ################
Since there are no '--update' and/or '--patchall' arguments, you are running the DRY-RUN validation
The validation will only check for schema rules, but not for object relations
############## DRY-RUN MODE ################
'''
assert out.strip() == message.strip()
def test_cabin_cross_check_remote_w_labopt_and_lab_has_single_award(mocker, connection_mock, capsys):
mocker.patch('wranglertools.import_data.pp.Path.is_file', return_value=True)
mocker.patch('wranglertools.import_data._verify_and_return_item', side_effect=[
{'awards': '/awards/test_award/'}, {'@id': '/awards/test_award/'}
])
connection_mock.labs = ['test_lab', 'other_lab']
imp.cabin_cross_check(connection_mock, False, False, 'blah', True, '/labs/test_lab/', None)
out = capsys.readouterr()[0]
print(out)
message = '''
Running on: https://data.4dnucleome.org/
Submitting User: test@test.test
Submitting Lab: /labs/test_lab/
Submitting Award: test_award
############## DRY-RUN MODE ################
Since there are no '--update' and/or '--patchall' arguments, you are running the DRY-RUN validation
The validation will only check for schema rules, but not for object relations
############## DRY-RUN MODE ################
'''
assert out.strip() == message.strip()
def test_cabin_cross_check_remote_w_unknown_lab_and_award(mocker, connection_mock, capsys):
mocker.patch('wranglertools.import_data.pp.Path.is_file', return_value=True)
mocker.patch('wranglertools.import_data._verify_and_return_item', side_effect=[None, None])
connection_mock.labs = ['test_lab', 'other_lab']
imp.cabin_cross_check(connection_mock, False, False, 'blah', True, 'unknown_lab', 'unknown_award')
out = capsys.readouterr()[0]
message = '''
Running on: https://data.4dnucleome.org/
Submitting Lab NOT FOUND: unknown_lab
Submitting award NOT FOUND: unknown_award
Submitting User: test@test.test
WARNING: Submitting Lab and Award Unspecified
Lab and Award info must be included for all items or submission will fail
Submitting Lab: None
Submitting Award: None
############## DRY-RUN MODE ################
Since there are no '--update' and/or '--patchall' arguments, you are running the DRY-RUN validation
The validation will only check for schema rules, but not for object relations
############## DRY-RUN MODE ################
'''
assert out.strip() == message.strip()
def test_cabin_cross_check_remote_w_award_not_for_lab_options(mocker, connection_mock, capsys):
mocker.patch('wranglertools.import_data.pp.Path.is_file', return_value=True)
mocker.patch('wranglertools.import_data._verify_and_return_item', side_effect=[
{'awards': ['/awards/test_award/', '/awards/1U54DK107977-01/']}, {'@id': '/awards/non-ren-lab-award/'}
])
with pytest.raises(SystemExit):
connection_mock.labs = ['test_lab', '/labs/bing-ren-lab']
imp.cabin_cross_check(connection_mock, False, False, 'blah', True, '/labs/bing-ren-lab/', '/awards/non-ren-lab-award/')
def test_get_all_aliases(workbooks):
wbname = "Exp_Set_insert.xlsx"
sheet = ["ExperimentSet"]
my_aliases = {'sample_expset': 'ExperimentSet'}
all_aliases = imp.get_all_aliases(workbooks.get(wbname), sheet)
assert my_aliases == all_aliases
@pytest.fixture
def fields2type():
return {
'biosource': 'array of Item:Biosource',
'biosample': 'Item:Biosample',
'description': 'string',
'biosample_quantity': 'number',
'experiment_relations.relationship_type': 'string',
'experiment_relations.experiment': 'Item:Experiment',
'average_fragment_size': 'integer',
'aliases': 'array of string'
}
@pytest.fixture
def json2post():
return {
'biosource': 'dcic:imr90',
'#biosample': 'dcic:biosamp',
'description': '',
'biosample_quantity': 1,
'aliases': 'dcic:test'
}
@pytest.fixture
def alias_dict():
return {
'test:alias1': 'Biosource',
'test:alias2': 'Biosource',
}
def test_get_f_type(fields2type):
fields = fields2type.keys()
for f in fields:
assert imp.get_f_type(f, fields2type) == fields2type[f]
assert not imp.get_f_type('nonexistent field', fields2type)
def test_add_to_mistype_message_3_words():
words = ['eeny', 'meeny', 'moe']
msg = imp.add_to_mistype_message(*words, msg='')
assert msg == "ERROR: 'eeny' is TYPE meeny - THE REQUIRED TYPE IS moe\n"
def test_add_to_mistype_message_w_msg():
words = ['eeny', 'meeny', 'moe']
msg1 = "ERROR: 'eeny' is TYPE meeny - THE REQUIRED TYPE IS moe\n"
msg2 = imp.add_to_mistype_message(*words, msg=msg1)
assert msg2 == msg1 * 2
def test_add_to_mistype_message_2_words():
words = ['eeny', 'meeny', '']
msg = imp.add_to_mistype_message(*words, msg='')
assert msg == "ERROR: 'eeny' is TYPE meeny - THE REQUIRED TYPE IS \n"
def test_add_to_mistype_message_not_found():
words = ['eeny', 'HTTPNotFound', 'moe']
msg = imp.add_to_mistype_message(*words, msg='')
assert msg == "ERROR: 'eeny' is NOT FOUND - THE REQUIRED TYPE IS moe\n"
def test_validate_item_in_alias_dict_correct_type(alias_dict, connection_mock):
item = 'test:alias1'
msg = imp.validate_item([item], 'Biosource', alias_dict, connection_mock)
assert not msg
def test_validate_item_in_alias_dict_incorrect_type(alias_dict, connection_mock):
item = 'test:alias1'
msg = imp.validate_item([item], 'Biosample', alias_dict, connection_mock)
assert msg.startswith("ERROR")
def test_validate_multiple_items_in_alias_dict_correct_type(alias_dict, connection_mock):
items = ['test:alias1', 'test:alias2']
msg = imp.validate_item(items, 'Biosource', alias_dict, connection_mock)
assert not msg
def test_validate_multiple_items_in_alias_dict_incorrect_type(alias_dict, connection_mock):
items = ['test:alias1', 'test:alias2']
msg = imp.validate_item(items, 'Biosample', alias_dict, connection_mock)
lns = msg.split('\n')
assert len(lns) == 2
for l in lns:
assert l.startswith("ERROR")
def test_validate_item_not_in_alias_dict_alias_indb(mocker, connection_mock):
item = 'test:alias1'
mocker.patch('dcicutils.ff_utils.get_metadata', return_value={'@type': ['Biosource']})
msg = imp.validate_item([item], 'Biosource', {}, connection_mock)
assert not msg