Example #1
0
    def test_crud(self):
        from clld.db.migration import Connection

        migration = Connection(DBSession)

        assert len(list(migration.select(common.Identifier))) == 0
        pk = migration.insert(
            common.Identifier,
            id='iso-csw', name='csw', type=common.IdentifierType.iso.value)
        assert migration.pk(common.Identifier, 'iso-csw') == pk
        assert len(list(migration.select(common.Identifier))) == 1

        identifier = DBSession.query(common.Identifier)\
            .options(undefer('*')).get(pk)
        assert identifier.active
        assert identifier.version == 1
        assert identifier.created
        assert identifier.updated

        migration.update(common.Identifier, [('name', 'cea')], pk=pk)
        DBSession.refresh(identifier)
        assert identifier.name == 'cea'

        migration.delete(common.Identifier, pk=pk)
        self.assertRaises(InvalidRequestError, DBSession.refresh, identifier)
Example #2
0
def test_crud(db):
    migration = Connection(DBSession)

    assert len(list(migration.select(common.Identifier))) == 0
    pk = migration.insert(common.Identifier,
                          id='iso-csw',
                          name='csw',
                          type=common.IdentifierType.iso.value)
    assert migration.pk(common.Identifier, 'iso-csw') == pk
    assert len(list(migration.select(common.Identifier))) == 1

    identifier = DBSession.query(common.Identifier)\
        .options(undefer('*')).get(pk)
    assert identifier.active
    assert identifier.version == 1
    assert identifier.created
    assert identifier.updated

    migration.update(common.Identifier, [('name', 'cea')], pk=pk)
    DBSession.refresh(identifier)
    assert identifier.name == 'cea'

    migration.delete(common.Identifier, pk=pk)
    with pytest.raises(InvalidRequestError):
        DBSession.refresh(identifier)
Example #3
0
    def test_crud(self):
        from clld.db.migration import Connection

        migration = Connection(DBSession)

        assert len(list(migration.select(common.Identifier))) == 0
        pk = migration.insert(common.Identifier,
                              id='iso-csw',
                              name='csw',
                              type=common.IdentifierType.iso.value)
        assert migration.pk(common.Identifier, 'iso-csw') == pk
        assert len(list(migration.select(common.Identifier))) == 1

        identifier = DBSession.query(common.Identifier).get(pk)
        assert identifier.active
        assert identifier.version == 1
        assert identifier.created
        assert identifier.updated

        migration.update(common.Identifier, [('name', 'cea')], pk=pk)
        DBSession.refresh(identifier)
        assert identifier.name == 'cea'

        migration.delete(common.Identifier, pk=pk)
        self.assertRaises(InvalidRequestError, DBSession.refresh, identifier)
Example #4
0
def upgrade():
    conn = Connection(op.get_bind())
    lpk = conn.pk(Language, 'jiar1239')
    for lid in list(conn.select(LanguageIdentifier, language_pk=lpk)):
        id_ = list(conn.select(Identifier, pk=lid.identifier_pk))[0]
        if id_.type == 'iso639-3':
            conn.delete(LanguageIdentifier, pk=lid.pk)
            conn.delete(Identifier, pk=id_.pk)
def upgrade():
    conn = Connection(op.get_bind())
    for fid, lid, sid in VALUESETREFERENCES:
        vs = conn.pk(ValueSet, '%s-%s' % (fid, lid))
        s = conn.pk(Source, sid)
        conn.update(ValueSetReference, dict(source_pk=s), valueset_pk=vs, source_pk=None)

    assert not list(conn.select(ValueSetReference, source_pk=None))
Example #6
0
def upgrade():
    conn = Connection(op.get_bind())
    for fid, lid, sid in VALUESETREFERENCES:
        vs = conn.pk(ValueSet, '%s-%s' % (fid, lid))
        s = conn.pk(Source, sid)
        conn.update(ValueSetReference,
                    dict(source_pk=s),
                    valueset_pk=vs,
                    source_pk=None)

    assert not list(conn.select(ValueSetReference, source_pk=None))