Пример #1
0
    def testChgrpImage(self):
        """
        Tests chgrp for a dummny image object (no Pixels)
        """
        # One user in two groups
        client, exp = self.new_client_and_user()
        grp = self.new_group([exp])
        gid = grp.id.val
        client.sf.getAdminService().getEventContext()  # Reset session
        update = client.sf.getUpdateService()
        query = client.sf.getQueryService()
        admin = client.sf.getAdminService()
        first_gid = admin.getEventContext().groupId

        # Create a dataset in the 'first group'
        ds = omero.model.DatasetI()
        ds.name = rstring("testChgrpImage_target")
        ds = update.saveAndReturnObject(ds)
        ds_id = ds.id.val

        # Change our context to new group and create image
        admin.setDefaultGroup(exp, omero.model.ExperimenterGroupI(gid, False))
        self.set_context(client, gid)
        update = client.sf.getUpdateService()  # do we need to get this again?
        img = self.new_image()
        img = update.saveAndReturnObject(img)

        # Move image to new group
        chgrp = omero.cmd.Chgrp(type="/Image",
                                id=img.id.val,
                                options=None,
                                grp=first_gid)

        # Link to Save
        link = omero.model.DatasetImageLinkI()
        link.child = omero.model.ImageI(img.id.val, False)
        link.parent = omero.model.DatasetI(ds_id, False)
        save = Save()
        save.obj = link
        requests = [chgrp, save]  # we're going to chgrp THEN save DIlink

        # Change our context to original group...
        admin.setDefaultGroup(exp,
                              omero.model.ExperimenterGroupI(first_gid, False))
        self.set_context(client, first_gid)

        # We have to be in destination group for link Save to work
        self.doAllChgrp(requests, client)

        # ...check image
        img = client.sf.getQueryService().get("Image", img.id.val)
        self.assertEqual(img.details.group.id.val, first_gid)
        # check Dataset
        query = "select link from DatasetImageLink link where link.child.id=%s" % img.id.val
        l = client.sf.getQueryService().findByQuery(query, None)
        self.assertTrue(l is not None,
                        "New DatasetImageLink on image not found")
        self.assertEqual(l.details.group.id.val, first_gid,
                         "Link Created in same group as Image target")
Пример #2
0
    def testChgrpImage(self):
        """
        Tests chgrp for a dummny image object (no Pixels)
        """
        # One user in two groups
        client, exp = self.new_client_and_user()
        grp = self.new_group([exp])
        gid = grp.id.val
        client.sf.getAdminService().getEventContext()  # Reset session
        update = client.sf.getUpdateService()
        query = client.sf.getQueryService()
        admin = client.sf.getAdminService()
        first_gid = admin.getEventContext().groupId

        # Create a dataset in the 'first group'
        ds = omero.model.DatasetI()
        ds.name = rstring("testChgrpImage_target")
        ds = update.saveAndReturnObject(ds)
        ds_id = ds.id.val

        # Change our context to new group and create image
        admin.setDefaultGroup(exp, omero.model.ExperimenterGroupI(gid, False))
        self.set_context(client, gid)
        update = client.sf.getUpdateService()  # do we need to get this again?
        img = self.new_image()
        img = update.saveAndReturnObject(img)

        # Move image to new group
        chgrp = omero.cmd.Chgrp(type="/Image", id=img.id.val, options=None, grp=first_gid)

        # Link to Save
        link = omero.model.DatasetImageLinkI()
        link.child = omero.model.ImageI(img.id.val, False)
        link.parent = omero.model.DatasetI(ds_id, False)
        save = Save()
        save.obj = link
        requests = [chgrp, save]  # we're going to chgrp THEN save DIlink

        # Change our context to original group...
        admin.setDefaultGroup(exp, omero.model.ExperimenterGroupI(first_gid, False))
        self.set_context(client, first_gid)

        # We have to be in destination group for link Save to work
        self.doAllSubmit(requests, client)

        # ...check image
        img = client.sf.getQueryService().get("Image", img.id.val)
        assert img.details.group.id.val == first_gid
        # check Dataset
        query = (
            "select link from DatasetImageLink link\
            where link.child.id=%s"
            % img.id.val
        )
        l = client.sf.getQueryService().findByQuery(query, None)
        assert l is not None, "New DatasetImageLink on image not found"
        assert l.details.group.id.val == first_gid, "Link Created in same group as Image target"
