def test880(self): try: createTestImage(self.client.sf) i = self.client.sf.getQueryService().findAll("Image", params.theFilter)[0] self.assert_(i != None) self.assert_(i.id != None) self.assert_(i.details != None) except omero.ValidationException, ve: print " test880 - createTestImage has failed. This fixture method needs to be fixed."
def test1179(self): createTestImage(self.root.sf) rdefs = self.root.sf.getQueryService().findAll("RenderingDef", None) if len(rdefs) == 0: raise "Must have at least one rendering def" share = self.root.sf.getShareService() sid = share.createShare("", None, [], [], [], True) share.activate(sid) tb = self.root.sf.createThumbnailStore() try: tb.setPixelsId(rdefs[0].pixels.id.val) except omero.SecurityViolation: self.fail("Pixels was not in share")
def testBasicUsage(self): gateway = self.client.sf.createGateway() gateway.getProjects([0], False) try: # query below does not find image if created with self.createTestImage() even though it # uses 'identical' code to createTestImage(self.client.sf), which uses script_utils # iid = self.createTestImage().getId().getValue() iid = createTestImage(self.client.sf) print iid, type(iid) query = self.client.sf.getQueryService() params = omero.sys.Parameters() params.map = {} params.map["oid"] = rlong(iid) params.theFilter = omero.sys.Filter() params.theFilter.offset = rint(0) params.theFilter.limit = rint(1) pixel = query.findByQuery( "select p from Pixels as p left outer join fetch p.image as i where i.id=:oid", params ) print pixel imgid = pixel.image.id.val print imgid gateway.getRenderedImage(pixel.id.val, 0, 0) except omero.ValidationException, ve: print " testBasicUsage - createTestImage has failed. This fixture method needs to be fixed."
def testBasicUsage(self): gateway = self.client.sf.createGateway() gateway.getProjects([0], False) try: # query below does not find image if created with self.createTestImage() even though it # uses 'identical' code to createTestImage(self.client.sf), which uses script_utils #iid = self.createTestImage().getId().getValue() iid = createTestImage(self.client.sf) print iid, type(iid) query = self.client.sf.getQueryService() params = omero.sys.Parameters() params.map = {} params.map["oid"] = rlong(iid) params.theFilter = omero.sys.Filter() params.theFilter.offset = rint(0) params.theFilter.limit = rint(1) pixel = query.findByQuery( "select p from Pixels as p left outer join fetch p.image as i where i.id=:oid", params) print pixel imgid = pixel.image.id.val print imgid gateway.getRenderedImage(pixel.id.val, 0, 0) except omero.ValidationException, ve: print " testBasicUsage - createTestImage has failed. This fixture method needs to be fixed."
def test8704(self): owner, owner_obj = self.new_client_and_user( perms="rw----") # Owner of share member, member_obj = self.new_client_and_user( perms="rw----") # Different group! member_suuid = member.sf.getAdminService().getEventContext( ).sessionUuid owner_suuid = owner.sf.getAdminService().getEventContext().sessionUuid member_groupId = member.sf.getAdminService().getEventContext().groupId owner_groupId = owner.sf.getAdminService().getEventContext().groupId self.assertFalse(member_suuid == owner_suuid) # just in case self.assertFalse(owner_obj.id.val == member_obj.id.val) # just in case # create image by owner owner_update = owner.sf.getUpdateService() image_id = createTestImage(owner.sf) p = omero.sys.Parameters() p.map = {"id": rlong(long(image_id))} sql = "select im from Image im join fetch im.details.owner join fetch im.details.group where im.id=:id order by im.name" image = owner.sf.getQueryService().findAllByQuery( sql, p, {'omero.group': str(owner_groupId)})[0] rdefs = owner.sf.getQueryService().findAll("RenderingDef", None) # create image by member member_update = member.sf.getUpdateService() image2 = self.new_image() image2 = member_update.saveAndReturnObject(image2) share = owner.sf.getShareService() sid = self.create_share(share, objects=[image], experimenters=[member_obj]) self.assertAccess(owner, sid) self.assertAccess(member, sid) member_share = member.sf.getShareService() share_obj = member_share.getShare(sid) # Activation shouldn't be needed any more as we pass {'omero.share': <sid>} #member_share.activate(long(sid)) # And the member should be able to use omero.share:sid member_query = member.sf.getQueryService() try: rv = member.sf.getQueryService().find("Image", image.id.val, None) except omero.SecurityViolation, sv: pass
def test8704(self): owner, owner_obj = self.new_client_and_user(perms="rw----") # Owner of share member, member_obj = self.new_client_and_user(perms="rw----") # Different group! member_suuid = member.sf.getAdminService().getEventContext().sessionUuid owner_suuid = owner.sf.getAdminService().getEventContext().sessionUuid member_groupId = member.sf.getAdminService().getEventContext().groupId owner_groupId = owner.sf.getAdminService().getEventContext().groupId self.assertFalse(member_suuid == owner_suuid) # just in case self.assertFalse(owner_obj.id.val == member_obj.id.val) # just in case # create image by owner owner_update = owner.sf.getUpdateService() image_id = createTestImage(owner.sf) p = omero.sys.Parameters() p.map = {"id": rlong(long(image_id))} sql = "select im from Image im join fetch im.details.owner join fetch im.details.group where im.id=:id order by im.name" image = owner.sf.getQueryService().findAllByQuery(sql, p, {'omero.group':str(owner_groupId)})[0] rdefs = owner.sf.getQueryService().findAll("RenderingDef", None) # create image by member member_update = member.sf.getUpdateService() image2 = self.new_image() image2 = member_update.saveAndReturnObject(image2) share = owner.sf.getShareService() sid = self.create_share(share, objects=[image], experimenters=[member_obj]) self.assertAccess(owner, sid) self.assertAccess(member, sid) member_share = member.sf.getShareService() share_obj = member_share.getShare(sid) # Activation shouldn't be needed any more as we pass {'omero.share': <sid>} #member_share.activate(long(sid)) # And the member should be able to use omero.share:sid member_query = member.sf.getQueryService() try: rv = member.sf.getQueryService().find("Image", image.id.val, None) except omero.SecurityViolation, sv: pass
def testThumbs(self): # root session is root.sf uuid = self.root.sf.getAdminService().getEventContext().sessionUuid admin = self.root.sf.getAdminService() group1name = "private_%s" % uuid group2name = "read-only_%s" % uuid group3name = "collaborative_%s" % uuid ownerName = "owner_%s" % uuid user1name = "user1_%s" % uuid user2name = "user2_%s" % uuid ### create three users in 3 groups listOfGroups = list() listOfGroups.append(admin.lookupGroup( "user")) # all users need to be in 'user' group to do anything! #group1 - private new_gr1 = ExperimenterGroupI() new_gr1.name = rstring(group1name) p = PermissionsI('rw----') new_gr1.details.permissions = p gid = admin.createGroup(new_gr1) privateGroup = admin.getGroup(gid) self.assertEquals('rw----', str(privateGroup.details.permissions)) listOfGroups.append(privateGroup) #group2 - read-only new_gr2 = ExperimenterGroupI() new_gr2.name = rstring(group2name) p2 = PermissionsI('rwr---') new_gr2.details.permissions = p2 gid2 = admin.createGroup(new_gr2) readOnlyGroup = admin.getGroup(gid2) self.assertEquals('rwr---', str(readOnlyGroup.details.permissions)) listOfGroups.append(readOnlyGroup) #group3 - read-annotate new_gr3 = ExperimenterGroupI() new_gr3.name = rstring(group3name) p = PermissionsI('rwra--') new_gr3.details.permissions = p gid3 = admin.createGroup(new_gr3) collaborativeGroup = admin.getGroup(gid3) self.assertEquals('rwra--', str(collaborativeGroup.details.permissions)) listOfGroups.append(collaborativeGroup) #new user (group owner) owner = ExperimenterI() owner.omeName = rstring(ownerName) owner.firstName = rstring("Group") owner.lastName = rstring("Owner") owner.email = rstring("*****@*****.**") ownerId = admin.createExperimenterWithPassword(owner, rstring("ome"), privateGroup, listOfGroups) newOwner = admin.getExperimenter(ownerId) admin.setGroupOwner(privateGroup, newOwner) admin.setGroupOwner(readOnlyGroup, newOwner) admin.setGroupOwner(collaborativeGroup, newOwner) #new user1 new_exp = ExperimenterI() new_exp.omeName = rstring(user1name) new_exp.firstName = rstring("Will") new_exp.lastName = rstring("Moore") new_exp.email = rstring("*****@*****.**") eid = admin.createExperimenterWithPassword(new_exp, rstring("ome"), privateGroup, listOfGroups) #new user2 new_exp2 = ExperimenterI() new_exp2.omeName = rstring(user2name) new_exp2.firstName = rstring("User") new_exp2.lastName = rstring("Test2") new_exp2.email = rstring("*****@*****.**") eid2 = admin.createExperimenterWithPassword(new_exp2, rstring("ome"), privateGroup, listOfGroups) ## get users user1 = admin.getExperimenter(eid) user2 = admin.getExperimenter(eid2) ## login as user1 (into their default group) client_share1 = self.new_client(user=user1, password="******") print len(client_share1.sf.activeServices()) # create image in private group privateImageId = createTestImage(client_share1.sf) print len(client_share1.sf.activeServices()) self.getThumbnail( client_share1.sf, privateImageId ) # if we don't get thumbnail, test fails when another user does print len(client_share1.sf.activeServices()) # change user into read-only group. Use object Ids for this, NOT objects from a different context a = client_share1.sf.getAdminService() me = a.getExperimenter(a.getEventContext().userId) a.setDefaultGroup(me, omero.model.ExperimenterGroupI(gid2, False)) self.set_context(client_share1, gid2) #print a.getEventContext() # create image and get thumbnail (in read-only group) readOnlyImageId = createTestImage(client_share1.sf) self.getThumbnail(client_share1.sf, readOnlyImageId) # change user into collaborative group. Use object Ids for this, NOT objects from a different context a.setDefaultGroup(me, omero.model.ExperimenterGroupI(gid3, False)) self.set_context(client_share1, gid3) # create image and get thumbnail (in collaborative group) collaborativeImageId = createTestImage(client_share1.sf) self.getThumbnail(client_share1.sf, collaborativeImageId) # check that we can't get thumbnails for images in other groups self.assertEquals(None, self.getThumbnail(client_share1.sf, privateImageId)) self.assertEquals(None, self.getThumbnail(client_share1.sf, readOnlyImageId)) # now check that the 'owner' of each group can see all 3 thumbnails. ## login as owner (into private group) owner_client = self.new_client(user=newOwner, password="******") self.getThumbnail(owner_client.sf, privateImageId) # check that we can't get thumbnails for images in other groups self.assertEquals(None, self.getThumbnail(owner_client.sf, readOnlyImageId)) self.assertEquals( None, self.getThumbnail(owner_client.sf, collaborativeImageId)) # change owner into read-only group. o = client_share1.sf.getAdminService() me = o.getExperimenter(o.getEventContext().userId) o.setDefaultGroup(me, omero.model.ExperimenterGroupI(gid2, False)) self.set_context(owner_client, gid2) self.getThumbnail(owner_client.sf, readOnlyImageId) # check that we can't get thumbnails for images in other groups self.assertEquals(None, self.getThumbnail(owner_client.sf, privateImageId)) self.assertEquals( None, self.getThumbnail(owner_client.sf, collaborativeImageId)) # change owner into collaborative group. o.setDefaultGroup(me, omero.model.ExperimenterGroupI(gid3, False)) self.set_context(owner_client, gid3) self.getThumbnail(owner_client.sf, collaborativeImageId) # check that we can't get thumbnails for images in other groups self.assertEquals(None, self.getThumbnail(owner_client.sf, privateImageId)) self.assertEquals(None, self.getThumbnail(owner_client.sf, readOnlyImageId)) # now check that the 'user2' of each group can see all thumbnails except private. ## login as user2 (into private group) user2_client = self.new_client(user=user2, password="******") # check that we can't get thumbnails for any images in private group self.assertEquals(None, self.getThumbnail(user2_client.sf, privateImageId)) self.assertEquals(None, self.getThumbnail(user2_client.sf, readOnlyImageId)) self.assertEquals( None, self.getThumbnail(user2_client.sf, collaborativeImageId)) # change owner into read-only group. u = user2_client.sf.getAdminService() me = u.getExperimenter(u.getEventContext().userId) u.setDefaultGroup(me, omero.model.ExperimenterGroupI(gid2, False)) self.set_context(user2_client, gid2) self.getThumbnail(user2_client.sf, readOnlyImageId) # check that we can't get thumbnails for images in other groups self.assertEquals(None, self.getThumbnail(user2_client.sf, privateImageId)) self.assertEquals( None, self.getThumbnail(user2_client.sf, collaborativeImageId)) # change owner into collaborative group. u.setDefaultGroup(me, omero.model.ExperimenterGroupI(gid3, False)) self.set_context(user2_client, gid3) self.getThumbnail(user2_client.sf, collaborativeImageId) # check that we can't get thumbnails for images in other groups self.assertEquals(None, self.getThumbnail(user2_client.sf, privateImageId)) self.assertEquals(None, self.getThumbnail(user2_client.sf, readOnlyImageId))
def testThumbs(self): # root session is root.sf uuid = self.root.sf.getAdminService().getEventContext().sessionUuid admin = self.root.sf.getAdminService() group1name = "private_%s" % uuid group2name = "read-only_%s" % uuid group3name = "collaborative_%s" % uuid ownerName = "owner_%s" % uuid user1name = "user1_%s" % uuid user2name = "user2_%s" % uuid ### create three users in 3 groups listOfGroups = list() listOfGroups.append(admin.lookupGroup("user")) # all users need to be in 'user' group to do anything! #group1 - private new_gr1 = ExperimenterGroupI() new_gr1.name = rstring(group1name) p = PermissionsI('rw----') new_gr1.details.permissions = p gid = admin.createGroup(new_gr1) privateGroup = admin.getGroup(gid) self.assertEquals('rw----', str(privateGroup.details.permissions)) listOfGroups.append(privateGroup) #group2 - read-only new_gr2 = ExperimenterGroupI() new_gr2.name = rstring(group2name) p2 = PermissionsI('rwr---') new_gr2.details.permissions = p2 gid2 = admin.createGroup(new_gr2) readOnlyGroup = admin.getGroup(gid2) self.assertEquals('rwr---', str(readOnlyGroup.details.permissions)) listOfGroups.append(readOnlyGroup) #group3 - read-annotate new_gr3 = ExperimenterGroupI() new_gr3.name = rstring(group3name) p = PermissionsI('rwra--') new_gr3.details.permissions = p gid3 = admin.createGroup(new_gr3) collaborativeGroup = admin.getGroup(gid3) self.assertEquals('rwra--', str(collaborativeGroup.details.permissions)) listOfGroups.append(collaborativeGroup) #new user (group owner) owner = ExperimenterI() owner.omeName = rstring(ownerName) owner.firstName = rstring("Group") owner.lastName = rstring("Owner") owner.email = rstring("*****@*****.**") ownerId = admin.createExperimenterWithPassword(owner, rstring("ome"), privateGroup, listOfGroups) newOwner = admin.getExperimenter(ownerId) admin.setGroupOwner(privateGroup, newOwner) admin.setGroupOwner(readOnlyGroup, newOwner) admin.setGroupOwner(collaborativeGroup, newOwner) #new user1 new_exp = ExperimenterI() new_exp.omeName = rstring(user1name) new_exp.firstName = rstring("Will") new_exp.lastName = rstring("Moore") new_exp.email = rstring("*****@*****.**") eid = admin.createExperimenterWithPassword(new_exp, rstring("ome"), privateGroup, listOfGroups) #new user2 new_exp2 = ExperimenterI() new_exp2.omeName = rstring(user2name) new_exp2.firstName = rstring("User") new_exp2.lastName = rstring("Test2") new_exp2.email = rstring("*****@*****.**") eid2 = admin.createExperimenterWithPassword(new_exp2, rstring("ome"), privateGroup, listOfGroups) ## get users user1 = admin.getExperimenter(eid) user2 = admin.getExperimenter(eid2) ## login as user1 (into their default group) client_share1 = self.new_client(user=user1, password="******") print len(client_share1.sf.activeServices()) # create image in private group privateImageId = createTestImage(client_share1.sf) print len(client_share1.sf.activeServices()) self.getThumbnail(client_share1.sf, privateImageId) # if we don't get thumbnail, test fails when another user does print len(client_share1.sf.activeServices()) # change user into read-only group. Use object Ids for this, NOT objects from a different context a = client_share1.sf.getAdminService() me = a.getExperimenter(a.getEventContext().userId) a.setDefaultGroup(me, omero.model.ExperimenterGroupI(gid2, False)) self.set_context(client_share1, gid2) #print a.getEventContext() # create image and get thumbnail (in read-only group) readOnlyImageId = createTestImage(client_share1.sf) self.getThumbnail(client_share1.sf, readOnlyImageId) # change user into collaborative group. Use object Ids for this, NOT objects from a different context a.setDefaultGroup(me, omero.model.ExperimenterGroupI(gid3, False)) self.set_context(client_share1, gid3) # create image and get thumbnail (in collaborative group) collaborativeImageId = createTestImage(client_share1.sf) self.getThumbnail(client_share1.sf, collaborativeImageId) # check that we can't get thumbnails for images in other groups self.assertEquals(None, self.getThumbnail(client_share1.sf, privateImageId)) self.assertEquals(None, self.getThumbnail(client_share1.sf, readOnlyImageId)) # now check that the 'owner' of each group can see all 3 thumbnails. ## login as owner (into private group) owner_client = self.new_client(user=newOwner, password="******") self.getThumbnail(owner_client.sf, privateImageId) # check that we can't get thumbnails for images in other groups self.assertEquals(None, self.getThumbnail(owner_client.sf, readOnlyImageId)) self.assertEquals(None, self.getThumbnail(owner_client.sf, collaborativeImageId)) # change owner into read-only group. o = client_share1.sf.getAdminService() me = o.getExperimenter(o.getEventContext().userId) o.setDefaultGroup(me, omero.model.ExperimenterGroupI(gid2, False)) self.set_context(owner_client, gid2) self.getThumbnail(owner_client.sf, readOnlyImageId) # check that we can't get thumbnails for images in other groups self.assertEquals(None, self.getThumbnail(owner_client.sf, privateImageId)) self.assertEquals(None, self.getThumbnail(owner_client.sf, collaborativeImageId)) # change owner into collaborative group. o.setDefaultGroup(me, omero.model.ExperimenterGroupI(gid3, False)) self.set_context(owner_client, gid3) self.getThumbnail(owner_client.sf, collaborativeImageId) # check that we can't get thumbnails for images in other groups self.assertEquals(None, self.getThumbnail(owner_client.sf, privateImageId)) self.assertEquals(None, self.getThumbnail(owner_client.sf, readOnlyImageId)) # now check that the 'user2' of each group can see all thumbnails except private. ## login as user2 (into private group) user2_client = self.new_client(user=user2, password="******") # check that we can't get thumbnails for any images in private group self.assertEquals(None, self.getThumbnail(user2_client.sf, privateImageId)) self.assertEquals(None, self.getThumbnail(user2_client.sf, readOnlyImageId)) self.assertEquals(None, self.getThumbnail(user2_client.sf, collaborativeImageId)) # change owner into read-only group. u = user2_client.sf.getAdminService() me = u.getExperimenter(u.getEventContext().userId) u.setDefaultGroup(me, omero.model.ExperimenterGroupI(gid2, False)) self.set_context(user2_client, gid2) self.getThumbnail(user2_client.sf, readOnlyImageId) # check that we can't get thumbnails for images in other groups self.assertEquals(None, self.getThumbnail(user2_client.sf, privateImageId)) self.assertEquals(None, self.getThumbnail(user2_client.sf, collaborativeImageId)) # change owner into collaborative group. u.setDefaultGroup(me, omero.model.ExperimenterGroupI(gid3, False)) self.set_context(user2_client, gid3) self.getThumbnail(user2_client.sf, collaborativeImageId) # check that we can't get thumbnails for images in other groups self.assertEquals(None, self.getThumbnail(user2_client.sf, privateImageId)) self.assertEquals(None, self.getThumbnail(user2_client.sf, readOnlyImageId))