def test_create(self):
        ownerid = 123
        session = MockSession(None, None, ownerid)
        fs = MockFeatureTable(None)
        self.mox.StubOutWithMock(OmeroTablesFeatureStore, 'list_tables')
        self.mox.StubOutWithMock(OmeroTablesFeatureStore, 'new_table')
        fsname = 'fsname'
        meta = [('Float', 'f')]
        colnames = ['x1', 'x2']

        OmeroTablesFeatureStore.list_tables(session,
                                            fsname,
                                            'x/features',
                                            ownerid=ownerid).AndReturn([])

        OmeroTablesFeatureStore.new_table(session, fsname, 'x/features',
                                          'x/source', meta,
                                          colnames).AndReturn(fs)

        self.mox.ReplayAll()

        fts = OmeroTablesFeatureStore.FeatureTableManager(session,
                                                          namespace='x')
        assert fts.create(fsname, meta, colnames) == fs

        assert len(fts.fss) == 1
        assert fts.fss.get((fsname, ownerid)) == fs

        self.mox.VerifyAll()
    def test_new_table(self, parent):
        tcols, meta, ftnames = TableStoreHelper.get_columns(
            [2], 'multi', False)

        if parent:
            iid = unwrap(TableStoreHelper.create_image(self.sess).getId())
            store = OmeroTablesFeatureStore.new_table(
                self.sess, self.name, self.ft_space, self.ann_space,
                meta, ftnames, 'Image:%d' % iid)
        else:
            store = OmeroTablesFeatureStore.new_table(
                self.sess, self.name, self.ft_space, self.ann_space,
                meta, ftnames)

        assert store.table
        TableStoreHelper.assert_coltypes_equal(store.cols, tcols)

        if parent:
            tid = unwrap(store.get_table().getOriginalFile().getId())
            q = ('SELECT link.child FROM ImageAnnotationLink link '
                 'WHERE link.parent.id=:id')
            p = omero.sys.ParametersI()
            p.addId(iid)
            r = self.sess.getQueryService().findAllByQuery(q, p)
            assert len(r) == 1
            assert isinstance(r[0], omero.model.FileAnnotation)
            assert unwrap(r[0].getFile().getId()) == tid

        store.close()
    def test_new_table(self, parent):
        tcols, meta, ftnames = TableStoreHelper.get_columns([2], "multi", False)

        if parent:
            iid = unwrap(TableStoreHelper.create_image(self.sess).getId())
            store = OmeroTablesFeatureStore.new_table(
                self.sess, self.name, self.ft_space, self.ann_space, meta, ftnames, "Image:%d" % iid
            )
        else:
            store = OmeroTablesFeatureStore.new_table(
                self.sess, self.name, self.ft_space, self.ann_space, meta, ftnames
            )

        assert store.table
        TableStoreHelper.assert_coltypes_equal(store.cols, tcols)

        if parent:
            tid = unwrap(store.get_table().getOriginalFile().getId())
            q = "SELECT link.child FROM ImageAnnotationLink link " "WHERE link.parent.id=:id"
            p = omero.sys.ParametersI()
            p.addId(iid)
            r = self.sess.getQueryService().findAllByQuery(q, p)
            assert len(r) == 1
            assert isinstance(r[0], omero.model.FileAnnotation)
            assert unwrap(r[0].getFile().getId()) == tid

        store.close()
    def test_create(self):
        ownerid = 123
        session = MockSession(None, None, ownerid)
        fs = MockFeatureTable(None)
        self.mox.StubOutWithMock(OmeroTablesFeatureStore, 'list_tables')
        self.mox.StubOutWithMock(OmeroTablesFeatureStore, 'new_table')
        fsname = 'fsname'
        meta = [('Float', 'f')]
        colnames = ['x1', 'x2']

        OmeroTablesFeatureStore.list_tables(
            session, fsname, 'x/features', ownerid=ownerid).AndReturn([])

        OmeroTablesFeatureStore.new_table(
            session, fsname, 'x/features', 'x/source', meta, colnames
            ).AndReturn(fs)

        self.mox.ReplayAll()

        fts = OmeroTablesFeatureStore.FeatureTableManager(
            session, namespace='x')
        assert fts.create(fsname, meta, colnames) == fs

        assert len(fts.fss) == 1
        assert fts.fss.get((fsname, ownerid)) == fs

        self.mox.VerifyAll()
    def setup_tables_for_list(self):
        tcols, meta, ftnames = TableStoreHelper.get_columns([2], "multi", False)

        iid = unwrap(TableStoreHelper.create_image(self.sess).getId())
        store1 = OmeroTablesFeatureStore.new_table(
            self.sess, "name-1", "ft_space-12", "ann_space-1", meta, ftnames, "Image:%s" % iid
        )
        store2 = OmeroTablesFeatureStore.new_table(self.sess, "name-2", "ft_space-12", "ann_space-2", meta, ftnames)

        r1 = (self.get_table_id(store1), "name-1", "ft_space-12", "ann_space-1")
        r2 = (self.get_table_id(store2), "name-2", "ft_space-12", "ann_space-2")

        store1.close()
        store2.close()

        return r1, r2, iid
    def setup_tables_for_list(self):
        tcols, meta, ftnames = TableStoreHelper.get_columns(
            [2], 'multi', False)

        iid = unwrap(TableStoreHelper.create_image(self.sess).getId())
        store1 = OmeroTablesFeatureStore.new_table(
            self.sess, 'name-1', 'ft_space-12', 'ann_space-1', meta, ftnames,
            'Image:%s' % iid)
        store2 = OmeroTablesFeatureStore.new_table(
            self.sess, 'name-2', 'ft_space-12', 'ann_space-2', meta, ftnames)

        r1 = (self.get_table_id(store1),
              'name-1', 'ft_space-12', 'ann_space-1')
        r2 = (self.get_table_id(store2),
              'name-2', 'ft_space-12', 'ann_space-2')

        store1.close()
        store2.close()

        return r1, r2, iid