Пример #3
0
    def testChgrpImage(self):
        """
        Tests chgrp for a dummny image object (no Pixels)
        """
        # One user in two groups
        client, exp = self.new_client_and_user()
        grp = self.new_group([exp])
        gid = grp.id.val
        client.sf.getAdminService().getEventContext()  # Reset session
        update = client.sf.getUpdateService()
        query = client.sf.getQueryService()
        admin = client.sf.getAdminService()
        first_gid = admin.getEventContext().groupId

        # Create a dataset in the 'first group'
        ds = self.make_dataset(name="testChgrpImage_target", client=client)
        ds_id = ds.id.val

        # Change our context to new group and create image
        admin.setDefaultGroup(exp, ExperimenterGroupI(gid, False))
        self.set_context(client, gid)
        update = client.sf.getUpdateService()  # do we need to get this again?
        img = self.new_image()
        img = update.saveAndReturnObject(img)

        # Move image to new group
        chgrp = Chgrp2(targetObjects={'Image': [img.id.val]},
                       groupId=first_gid)

        # Link to Save
        link = DatasetImageLinkI()
        link.child = ImageI(img.id.val, False)
        link.parent = DatasetI(ds_id, False)
        save = Save()
        save.obj = link
        requests = [chgrp, save]  # we're going to chgrp THEN save DIlink

        # Change our context to original group...
        admin.setDefaultGroup(exp, ExperimenterGroupI(first_gid, False))
        self.set_context(client, first_gid)

        # We have to be in destination group for link Save to work
        self.doSubmit(requests, client)

        # ...check image
        img = client.sf.getQueryService().get("Image", img.id.val)
        assert img.details.group.id.val == first_gid
        # check Dataset
        query = "select link from DatasetImageLink link\
            where link.child.id=%s" % img.id.val
        l = client.sf.getQueryService().findByQuery(query, None)
        assert l is not None, "New DatasetImageLink on image not found"
        assert l.details.group.id.val == first_gid,\
            "Link Created in same group as Image target"
Пример #4
0
    def testChgrpDatasetToTargetProject(self, credentials):
        """
        Tests that an Admin can move a user's Dataset to a private
        group and link it to an existing user's Project there.
        Also tests that the user can do the same chgrp themselves.
        """

        # One user in two groups
        client, user = self.new_client_and_user(perms=PRIVATE)
        target_grp = self.new_group([user], perms=PRIVATE)
        eCtx = client.sf.getAdminService().getEventContext()  # Reset session
        userId = eCtx.userId
        target_gid = target_grp.id.val

        # User creates Dataset in current group...
        update = client.sf.getUpdateService()
        ds = self.make_dataset(client=client)
        # ...and Project in target group
        ctx = {'omero.group': str(target_gid)}
        pr = self.new_project()
        pr = update.saveAndReturnObject(pr, ctx)

        requests = []
        saves = []
        chgrp = Chgrp2(
            targetObjects={"Dataset": [ds.id.val]}, groupId=target_gid)
        requests.append(chgrp)
        link = ProjectDatasetLinkI()
        link.details.owner = ExperimenterI(userId, False)
        link.child = DatasetI(ds.id.val, False)
        link.parent = ProjectI(pr.id.val, False)
        save = Save()
        save.obj = link
        saves.append(save)
        requests.extend(saves)

        if credentials == "user":
            c = client
        else:
            c = self.root
        self.doSubmit(requests, c, omero_group=target_gid)

        queryService = client.sf.getQueryService()
        ctx = {'omero.group': '-1'}  # query across groups
        dataset = queryService.get('Dataset', ds.id.val, ctx)
        ds_gid = dataset.details.group.id.val
        assert target_gid == ds_gid,\
            "Dataset should be in group: %s, NOT %s" % (target_gid, ds_gid)
