def test_table_delete_row_with_where_clause(capsys, connection, table):
    insert_data(connection, table, DATA)
    snippets.delete_row_with_where_clause(connection, table)

    out, err = capsys.readouterr()
    assert "Row count: 6" in out
    assert "Row count after deletion: 5" in out
def test_table_delete_all_rows(capsys, connection, table):
    insert_data(connection, table, DATA)
    snippets.delete_all_rows(connection, table)

    out, err = capsys.readouterr()
    assert "Row count: 6" in out
    assert "Row count after deletion: 0" in out
def test_table_fetch_rows_with_limit_offset(capsys, connection, table):
    insert_data(connection, table, DATA)
    snippets.fetch_rows_with_limit_offset(connection, table)

    out, err = capsys.readouterr()
    assert "Fetched rows:" in out
    assert str(tuple(DATA[1].values())) in out
    assert str(tuple(DATA[2].values())) in out
def test_table_update_row(capsys, connection, table):
    insert_data(connection, table, DATA)
    snippets.update_row(connection, table)

    out, err = capsys.readouterr()
    assert "Updated row:" in out

    rows = list(connection.execute(table.select()))
    rows[0][1] == "GEH"
def test_table_fetch_rows(capsys, connection, table):
    insert_data(connection, table, DATA)
    snippets.fetch_rows(connection, table)

    out, err = capsys.readouterr()
    assert "Fetched rows:" in out

    for row in DATA:  # check that all rows were fetched
        assert str(tuple(row.values())) in out
def test_table_filter_data_startswith(capsys, connection, table):
    insert_data(connection, table, DATA)
    snippets.filter_data_startswith(connection, table)

    out, err = capsys.readouterr()
    assert "Fetched rows:" in out

    rows = []
    for ind in (0, 4, 5):
        rows.append(tuple(DATA[ind].values()))

    assert str(rows) in out
def test_table_fetch_rows_with_order_by(capsys, connection, table):
    insert_data(connection, table, DATA)
    snippets.fetch_rows_with_order_by(connection, table)

    out, err = capsys.readouterr()
    assert "Ordered rows:" in out

    rows = []
    for row in sorted(DATA, key=lambda r: r["user_name"]):
        rows.append(tuple(row.values()))

    assert str(rows) in out
def test_table_fetch_row_with_where_clause(capsys, connection, table):
    insert_data(connection, table, DATA)
    snippets.fetch_row_with_where_clause(connection, table)

    out, err = capsys.readouterr()
    assert str(tuple(DATA[0].values())) in out