-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_tree.py
2466 lines (2102 loc) · 81.8 KB
/
test_tree.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2014-2015 Glencoe Software, Inc.
# All rights reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
Simple integration tests for the "tree" module.
"""
import pytest
from omero.testlib import ITest
from omero.gateway import BlitzGateway, _letterGridLabel
from omero.constants.metadata import NSINSIGHTTAGSET
from omero.model import ProjectI, DatasetI, ImageI, ScreenI, PlateI, \
PlateAcquisitionI, TagAnnotationI, ProjectAnnotationLinkI, \
DatasetAnnotationLinkI, ImageAnnotationLinkI, ScreenAnnotationLinkI, \
PlateAnnotationLinkI, PlateAcquisitionAnnotationLinkI, \
WellI, WellAnnotationLinkI
from omero.rtypes import rstring, rtime, rint
from omeroweb.webclient.tree import marshal_experimenter, \
marshal_projects, marshal_datasets, marshal_images, marshal_plates, \
marshal_screens, marshal_plate_acquisitions, marshal_orphaned, \
marshal_tags, marshal_tagged, marshal_shares, marshal_discussions
from datetime import datetime
def unwrap(x):
"""Handle case where there is no value because attribute is None"""
if x is not None:
return x.val
return None
def cmp_id(x, y):
"""Identifier comparator."""
return cmp(unwrap(x.id), unwrap(y.id))
def cmp_name(x, y):
"""Name comparator."""
return cmp(unwrap(x.name), unwrap(y.name))
def cmp_column(x, y):
"""Column comparator for Wells."""
return cmp(unwrap(x.column), unwrap(y.column))
def lower_or_none(x):
""" Lower the case or `None`"""
if x is not None:
return x.lower()
return None
def cmp_name_insensitive(x, y):
"""Case-insensitive name comparator."""
return cmp(lower_or_none(unwrap(x.name)),
lower_or_none(unwrap(y.name)))
def cmp_omename_insensitive(x, y):
"""Case-insensitive omeName comparator."""
return cmp(lower_or_none(unwrap(x.omeName)),
lower_or_none(unwrap(y.omeName)))
def cmp_textValue_insensitive(x, y):
"""Case-insensitive textValue comparator."""
return cmp(lower_or_none(unwrap(x.textValue)),
lower_or_none(unwrap(y.textValue)))
def get_connection(user, group_id=None):
"""
Get a BlitzGateway connection for the given user's client
"""
connection = BlitzGateway(client_obj=user[0])
# Refresh the session context
connection.getEventContext()
if group_id is not None:
connection.SERVICE_OPTS.setOmeroGroup(group_id)
return connection
def get_update_service(user):
"""
Get the update_service for the given user's client
"""
return user[0].getSession().getUpdateService()
def get_perms(user, obj, dtype):
"""
Get the permissions as a string from this list and in this order:
'canEdit canAnnotate canLink canDelete canChgrp'
according to the specified user (client, user)
"""
qs = user[0].getSession().getQueryService()
# user reloads obj so that permissions apply correctly
obj = qs.get(dtype, obj.id.val, {'omero.group': '-1'})
permissions = obj.details.permissions
perms = []
if permissions.canEdit():
perms.append('canEdit')
if permissions.canAnnotate():
perms.append('canAnnotate')
if permissions.canLink():
perms.append('canLink')
if permissions.canDelete():
perms.append('canDelete')
if permissions.canChgrp():
perms.append('canChgrp')
if permissions.canChown():
perms.append('canChown')
if obj.details.owner.id.val == user[1].id.val:
perms.append('isOwned')
return ' '.join(perms)
def expected_experimenter(user):
expected = {
'id': user[1].id.val,
'omeName': user[1].omeName.val,
'firstName': user[1].firstName.val,
'lastName': user[1].lastName.val
}
if user[1].email is not None:
expected['email'] = user[1].email.val
return expected
def expected_projects(user, projects):
""" Marshal projects with permissions according to user """
expected = []
for project in projects:
expected.append({
'id': project.id.val,
'name': project.name.val,
'ownerId': project.details.owner.id.val,
'childCount': len(project.linkedDatasetList()),
'permsCss': get_perms(user, project, "Project")
})
return expected
def expected_datasets(user, datasets):
expected = []
for dataset in datasets:
expected.append({
'id': dataset.id.val,
'name': dataset.name.val,
'ownerId': dataset.details.owner.id.val,
'childCount': len(dataset.linkedImageList()),
'permsCss': get_perms(user, dataset, "Dataset")
})
return expected
def expected_images(user, images, extraValues=None):
expected = []
for image in images:
i = {
'id': image.id.val,
'name': image.name.val,
'ownerId': image.details.owner.id.val,
'permsCss': get_perms(user, image, "Image"),
}
if extraValues is not None:
i.update(extraValues)
if image.fileset is not None:
i['filesetId'] = image.fileset.id.val
expected.append(i)
return expected
def expected_screens(user, screens):
expected = []
for screen in screens:
expected.append({
'id': screen.id.val,
'name': screen.name.val,
'ownerId': screen.details.owner.id.val,
'childCount': len(screen.linkedPlateList()),
'permsCss': get_perms(user, screen, "Screen")
})
return expected
def expected_plates(user, plates):
expected = []
for plate in plates:
expected.append({
'id': plate.id.val,
'name': plate.name.val,
'ownerId': plate.details.owner.id.val,
'childCount': len(plate.copyPlateAcquisitions()),
'permsCss': get_perms(user, plate, "Plate")
})
return expected
def expected_plate_acquisitions(user, plate_acquisitions):
expected = []
for acq in plate_acquisitions:
if acq.name is not None:
acq_name = acq.name.val
elif acq.startTime is not None and acq.endTime is not None:
start_time = datetime.utcfromtimestamp(acq.startTime.val / 1000.0)
end_time = datetime.utcfromtimestamp(acq.endTime.val / 1000.0)
acq_name = '%s - %s' % (start_time, end_time)
else:
acq_name = 'Run %d' % acq.id.val
expected.append({
'id': acq.id.val,
'name': acq_name,
'ownerId': acq.details.owner.id.val,
'permsCss': get_perms(user, acq, "PlateAcquisition")
})
return expected
def expected_wells(user, wells):
expected = []
for well in wells:
rName = unwrap(well.plate.rowNamingConvention)
cName = unwrap(well.plate.columnNamingConvention)
pName = unwrap(well.plate.name)
row = well.row.val
col = well.column.val
rowname = str(row + 1) if rName == 'number' else _letterGridLabel(row)
colname = _letterGridLabel(col) if cName == 'letter' else str(col + 1)
name = "%s - %s%s" % (pName, rowname, colname)
expected.append({
'id': well.id.val,
'name': name,
'ownerId': well.details.owner.id.val,
'plateId': well.plate.id.val,
'permsCss': get_perms(user, well, "Well")
})
return expected
def expected_orphaned(user, images):
return {
'id': user[1].id.val,
'childCount': len(images)
}
def expected_tags(user, tags):
expected = []
for tag in tags:
t = {
'id': tag.id.val,
'value': tag.textValue.val,
'ownerId': tag.details.owner.id.val,
'childCount': len(tag.linkedAnnotationList()),
'permsCss': get_perms(user, tag, "TagAnnotation")
}
if tag.description is not None:
t['description'] = tag.description.val
if tag.ns is not None and tag.ns.val == NSINSIGHTTAGSET:
t['set'] = True
else:
t['set'] = False
expected.append(t)
return expected
def expected_tagged(user, projects, datasets, images, screens, plates,
plate_acquisitions, wells=[]):
return {
'projects': expected_projects(user, projects),
'datasets': expected_datasets(user, datasets),
'images': expected_images(user, images),
'screens': expected_screens(user, screens),
'plates': expected_plates(user, plates),
'acquisitions': expected_plate_acquisitions(user, plate_acquisitions),
'wells': expected_wells(user, wells),
}
def expected_shares(user, shares):
expected = []
for share in shares:
expected.append({
'id': share.id.val,
'ownerId': share.owner.id.val,
'isOwned':
True if user[1].id.val == share.owner.id.val else False,
'expired': False,
'active': True,
'childCount': share.getItemCount().val
})
return expected
def expected_discussions(user, discussions):
expected = []
for discussion in discussions:
expected.append({
'id': discussion.id.val,
'ownerId': discussion.owner.id.val,
'isOwned':
True if user[1].id.val == discussion.owner.id.val else False,
'expired': False,
'active': True
})
return expected
# Some names
@pytest.fixture(scope='module')
def names1(request):
return ('Apple', 'bat')
@pytest.fixture(scope='module')
def names2(request):
return ('Axe',)
@pytest.fixture(scope='module')
def names3(request):
return ('Bark', 'custard')
@pytest.fixture(scope='module')
def names4(request):
return ('Butter',)
# Projects
@pytest.fixture(scope='function')
def projects_userA_groupA(request, names1, userA,
project_hierarchy_userA_groupA):
"""
Returns new OMERO Projects with required fields set and with names
that can be used to exercise sorting semantics.
"""
to_save = []
for name in names1:
project = ProjectI()
project.name = rstring(name)
to_save.append(project)
projects = get_update_service(userA).saveAndReturnArray(to_save)
projects.extend(project_hierarchy_userA_groupA[:2])
projects.sort(cmp_name_insensitive)
return projects
@pytest.fixture(scope='function')
def projects_userB_groupA(request, names2, userB):
"""
Returns a new OMERO Project with required fields set and with a name
that can be used to exercise sorting semantics.
"""
to_save = []
for name in names2:
project = ProjectI()
project.name = rstring(name)
to_save.append(project)
projects = get_update_service(userB).saveAndReturnArray(
to_save)
projects.sort(cmp_name_insensitive)
return projects
@pytest.fixture(scope='function')
def projects_userA_groupB(request, names3, userA, groupB):
"""
Returns new OMERO Projects with required fields set and with names
that can be used to exercise sorting semantics.
"""
to_save = []
for name in names3:
project = ProjectI()
project.name = rstring(name)
to_save.append(project)
conn = get_connection(userA, groupB.id.val)
projects = conn.getUpdateService().saveAndReturnArray(to_save,
conn.SERVICE_OPTS)
projects.sort(cmp_name_insensitive)
return projects
@pytest.fixture(scope='function')
def projects_groupA(request, projects_userA_groupA,
projects_userB_groupA):
"""
Returns OMERO Projects for userA and userB in groupA
"""
projects = projects_userA_groupA + projects_userB_groupA
projects.sort(cmp_name_insensitive)
return projects
@pytest.fixture(scope='function')
def projects_groupB(request, projects_userA_groupB):
"""
Returns OMERO Projects for userA and userB in groupB
"""
projects = projects_userA_groupB
# projects.sort(cmp_name_insensitive)
return projects
@pytest.fixture(scope='function')
def projects_userA(request, projects_userA_groupA,
projects_userA_groupB):
"""
Returns OMERO Projects for userA in both groupA and groupB
"""
projects = projects_userA_groupA + projects_userA_groupB
projects.sort(cmp_name_insensitive)
return projects
@pytest.fixture(scope='function')
def projects(request, projects_groupA,
projects_groupB):
"""
Returns OMERO Projects for both users in read-only group
"""
projects = projects_groupA + projects_groupB
projects.sort(cmp_name_insensitive)
return projects
# Datasets
@pytest.fixture(scope='function')
def datasets_userA_groupA(request, userA):
"""
Returns new OMERO Datasets without project parents for userA in groupA
"""
to_save = []
for name in ['Tiger', 'sparrow']:
dataset = DatasetI()
dataset.name = rstring(name)
to_save.append(dataset)
datasets = get_update_service(userA).saveAndReturnArray(to_save)
datasets.sort(cmp_name_insensitive)
return datasets
@pytest.fixture(scope='function')
def datasets_userB_groupA(request, userB):
"""
Returns new OMERO Datasets without project parents for userB in groupA
"""
to_save = []
for name in ['lion', 'Zebra']:
dataset = DatasetI()
dataset.name = rstring(name)
to_save.append(dataset)
datasets = get_update_service(userB).saveAndReturnArray(to_save)
datasets.sort(cmp_name_insensitive)
return datasets
@pytest.fixture(scope='function')
def datasets_userA_groupB(request, userA, groupB):
"""
Returns new OMERO Datasets without project parents for userA in groupB
"""
to_save = []
for name in ['Meerkat', 'anteater']:
dataset = DatasetI()
dataset.name = rstring(name)
to_save.append(dataset)
conn = get_connection(userA, groupB.id.val)
datasets = conn.getUpdateService().saveAndReturnArray(to_save,
conn.SERVICE_OPTS)
datasets.sort(cmp_name_insensitive)
return datasets
@pytest.fixture(scope='function')
def datasets_groupA(request, datasets_userA_groupA,
datasets_userB_groupA):
"""
Returns OMERO Datasets for userA and userB in groupA
"""
datasets = datasets_userA_groupA + datasets_userB_groupA
datasets.sort(cmp_name_insensitive)
return datasets
@pytest.fixture(scope='function')
def datasets_groupB(request, datasets_userA_groupB):
"""
Returns OMERO Datasets for userA and userB in groupB
"""
datasets = datasets_userA_groupB
# datasets.sort(cmp_name_insensitive)
return datasets
@pytest.fixture(scope='function')
def datasets_userA(request, datasets_userA_groupA,
datasets_userA_groupB):
"""
Returns OMERO Datasets for userA in groupA and groupB
"""
datasets = datasets_userA_groupA + datasets_userA_groupB
datasets.sort(cmp_name_insensitive)
return datasets
@pytest.fixture(scope='function')
def datasets(request, datasets_groupA,
datasets_groupB):
"""
Returns OMERO Datasets for all users in all groups
"""
datasets = datasets_groupA + datasets_groupB
datasets.sort(cmp_name_insensitive)
return datasets
# ### Images ###
@pytest.fixture(scope='function')
def images_groupA(request, images_userA_groupA,
images_userB_groupA):
"""
Returns OMERO Images for userA and userB in groupA
"""
images = images_userA_groupA + images_userB_groupA
images.sort(cmp_name_insensitive)
return images
@pytest.fixture(scope='function')
def images_groupB(request, images_userA_groupB):
"""
Returns OMERO Images for userA and userB in groupB
"""
images = images_userA_groupB
# images.sort(cmp_name_insensitive)
return images
@pytest.fixture(scope='function')
def images_userA(request, images_userA_groupA, images_userA_groupB):
"""
Returns OMERO Images for userA in groupA and groupB
"""
images = images_userA_groupA + images_userA_groupB
images.sort(cmp_name_insensitive)
return images
@pytest.fixture(scope='function')
def images(request, images_groupA, images_groupB):
"""
Returns OMERO Images for all users in all groups
"""
images = images_groupA + images_groupB
images.sort(cmp_name_insensitive)
return images
# Shares
@pytest.fixture(scope='function')
def shares_userA_owned(request, userA, userB, images_userA_groupA):
"""
Returns OMERO Shares with Image Children for userA
"""
conn = get_connection(userA)
shares = []
for name in ['ShareB', 'ShareA']:
# It seems odd that unlike most services, createShare returns the id
# of what was created instead of the share itself
sid = conn.getShareService().createShare(name, rtime(None),
images_userA_groupA,
[userB[1]],
[], True)
sh = conn.getShareService().getShare(sid)
shares.append(sh)
shares.sort(cmp_id)
return shares
@pytest.fixture(scope='function')
def shares_userB_owned(request, userA, userB, images_userB_groupA):
"""
Returns new OMERO Shares with Image Children for userB
"""
conn = get_connection(userB)
shares = []
for name in ['ShareD', 'ShareC']:
sid = conn.getShareService().createShare(name, rtime(None),
images_userB_groupA,
[userA[1]],
[], True)
sh = conn.getShareService().getShare(sid)
shares.append(sh)
shares.sort(cmp_id)
return shares
@pytest.fixture(scope='function')
def shares(request, shares_userA_owned, shares_userB_owned):
"""
Returns OMERO Shares for userA and userB
"""
shares = shares_userA_owned + shares_userB_owned
shares.sort(cmp_id)
return shares
# Discussions
@pytest.fixture(scope='function')
def discussions_userA_owned(request, userA, userB):
"""
Returns OMERO Shares with Image Children for userA
"""
conn = get_connection(userA)
discussions = []
for name in ['DiscussionB', 'DiscussionA']:
sid = conn.getShareService().createShare(name, rtime(None),
[],
[userB[1]],
[], True)
sh = conn.getShareService().getShare(sid)
discussions.append(sh)
discussions.sort(cmp_id)
return discussions
@pytest.fixture(scope='function')
def discussions_userB_owned(request, userA, userB):
"""
Returns new OMERO Shares with Image Children for userB
"""
conn = get_connection(userB)
discussions = []
for name in ['DiscussionD', 'DiscussionC']:
sid = conn.getShareService().createShare(name, rtime(None),
[],
[userA[1]],
[], True)
sh = conn.getShareService().getShare(sid)
discussions.append(sh)
discussions.sort(cmp_id)
return discussions
@pytest.fixture(scope='function')
def discussions(request, discussions_userA_owned, discussions_userB_owned):
"""
Returns OMERO Shares for userA and userB
"""
discussions = discussions_userA_owned + discussions_userB_owned
discussions.sort(cmp_id)
return discussions
# Screens
@pytest.fixture(scope='function')
def screens_userA_groupA(request, userA):
"""
Returns new OMERO Screens for userA in groupA
"""
to_save = []
for name in ['France', 'albania']:
screen = ScreenI()
screen.name = rstring(name)
to_save.append(screen)
screens = get_update_service(userA).saveAndReturnArray(to_save)
screens.sort(cmp_name_insensitive)
return screens
@pytest.fixture(scope='function')
def screens_userB_groupA(request, userB):
"""
Returns new OMERO Screens for userB in groupA
"""
to_save = []
for name in ['Canada', 'Australia']:
screen = ScreenI()
screen.name = rstring(name)
to_save.append(screen)
screens = get_update_service(userB).saveAndReturnArray(to_save)
screens.sort(cmp_name_insensitive)
return screens
@pytest.fixture(scope='function')
def screens_userA_groupB(request, userA, groupB):
"""
Returns new OMERO Screens for userA in groupB
"""
to_save = []
for name in ['United States of America', 'United Kingom']:
screen = ScreenI()
screen.name = rstring(name)
to_save.append(screen)
conn = get_connection(userA, groupB.id.val)
screens = conn.getUpdateService().saveAndReturnArray(to_save,
conn.SERVICE_OPTS)
screens.sort(cmp_name_insensitive)
return screens
@pytest.fixture(scope='function')
def screens_groupA(request, screens_userA_groupA, screens_userB_groupA):
"""
Returns OMERO Screens for userA and userB in groupA
"""
screens = screens_userA_groupA + screens_userB_groupA
screens.sort(cmp_name_insensitive)
return screens
@pytest.fixture(scope='function')
def screens_groupB(request, screens_userA_groupB):
"""
Returns OMERO Screens for userA and userB in groupB
"""
screens = screens_userA_groupB
# screens.sort(cmp_name_insensitive)
return screens
@pytest.fixture(scope='function')
def screens_userA(request, screens_userA_groupA, screens_userA_groupB):
"""
Returns OMERO Screens for userA in groupA and groupB
"""
screens = screens_userA_groupA + screens_userA_groupB
screens.sort(cmp_name_insensitive)
return screens
@pytest.fixture(scope='function')
def screens(request, screens_groupA, screens_groupB):
"""
Returns OMERO Screens for all users in all groups
"""
screens = screens_groupA + screens_groupB
screens.sort(cmp_name_insensitive)
return screens
# Plates
@pytest.fixture(scope='function')
def plates_userA_groupA(request, userA):
"""
Returns new OMERO Plates for userA in groupA
"""
to_save = []
for name in ['New York', 'New Amsterdam']:
plate = PlateI()
plate.name = rstring(name)
to_save.append(plate)
plates = get_update_service(userA).saveAndReturnArray(to_save)
plates.sort(cmp_name_insensitive)
return plates
@pytest.fixture(scope='function')
def plates_userB_groupA(request, userB):
"""
Returns new OMERO Plates for userB in groupA
"""
to_save = []
for name in ['Istanbul', 'Constantinople']:
plate = PlateI()
plate.name = rstring(name)
to_save.append(plate)
plates = get_update_service(userB).saveAndReturnArray(to_save)
plates.sort(cmp_name_insensitive)
return plates
@pytest.fixture(scope='function')
def plates_userA_groupB(request, userA, groupB):
"""
Returns new OMERO Plates for userA in groupB
"""
to_save = []
for name in ['Mumbai', 'Bombay']:
plate = PlateI()
plate.name = rstring(name)
to_save.append(plate)
conn = get_connection(userA, groupB.id.val)
plates = conn.getUpdateService().saveAndReturnArray(to_save,
conn.SERVICE_OPTS)
plates.sort(cmp_name_insensitive)
return plates
@pytest.fixture(scope='function')
def plates_groupA(request, plates_userA_groupA, plates_userB_groupA):
"""
Returns OMERO Plates for userA and userB in groupA
"""
plates = plates_userA_groupA + plates_userB_groupA
plates.sort(cmp_name_insensitive)
return plates
@pytest.fixture(scope='function')
def plates_groupB(request, plates_userA_groupB):
"""
Returns OMERO Plates for userA and userB in groupB
"""
plates = plates_userA_groupB
# plates.sort(cmp_name_insensitive)
return plates
@pytest.fixture(scope='function')
def plates_userA(request, plates_userA_groupA, plates_userA_groupB):
"""
Returns OMERO Plates for userA in groupA and groupB
"""
plates = plates_userA_groupA + plates_userA_groupB
plates.sort(cmp_name_insensitive)
return plates
@pytest.fixture(scope='function')
def plates(request, plates_groupA, plates_groupB):
"""
Returns OMERO Plates for all users in all groups
"""
plates = plates_groupA + plates_groupB
plates.sort(cmp_name_insensitive)
return plates
@pytest.fixture(scope='function')
def screen_hierarchy_userA_groupA(request, userA):
"""
Returns OMERO Screens with Plate Children with Plate Acquisition Children
Note: This returns a list of mixed objects in a specified order
"""
# Create and name all the objects
screenA = ScreenI()
screenA.name = rstring('ScreenA')
screenB = ScreenI()
screenB.name = rstring('ScreenB')
plateA = PlateI()
plateA.name = rstring('PlateA')
acqA = PlateAcquisitionI()
acqA.name = rstring('AcqA')
# No name for acqB
acqNone = PlateAcquisitionI()
# Only set startTime and endTime for acqC
acqTime = PlateAcquisitionI()
acqTime.startTime = rtime(0)
acqTime.endTime = rtime(1)
wellA1 = WellI()
wellA1.column = rint(0)
wellA1.row = rint(0)
wellA2 = WellI()
wellA2.column = rint(1)
wellA2.row = rint(0)
# Link them together like so:
# screenA
# plateA
# acqA
# acqNone
# acqTime
# screenB
# plateA
# acqA
# acqNone
# acqTime
screenA.linkPlate(plateA)
screenB.linkPlate(plateA)
plateA.addPlateAcquisition(acqA)
plateA.addPlateAcquisition(acqNone)
plateA.addPlateAcquisition(acqTime)
plateA.addWell(wellA1)
plateA.addWell(wellA2)
to_save = [screenA, screenB]
screens = get_update_service(userA).saveAndReturnArray(to_save)
screens.sort(cmp_name_insensitive)
plates = screens[0].linkedPlateList()
plates.sort(cmp_name_insensitive)
acqs = plates[0].copyPlateAcquisitions()
acqs.sort(cmp_id)
wells = plates[0].copyWells()
wells.sort(cmp_column)
# return [scr, scr, plate, acq, acq, acq, well, well]
return screens + plates + acqs + wells
@pytest.fixture(scope='function')
def screen_hierarchy_userB_groupA(request, userB):
"""
Returns OMERO Screens with Plate Children with Plate Acquisition Children
Note: This returns a list of mixed objects in a specified order
"""
# Create and name all the objects
screenC = ScreenI()
screenC.name = rstring('ScreenC')
plateB = PlateI()
plateB.name = rstring('PlateB')
acqB = PlateAcquisitionI()
acqB.name = rstring('AcqB')
# Link them together like so:
# screenC
# plateB
# acqB
screenC.linkPlate(plateB)
plateB.addPlateAcquisition(acqB)
to_save = [screenC]
screens = get_update_service(userB).saveAndReturnArray(to_save)
screens.sort(cmp_name_insensitive)
plates = screens[0].linkedPlateList()
acqs = plates[0].copyPlateAcquisitions()
return screens + plates + acqs
@pytest.fixture(scope='function')
def screen_hierarchy_userA_groupB(request, userA, groupB):
"""
Returns OMERO Screens with Plate Children with Plate Acquisition Children
Note: This returns a list of mixed objects in a specified order
"""
# Create and name all the objects
screenD = ScreenI()
screenD.name = rstring('ScreenD')
plateC = PlateI()
plateC.name = rstring('PlateC')
acqC = PlateAcquisitionI()
acqC.name = rstring('AcqC')
# Link them together like so:
# screenD
# plateC
# acqC
screenD.linkPlate(plateC)
plateC.addPlateAcquisition(acqC)
to_save = [screenD]
conn = get_connection(userA, groupB.id.val)
screens = conn.getUpdateService().saveAndReturnArray(to_save,
conn.SERVICE_OPTS)
screens.sort(cmp_name_insensitive)
plates = screens[0].linkedPlateList()
acqs = plates[0].copyPlateAcquisitions()