Пример #5
0
    def testChgrpDatasetToTargetProject(self, credentials):
        """
        Tests that an Admin can move a user's Dataset to a private
        group and link it to an existing user's Project there.
        Also tests that the user can do the same chgrp themselves.
        """

        # One user in two groups
        client, user = self.new_client_and_user(perms=PRIVATE)
        target_grp = self.new_group([user], perms=PRIVATE)
        eCtx = client.sf.getAdminService().getEventContext()  # Reset session
        userId = eCtx.userId
        target_gid = target_grp.id.val

        # User creates Dataset in current group...
        update = client.sf.getUpdateService()
        ds = self.make_dataset(client=client)
        # ...and Project in target group
        ctx = {'omero.group': str(target_gid)}
        pr = self.new_project()
        pr = update.saveAndReturnObject(pr, ctx)

        requests = []
        saves = []
        chgrp = Chgrp2(targetObjects={"Dataset": [ds.id.val]},
                       groupId=target_gid)
        requests.append(chgrp)
        link = ProjectDatasetLinkI()
        link.details.owner = ExperimenterI(userId, False)
        link.child = DatasetI(ds.id.val, False)
        link.parent = ProjectI(pr.id.val, False)
        save = Save()
        save.obj = link
        saves.append(save)
        requests.extend(saves)

        if credentials == "user":
            c = client
        else:
            c = self.root
        self.doSubmit(requests, c, omero_group=target_gid)

        queryService = client.sf.getQueryService()
        ctx = {'omero.group': '-1'}  # query across groups
        dataset = queryService.get('Dataset', ds.id.val, ctx)
        ds_gid = dataset.details.group.id.val
        assert target_gid == ds_gid,\
            "Dataset should be in group: %s, NOT %s" % (target_gid, ds_gid)
Пример #6
0
    def chgrpImagesToTargetDataset(self, imgCount):
        """
        Helper method to test chgrp of image(s) to target Dataset
        """
        # One user in two groups
        client, user = self.new_client_and_user(perms=PRIVATE)
        admin = client.sf.getAdminService()
        target_grp = self.new_group([user], perms=PRIVATE)
        target_gid = target_grp.id.val

        images = self.importMIF(imgCount, client=client)
        ds = self.createDSInGroup(target_gid, client=client)

        # each chgrp includes a 'save' link to target dataset
        saves = []
        ids = []
        for i in images:
            ids.append(i.id.val)
            link = DatasetImageLinkI()
            link.child = ImageI(i.id.val, False)
            link.parent = DatasetI(ds.id.val, False)
            save = Save()
            save.obj = link
            saves.append(save)
        chgrp = Chgrp2(
            targetObjects={"Image": ids}, groupId=target_gid)
        requests = [chgrp]
        requests.extend(saves)
        self.doSubmit(requests, client, omero_group=target_gid)

        # Check Images moved to correct group
        queryService = client.sf.getQueryService()
        ctx = {'omero.group': '-1'}  # query across groups
        for i in images:
            image = queryService.get('Image', i.id.val, ctx)
            img_gid = image.details.group.id.val
            assert target_gid == img_gid,\
                "Image should be in group: %s, NOT %s" % (target_gid,  img_gid)
        # Check Dataset has images linked
        dsImgs = client.sf.getContainerService().getImages(
            'Dataset', [ds.id.val], None, ctx)
        assert len(dsImgs) == len(images),\
            "All Images should be in target Dataset"

        previous_gid = admin.getEventContext().groupId
        return (ds, images, client, user, previous_gid, target_gid)
Пример #7
0
    def chgrpImagesToTargetDataset(self, imgCount):
        """
        Helper method to test chgrp of image(s) to target Dataset
        """
        # One user in two groups
        client, user = self.new_client_and_user(perms=PRIVATE)
        admin = client.sf.getAdminService()
        target_grp = self.new_group([user], perms=PRIVATE)
        target_gid = target_grp.id.val

        images = self.importMIF(imgCount, client=client)
        ds = self.createDSInGroup(target_gid, client=client)

        # each chgrp includes a 'save' link to target dataset
        saves = []
        ids = []
        for i in images:
            ids.append(i.id.val)
            link = DatasetImageLinkI()
            link.child = ImageI(i.id.val, False)
            link.parent = DatasetI(ds.id.val, False)
            save = Save()
            save.obj = link
            saves.append(save)
        chgrp = Chgrp2(targetObjects={"Image": ids}, groupId=target_gid)
        requests = [chgrp]
        requests.extend(saves)
        self.doSubmit(requests, client, omero_group=target_gid)

        # Check Images moved to correct group
        queryService = client.sf.getQueryService()
        ctx = {'omero.group': '-1'}  # query across groups
        for i in images:
            image = queryService.get('Image', i.id.val, ctx)
            img_gid = image.details.group.id.val
            assert target_gid == img_gid,\
                "Image should be in group: %s, NOT %s" % (target_gid,  img_gid)
        # Check Dataset has images linked
        dsImgs = client.sf.getContainerService().getImages(
            'Dataset', [ds.id.val], None, ctx)
        assert len(dsImgs) == len(images),\
            "All Images should be in target Dataset"

        previous_gid = admin.getEventContext().groupId
        return (ds, images, client, user, previous_gid, target_gid)