Esempio n. 1
0
def test_fetch_record(create_movies_sql):
    fields = dict(title='Frozen', revenue=1_290_000_000)
    with connect() as con:
        con.execute(create_movies_sql)
        pk = insert_record('movies', fields)
        row = fetch_record('movies', pk)
    assert tuple(row) == (1, 'Frozen', 1_290_000_000.0)
Esempio n. 2
0
def test_persistent_valid_table(create_movies_sql):
    fields = dict(title=str, revenue=float)

    with connect() as con:
        con.execute(create_movies_sql)
        con.commit()
        assert valid_table('movies', fields)
Esempio n. 3
0
def test_insert_record(create_movies_sql):
    fields = dict(title='Frozen', revenue=1_290_000_000)
    with connect() as con:
        con.execute(create_movies_sql)
        for _ in range(3):
            result = insert_record('movies', fields)
    assert result == 3
Esempio n. 4
0
def test_persistent_valid_table_false(create_movies_sql):
    # year field not in movies_sql
    fields = dict(title=str, revenue=float, year=int)

    with connect() as con:
        con.execute(create_movies_sql)
        con.commit()
        assert not valid_table('movies', fields)
Esempio n. 5
0
def test_delete_record(create_movies_sql):
    fields = dict(title='Frozen', revenue=1_290_000_000)
    with connect() as con:
        con.execute(create_movies_sql)
        pk = insert_record('movies', fields)
        delete_record('movies', pk)
        with pytest.raises(NoSuchRecord) as e:
            fetch_record('movies', pk)
        assert e.value.pk == pk
Esempio n. 6
0
def test_read_columns_sql(create_movies_sql):
    expected = [
        ColumnSchema(name='pk', sql_type='INTEGER'),
        ColumnSchema(name='title', sql_type='TEXT'),
        ColumnSchema(name='revenue', sql_type='REAL'),
    ]
    with connect() as con:
        con.execute(create_movies_sql)
        result = read_columns_sql('movies')
    assert result == expected
Esempio n. 7
0
def test_update_record(create_movies_sql):
    fields = dict(title='Frozen', revenue=1_290_000_000)
    with connect() as con:
        con.execute(create_movies_sql)
        pk = insert_record('movies', fields)
        fields['revenue'] = 1_299_999_999
        sql, values = update_record('movies', pk, fields)
        row = fetch_record('movies', pk)
    assert sql == 'UPDATE movies SET (title, revenue) = (?, ?) WHERE pk = ?'
    assert values == ('Frozen', 1_299_999_999, 1)
    assert tuple(row) == (1, 'Frozen', 1_299_999_999.0)
Esempio n. 8
0
def test_fetch_record_no_such_pk(create_movies_sql):
    with connect() as con:
        con.execute(create_movies_sql)
        with pytest.raises(NoSuchRecord) as e:
            fetch_record('movies', 42)
        assert e.value.pk == 42
Esempio n. 9
0
def test_read_columns_sql_no_such_table(create_movies_sql):
    with connect() as con:
        con.execute(create_movies_sql)
        result = read_columns_sql('no_such_table')
    assert result == []
Esempio n. 10
0
 def _connect(db_path: str = db.DEFAULT_DB_PATH):
     return db.connect(db_path)