Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_MultiSelect(env):
from clld.web.util.multiselect import MultiSelect
ms = MultiSelect(env['request'], common.Language, 'x', url='/')
ms.render()
ms.render(selected=[common.Language.first()])
ms.format_result(common.Language(id='x'))
def test_MultiSelect(env):
from clld.web.util.multiselect import MultiSelect
ms = MultiSelect(env['request'], common.Language, 'x', url='/')
ms.render()
ms.render(selected=[common.Language.first()])
ms.format_result(common.Language(id='x'))
def test_Data(db):
from clld.db.models.common import Language, Language_data
l = Language(id='abc', name='Name')
l.data.append(Language_data(key='abstract', value='c'))
DBSession.add(l)
DBSession.flush()
DBSession.refresh(l)
assert l.datadict()['abstract'] == 'c'
def test_Base_jsondata(db):
l = Language(id='abc', name='Name')
VersionedDBSession.add(l)
VersionedDBSession.flush()
l.update_jsondata(a=1)
assert 'a' in l.jsondata
l.update_jsondata(b=1)
assert 'b' in l.jsondata and 'a' in l.jsondata
assert 'b' in l.__json__(None)['jsondata']
def test_Language():
from clld.db.models.common import Language
d = Language(id='abc')
assert d.glottocode is None
assert d.iso_code is None
def test_Data(mocker):
from clld.db.models.common import Language
from clld.scripts.util import Data
session = set()
mocker.patch('clld.scripts.util.DBSession', session)
d = Data(jsondata={})
d.add(Language, 'l', id='l', name='l')
assert session
d.add(Language, 'l2', _obj=5)
with pytest.raises(ValueError):
d.add(Language, 'l3', id='l.3')
def test_compute_language_sources(data):
from clld.db.util import compute_language_sources
from clld.db.models.common import Source, Sentence, Language, SentenceReference
from clld.db.meta import DBSession
s = Sentence(id='sentenced', language=Language(id='newlang'))
sr = SentenceReference(sentence=s, source=Source.first())
DBSession.add(sr)
DBSession.flush()
compute_language_sources()
def test_source2source(env):
from clld.web.adapters.cldf import source2source
for source in DBSession.query(Source):
res = source2source(env['request'], source)
assert len(res) >= 1
def test_CsvMixin(db):
l1 = Language(id='abc', name='Name', latitude=12.4, jsondata=dict(a=None))
DBSession.add(l1)
DBSession.flush()
l1 = Language.csv_query(DBSession).first()
cols = l1.csv_head()
row = l1.to_csv()
for k, v in zip(cols, row):
if k == 'jsondata':
assert 'a' in json.loads(v)
l2 = Language.from_csv(row)
assert pytest.approx(l1.latitude) == l2.latitude
row[cols.index('latitude')] = '3,5'
l2 = Language.from_csv(row)
assert l2.latitude < l1.latitude
def testdb(mocker):
subprocess.check_call(['dropdb', '-U', 'postgres', '--if-exists', TEST_DB])
subprocess.check_call(['createdb', '-U', 'postgres', TEST_DB])
engine = create_engine('postgresql://postgres@/' + TEST_DB)
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
mocker.patch('glottolog3.__main__.db_url', mocker.Mock(return_value=engine.url))
mocker.patch('glottolog3.__main__.with_session')
yield DBSession
DBSession.close_all()
DBSession.remove()
engine.dispose()
subprocess.check_call(['dropdb', '-U', 'postgres', '--if-exists', TEST_DB])