Ejemplo n.º 1
0
def unfreeze_func(args, engine=None):
    try:
        importlib.import_module(args.module.__name__)
    except ImportError:
        pass  # pragma: no cover
    engine = engine or DBSession.get_bind()
    data_dir = Path(mkdtemp())

    with ZipFile(as_posix(args.module_dir.joinpath('..', 'data.zip'))) as fp:
        fp.extractall(as_posix(data_dir))

    db_version = None
    for table in Base.metadata.sorted_tables:
        csv = data_dir.joinpath('%s.csv' % table.name)
        if csv.exists():
            db_version = load(table, csv, engine)

    if db_version:
        set_alembic_version(engine, db_version)

    rmtree(data_dir)
Ejemplo n.º 2
0
def unfreeze_func(args, engine=None):
    try:
        importlib.import_module(args.module.__name__)
    except ImportError:
        pass  # pragma: no cover
    engine = engine or DBSession.get_bind()
    data_dir = Path(mkdtemp())

    with ZipFile(as_posix(args.module_dir.joinpath('..', 'data.zip'))) as fp:
        fp.extractall(as_posix(data_dir))

    db_version = None
    for table in Base.metadata.sorted_tables:
        csv = data_dir.joinpath('%s.csv' % table.name)
        if csv.exists():
            db_version = load(table, csv, engine)

    if db_version:
        set_alembic_version(engine, db_version)  # pragma: no cover

    rmtree(data_dir)
Ejemplo n.º 3
0
def test_alembic_version(db):
    from clld.db.util import set_alembic_version, get_alembic_version

    assert get_alembic_version(db) != '1234'
    set_alembic_version(db, '1234')
    assert get_alembic_version(db) == '1234'
Ejemplo n.º 4
0
def populate_test_db(engine):
    set_alembic_version(engine, '58559d4eea0d')

    data = TestData()
    data.add_default(
        cm.Dataset,
        domain='clld',
        jsondata={'license_icon': 'cc-by', 'license_url': 'http://example.org'})

    data.add_default(cm.Contributor, name='A Name', email='*****@*****.**')
    for id_, name in {
            'b': 'b Name',
            'c': 'c Name',
            'd': 'd Name'}.items():
        data.add(cm.Contributor, id_, id=id_, name=name, url='http://example.org')

    DBSession.add(
        cm.Editor(dataset=data[cm.Dataset], contributor=data[cm.Contributor]))

    data.add_default(cm.Source)
    data.add(
        cm.Source,
        'replaced',
        id='replaced',
        active=False,
        jsondata={'__replacement_id__': 'source'})

    data.add_default(cm.Contribution)
    cm.ContributionReference(contribution=data[cm.Contribution], source=data[cm.Source])

    for primary, c in [(True, 'contributor'), (False, 'b'), (True, 'c'), (False, 'd')]:
        cm.ContributionContributor(
            contribution=data[cm.Contribution],
            primary=primary,
            contributor=data['Contributor'][c])

    data.add_default(cm.Language, latitude=10.5, longitude=0.3)
    data[cm.Language].sources.append(data[cm.Source])

    for i, type_ in enumerate(cm.IdentifierType):
        cm.LanguageIdentifier(
            language=data[cm.Language],
            identifier=cm.Identifier(type=type_.value, id=type_.value + str(i), name='a'))

    cm.LanguageIdentifier(
        language=data[cm.Language],
        identifier=cm.Identifier(type='name', id='name', name='a'))

    for i in range(2, 102):
        _l = cm.Language(id='l%s' % i, name='Language %s' % i)
        _i = cm.Identifier(type='iso639-3', id='%.3i' % i, name='%.3i' % i)
        cm.LanguageIdentifier(language=_l, identifier=_i)
        DBSession.add(_l)

    param = data.add_default(cm.Parameter)
    de = cm.DomainElement(id='de', name='DomainElement', parameter=param)
    de2 = cm.DomainElement(id='de2', name='DomainElement2', parameter=param)

    valueset = data.add_default(
        cm.ValueSet,
        language=data[cm.Language],
        parameter=param,
        contribution=data[cm.Contribution])
    cm.ValueSetReference(valueset=valueset, source=data[cm.Source], description='10-20')

    data.add_default(
        cm.Value,
        domainelement=de,
        valueset=valueset,
        frequency=50,
        confidence='high')
    data.add(
        cm.Value, 'value2',
        id='value2',
        domainelement=de2,
        valueset=valueset,
        frequency=50,
        confidence='high')

    paramnd = data.add(
        cm.Parameter,
        'no-domain',
        id='no-domain',
        name='Parameter without domain')
    valueset = cm.ValueSet(
        id='vs2',
        language=data[cm.Language],
        parameter=paramnd,
        contribution=data[cm.Contribution])

    cm.ValueSetReference(valueset=valueset, source=data[cm.Source], description='10-20')
    cm.Value(id='v2', valueset=valueset, frequency=50, confidence='high')

    unit = data.add_default(cm.Unit, language=data[cm.Language])
    up = data.add_default(cm.UnitParameter)
    cm.UnitValue(
        id='unitvalue', name='UnitValue', unit=unit, unitparameter=up)

    up2 = cm.UnitParameter(id='up2', name='UnitParameter with domain')
    de = cm.UnitDomainElement(id='de', name='de', parameter=up2)
    DBSession.add(cm.UnitValue(
        id='uv2',
        name='UnitValue2',
        unit=unit,
        unitparameter=up2,
        unitdomainelement=de))

    DBSession.add(cm.Source(id='s'))

    sentence = data.add_default(
        cm.Sentence,
        description='sentence description',
        analyzed='a\tmorpheme\tdoes\tdo',
        gloss='a\tmorpheme\t1SG\tdo.SG2',
        source='own',
        comment='comment',
        original_script='a morpheme',
        language=data[cm.Language],
        jsondata={'alt_translation': 'Spanish: ...'})
    cm.SentenceReference(sentence=sentence, source=data[cm.Source])
    DBSession.add(cm.Config(key='key', value='value'))

    cm.Config.add_replacement('replaced', 'language', model=cm.Language)
    cm.Config.add_replacement('gone', None, model=cm.Language)
    DBSession.flush()
