Beispiel #1
0
def test_json_readwrite(tmpdir):
    """
    Regression test for issue #1
    """
    path = str(tmpdir.join('test.db.json'))

    # Create Flata instance
    db = Flata(path, storage=JSONStorage)

    # Create table test_table
    tb = db.table('test_table')

    item = {'data': 'data exists'}
    item2 = {'data': 'data not exists'}

    get = lambda s: tb.get(where('data') == s)

    tb.insert(item)
    assert dict(get('data exists'))['data'] == 'data exists'

    assert get('data not exists') is None

    tb.remove(where('data') == 'data exists')
    assert get('data exists') is None

    db.close()
Beispiel #2
0
def test_gc(tmpdir):
    path = str(tmpdir.join('test.db.json'))
    db = Flata(path)
    table = db.table('foo')
    table.insert({'something': 'else'})
    table.insert({'int': 13})
    assert len(table.search(where('int') == 13)) == 1
    assert table.all() == [{
        'id': 1,
        'something': 'else'
    }, {
        'id': 2,
        'int': 13
    }]
    db.close()
Beispiel #3
0
def test_json_kwargs(tmpdir):
    db_file = tmpdir.join('test.db.json')
    db = Flata(str(db_file), sort_keys=True, indent=4, separators=(',', ': '))

    # Create table test_table
    tb = db.table('test_table')

    # Write contents
    tb.insert({'b': 1})
    # tb.insert({'a': 1})
    print(db_file.read())

    assert db_file.read() == '''{
    "test_table": [
        {
            "b": 1,
            "id": 1
        }
    ]
}'''
    db.close()