예제 #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)
예제 #2
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
예제 #3
0
 def _save(self) -> int:
     table = self.__class__._ensure_table()
     if self._pk is None:
         self._pk = db.insert_record(table, self._asdict())
     else:
         db.update_record(table, self._pk, self._asdict())
     return self._pk
예제 #4
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
예제 #5
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)