示例#1
0
def testFileAnnotation(author_testimg_generated, gatewaywrapper):
    """ Creates a file annotation from a local file """
    tempFileName = "tempFile"
    f = open(tempFileName, "w")
    fileText = "Test text for writing to file for upload"
    f.write(fileText)
    f.close()
    fileSize = os.path.getsize(tempFileName)
    ns = TESTANN_NS
    image = author_testimg_generated

    # use the same file to create various file annotations with different namespaces
    fileAnn = gatewaywrapper.gateway.createFileAnnfromLocalFile(tempFileName, mimetype="text/plain", ns=ns)
    image.linkAnnotation(fileAnn)
    compAnn = gatewaywrapper.gateway.createFileAnnfromLocalFile(
        tempFileName, mimetype="text/plain", ns=omero.constants.namespaces.NSCOMPANIONFILE
    )
    image.linkAnnotation(compAnn)
    os.remove(tempFileName)

    # get user-id of another user to use below.
    gatewaywrapper.loginAsAdmin()
    adminId = gatewaywrapper.gateway.getUser().getId()
    gatewaywrapper.loginAsAuthor()

    # test listing of File Annotations. Should exclude companion files by default and all files should be loaded
    gateway = gatewaywrapper.gateway
    eid = gateway.getUser().getId()
    fas = list(gateway.listFileAnnotations(eid=eid, toInclude=[ns]))
    faIds = [fa.id for fa in fas]
    assert fileAnn.getId() in faIds
    assert compAnn.getId() not in faIds
    for fa in fas:
        assert fa.getNs() == ns, "All files should be filtered by this namespace"
        assert fa._obj.file.loaded, "All file annotations should have files loaded"

    # filtering by namespace
    fas = list(gateway.listFileAnnotations(toInclude=["nothing.with.this.namespace"], eid=eid))
    assert len(fas) == 0, "No file annotations should exist with bogus namespace"

    # filtering files by a different user should not return the annotations above.
    fas = list(gateway.listFileAnnotations(eid=adminId))
    faIds = [fa.id for fa in fas]
    assert fileAnn.getId() not in faIds
    assert compAnn.getId() not in faIds

    image._conn = gatewaywrapper.gateway  # needs a fresh connection, original was closed already
    ann = image.getAnnotation(ns)
    annId = ann.getId()
    assert ann.OMERO_TYPE == omero.model.FileAnnotationI
    for t in ann.getFileInChunks():
        assert str(t) == fileText  # we get whole text in one chunk

    # delete what we created
    assert gateway.getObject("Annotation", annId) is not None
    link = ann.link
    gateway.deleteObjectDirect(link._obj)  # delete link
    gateway.deleteObjectDirect(ann._obj)  # then the annotation
    gateway.deleteObjectDirect(ann._obj.file)  # then the file
    assert gateway.getObject("Annotation", annId) is None
示例#2
0
    def test9655(self):
        # Create an image without statsinfo objects and attempt
        # to retrieve it from the Rendering service.

        # Get the pixels
        image_id = self.testCreateImage()
        gateway = omero.gateway.BlitzGateway(client_obj=self.client)
        image = gateway.getObject("Image", image_id)
        pixels_id = image.getPrimaryPixels().id

        # Save the pixels
        rps = self.client.sf.createRawPixelsStore()
        rps.setPixelsId(pixels_id, False)
        rps.setPlane([0], 0, 0, 0)
        rps.save()
        rps.close()

        # Now use the RE to load
        re = self.client.sf.createRenderingEngine()
        re.lookupPixels(pixels_id)
        re.resetDefaults()
        re.lookupPixels(pixels_id)
        re.lookupRenderingDef(pixels_id)
        re.getPixels()
    def test9655(self):
        # Create an image without statsinfo objects and attempt
        # to retrieve it from the Rendering service.

        # Get the pixels
        image_id = self.testCreateImage()
        gateway = omero.gateway.BlitzGateway(client_obj=self.client)
        image = gateway.getObject("Image", image_id)
        pixels_id = image.getPrimaryPixels().id

        # Save the pixels
        rps = self.client.sf.createRawPixelsStore()
        rps.setPixelsId(pixels_id, False)
        rps.setPlane([0], 0, 0, 0)
        rps.save()
        rps.close()

        # Now use the RE to load
        re = self.client.sf.createRenderingEngine()
        re.lookupPixels(pixels_id)
        re.resetDefaults()
        re.lookupPixels(pixels_id)
        re.lookupRenderingDef(pixels_id)
        re.getPixels()
示例#4
0
def testFileAnnotation(author_testimg_generated, gatewaywrapper):
    """ Creates a file annotation from a local file """
    tempFileName = "tempFile"
    f = open(tempFileName, 'w')
    fileText = "Test text for writing to file for upload"
    f.write(fileText)
    f.close()
    ns = TESTANN_NS
    image = author_testimg_generated

    # use the same file to create various file annotations with different
    # namespaces
    fileAnn = gatewaywrapper.gateway.createFileAnnfromLocalFile(
        tempFileName, mimetype='text/plain', ns=ns)
    image.linkAnnotation(fileAnn)
    compAnn = gatewaywrapper.gateway.createFileAnnfromLocalFile(
        tempFileName,
        mimetype='text/plain',
        ns=omero.constants.namespaces.NSCOMPANIONFILE)
    image.linkAnnotation(compAnn)
    os.remove(tempFileName)

    # get user-id of another user to use below.
    gatewaywrapper.loginAsAdmin()
    adminId = gatewaywrapper.gateway.getUser().getId()
    gatewaywrapper.loginAsAuthor()

    # test listing of File Annotations. Should exclude companion files by
    # default and all files should be loaded
    gateway = gatewaywrapper.gateway
    eid = gateway.getUser().getId()
    fas = list(gateway.listFileAnnotations(eid=eid, toInclude=[ns]))
    faIds = [fa.id for fa in fas]
    assert fileAnn.getId() in faIds
    assert compAnn.getId() not in faIds
    for fa in fas:
        assert fa.getNs() == ns, \
            "All files should be filtered by this namespace"
        assert fa._obj.file.loaded, \
            "All file annotations should have files loaded"

    # filtering by namespace
    fas = list(
        gateway.listFileAnnotations(toInclude=["nothing.with.this.namespace"],
                                    eid=eid))
    assert len(fas) == 0, \
        "No file annotations should exist with bogus namespace"

    # filtering files by a different user should not return the annotations
    # above.
    fas = list(gateway.listFileAnnotations(eid=adminId))
    faIds = [fa.id for fa in fas]
    assert fileAnn.getId() not in faIds
    assert compAnn.getId() not in faIds

    # needs a fresh connection, original was closed already
    image._conn = gatewaywrapper.gateway
    ann = image.getAnnotation(ns)
    annId = ann.getId()
    assert ann.OMERO_TYPE == omero.model.FileAnnotationI
    for t in ann.getFileInChunks():
        assert str(t) == fileText  # we get whole text in one chunk

    # delete what we created
    assert gateway.getObject("Annotation", annId) is not None
    link = ann.link
    gateway.deleteObjectDirect(link._obj)  # delete link
    gateway.deleteObjectDirect(ann._obj)  # then the annotation
    gateway.deleteObjectDirect(ann._obj.file)  # then the file
    assert gateway.getObject("Annotation", annId) is None