-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_containers.py
200 lines (167 loc) · 6.75 KB
/
test_containers.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2016 University of Dundee & Open Microscopy Environment.
# 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/>.
"""
Tests creation, linking, editing & deletion of containers
"""
import omero
import omero.clients
from omero.rtypes import rtime
from omeroweb.api import api_settings
from omeroweb.testlib import IWebTest
from omeroweb.testlib import get_json, post, post_json, delete_json
import json
from django.core.urlresolvers import reverse
class TestContainers(IWebTest):
"""
Tests creation, linking, editing & deletion of containers
"""
def blank_image(self):
"""
Returns a new foundational Image with Channel objects attached for
view method testing.
"""
print dir(self)
pixels = self.create_pixels(client=self.client)
for the_c in range(pixels.getSizeC().val):
channel = omero.model.ChannelI()
channel.logicalChannel = omero.model.LogicalChannelI()
pixels.addChannel(channel)
image = pixels.getImage()
return self.sf.getUpdateService().saveAndReturnObject(image)
def test_add_and_rename_container(self):
# Add project
request_url = reverse("manage_action_containers",
args=["addnewcontainer"])
data = {
'folder_type': 'project',
'name': 'foobar'
}
response = post(self.django_client, request_url, data)
pid = json.loads(response.content).get("id")
# Add dataset to the project
request_url = reverse("manage_action_containers",
args=["addnewcontainer", "project", pid])
data = {
'folder_type': 'dataset',
'name': 'foobar'
}
post(self.django_client, request_url, data)
# Rename project
request_url = reverse("manage_action_containers",
args=["savename", "project", pid])
data = {
'name': 'anotherfoobar'
}
post(self.django_client, request_url, data)
# Change project description
request_url = reverse("manage_action_containers",
args=["savedescription", "project", pid])
data = {
'description': 'anotherfoobar'
}
post(self.django_client, request_url, data)
def test_add_owned_container(self):
"""Test root user creating a Dataset owned by another user."""
request_url = reverse("manage_action_containers",
args=["addnewcontainer"])
# Create user in 2 groups
group1 = self.new_group()
group2 = self.new_group()
user = self.new_user(group=group1)
self.add_groups(user, [group2])
# Container will get added to active_group
session = self.django_root_client.session
session['active_group'] = group2.id.val
session.save()
data = {
'folder_type': 'dataset',
'name': 'ownedby',
'owner': str(user.id.val)
}
response = post(self.django_root_client, request_url, data)
did = json.loads(response.content).get("id")
# Check that Dataset was created & has correct group and owner
request_url = reverse("manage_action_containers",
args=["addnewcontainer"])
version = api_settings.API_VERSIONS[-1]
request_url = reverse('api_dataset', kwargs={'api_version': version,
'object_id': did})
rsp_json = get_json(self.django_root_client, request_url, {})
dataset = rsp_json['data']
assert dataset['@id'] == did
assert dataset['omero:details']['owner']['@id'] == user.id.val
assert dataset['omero:details']['group']['@id'] == group2.id.val
def test_paste_move_remove_deletamany_image(self):
# Add dataset
request_url = reverse("manage_action_containers",
args=["addnewcontainer"])
data = {
'folder_type': 'dataset',
'name': 'foobar'
}
response = post(self.django_client, request_url, data)
did = json.loads(response.content).get("id")
img = self.make_image()
print img
# Link image to Dataset
request_url = reverse("api_links")
data = {
'dataset': {did: {'image': [img.id.val]}}
}
post_json(self.django_client, request_url, data)
# Unlink image from Dataset
request_url = reverse("api_links")
data = {
'dataset': {did: {'image': [img.id.val]}}
}
response = delete_json(self.django_client, request_url, data)
# Response will contain remaining links from image (see test_links.py)
assert response == {"success": True}
def test_create_share(self):
img = self.make_image()
request_url = reverse("manage_action_containers",
args=["add", "share"])
data = {
'enable': 'on',
'image': img.id.val,
'members': self.user.id.val,
'message': 'foobar'
}
post(self.django_client, request_url, data)
def test_edit_share(self):
# create images
images = [self.create_test_image(session=self.sf),
self.create_test_image(session=self.sf)]
sid = self.sf.getShareService().createShare(
"foobar", rtime(None), images, [self.user], [], True)
request_url = reverse("manage_action_containers",
args=["save", "share", sid])
data = {
'enable': 'on',
'image': [i.id.val for i in images],
'members': self.user.id.val,
'message': 'another foobar'
}
post(self.django_client, request_url, data)
# remove image from share
request_url = reverse("manage_action_containers",
args=["removefromshare", "share", sid])
data = {
'source': images[1].id.val,
}
post(self.django_client, request_url, data)