Ejemplo n.º 5
0
def populate_test_db(engine):
    set_alembic_version(engine, '58559d4eea0d')

    data = TestData()
    data.add_default(common.Dataset,
                     domain='clld',
                     jsondata={
                         'license_icon': 'cc-by',
                         'license_url': 'http://example.org'
                     })

    data.add_default(common.Contributor, name='A Name', email='*****@*****.**')
    for id_, name in {
            'b': 'b Name',
            'c': 'c Name',
            'd': 'd Name',
    }.items():
        data.add(common.Contributor,
                 id_,
                 id=id_,
                 name=name,
                 url='http://example.org')

    DBSession.add(
        common.Editor(dataset=data[common.Dataset],
                      contributor=data[common.Contributor]))

    data.add_default(common.Source)
    data.add(common.Source,
             'replaced',
             id='replaced',
             active=False,
             jsondata={'__replacement_id__': 'source'})

    data.add_default(common.Contribution)
    common.ContributionReference(contribution=data[common.Contribution],
                                 source=data[common.Source])

    for primary, c in [(True, 'contributor'), (False, 'b'), (True, 'c'),
                       (False, 'd')]:
        common.ContributionContributor(contribution=data[common.Contribution],
                                       primary=primary,
                                       contributor=data['Contributor'][c])

    data.add_default(common.Language, latitude=10.5, longitude=0.3)
    data[common.Language].sources.append(data[common.Source])

    for i, type_ in enumerate(common.IdentifierType):
        common.LanguageIdentifier(
            language=data[common.Language],
            identifier=common.Identifier(
                type=type_.value,
                id=type_.value + str(i),
                name='abc' if type_.name == 'iso' else 'glot1234'))

    common.LanguageIdentifier(language=data[common.Language],
                              identifier=common.Identifier(type='name',
                                                           id='name',
                                                           name='a'))

    for i in range(2, 102):
        _l = common.Language(id='l%s' % i, name='Language %s' % i)
        _i = common.Identifier(type='iso639-3', id='%.3i' % i, name='abc')
        common.LanguageIdentifier(language=_l, identifier=_i)
        DBSession.add(_l)

    param = data.add_default(common.Parameter)
    de = common.DomainElement(id='de', name='DomainElement', parameter=param)
    de2 = common.DomainElement(id='de2',
                               name='DomainElement2',
                               parameter=param)

    valueset = data.add_default(common.ValueSet,
                                language=data[common.Language],
                                parameter=param,
                                contribution=data[common.Contribution])
    common.ValueSetReference(valueset=valueset,
                             source=data[common.Source],
                             description='10-20')

    data.add_default(common.Value,
                     domainelement=de,
                     valueset=valueset,
                     frequency=50,
                     confidence='high')
    data.add(common.Value,
             'value2',
             id='value2',
             domainelement=de2,
             valueset=valueset,
             frequency=50,
             confidence='high')

    paramnd = data.add(common.Parameter,
                       'no-domain',
                       id='no-domain',
                       name='Parameter without domain')
    valueset = common.ValueSet(id='vs2',
                               language=data[common.Language],
                               parameter=paramnd,
                               contribution=data[common.Contribution])

    common.ValueSetReference(valueset=valueset,
                             source=data[common.Source],
                             description='10-20')
    common.Value(id='v2', valueset=valueset, frequency=50, confidence='high')

    unit = data.add_default(common.Unit, language=data[common.Language])
    up = data.add_default(common.UnitParameter)
    common.UnitValue(id='unitvalue',
                     name='UnitValue',
                     unit=unit,
                     unitparameter=up)

    up2 = common.UnitParameter(id='up2', name='UnitParameter with domain')
    de = common.UnitDomainElement(id='de', name='de', parameter=up2)
    DBSession.add(
        common.UnitValue(id='uv2',
                         name='UnitValue2',
                         unit=unit,
                         unitparameter=up2,
                         unitdomainelement=de))

    DBSession.add(common.Source(id='s'))

    sentence = data.add_default(common.Sentence,
                                description='sentence description',
                                analyzed='a\tmorpheme\tdoes\tdo',
                                gloss='a\tmorpheme\t1SG\tdo.SG2',
                                source='own',
                                comment='comment',
                                original_script='a morpheme',
                                language=data[common.Language],
                                jsondata={'alt_translation': 'Spanish: ...'})
    common.SentenceReference(sentence=sentence, source=data[common.Source])
    DBSession.add(common.Config(key='key', value='value'))

    common.Config.add_replacement('replaced',
                                  'language',
                                  model=common.Language)
    common.Config.add_replacement('gone', None, model=common.Language)
    DBSession.flush()
Ejemplo n.º 6
0
def test_alembic_version(db):
    from clld.db.util import set_alembic_version, get_alembic_version

    assert get_alembic_version(db) != '1234'
    set_alembic_version(db, '1234')
    assert get_alembic_version(db) == '1234'