from dbSetup.tinyDbSetup import db
import tinydb

PATH = 'tinydb.json'

TEST_DATA = [
    {'name': 'John', 'age': 40},
    {'name': 'Ringo', 'age': 79},
    {'name': 'Paul', 'age': 77},
    {'name': 'George', 'age': 58}
]


def test_basic():
    """ simplest possible test to verify the import works """
    db(PATH).purge_tables()
    db(PATH).insert({'thing1': 'thing2'})
    assert db(PATH).all() == [{'thing1': 'thing2'}]


def test_selects():
    """ confirm I can narrow from 'all' """
    db(PATH).purge_tables()
    for d in TEST_DATA:
        db(PATH).insert(d)

    assert db(PATH).all() == TEST_DATA
    paul = db(PATH).search(tinydb.where('name') == 'Paul')
    assert paul == [{'name': 'Paul', 'age': 77}]


def test_insert_list():
    """ Confirm there is syntax for inserting many """
    db(PATH).purge_tables()
    db(PATH).insert_multiple(TEST_DATA)
    assert db(PATH).all() == TEST_DATA


@@ -900,9 +900,8 @@
 ST_DATA%0A
-%0A

blank line