Exemplo n.º 1
0
def test_csv_wrapping(csv_file):
    # Given
    reader = csv.DictReader(csv_file)

    # When
    wrapper = RowWrapper(reader.fieldnames)
    rows = [wrapper.wrap(row) for row in reader]

    # Then
    assert_that(
        rows,
        contains(
            has_properties(kind="cumberland", rating="10"),
            has_properties(kind="lincolnshire", rating="9"),
            has_properties(kind="vegetarian", rating="0"),
        ),
    )
Exemplo n.º 2
0
def test_wrap_all(db):
    # Given
    cursor = db.cursor()
    cursor.execute("SELECT kind, rating FROM sausages ORDER BY rating DESC;")

    # When
    wrapper = RowWrapper(cursor.description)
    rows = wrapper.wrap_all(cursor.fetchall())

    # Then
    assert_that(
        rows,
        contains(
            has_properties(kind="cumberland", rating=10),
            has_properties(kind="lincolnshire", rating=9),
            has_properties(kind="vegetarian", rating=0),
        ),
    )
Exemplo n.º 3
0
def test_column_identifiers_deduplication_for_mapping_row():
    # Given
    wrapper = RowWrapper(["column-name", "column$name"])

    # When
    row = wrapper({"column-name": "value", "column$name": "another-value"})

    # Then
    assert_that(
        row, has_properties(column_name="value",
                            column_name_2="another-value"))
Exemplo n.º 4
0
def test_identifiers_fixed_for_positional_row():
    # Given
    wrapper = RowWrapper(["column-name", "Another One", "3rd Column"])

    # When
    row = wrapper(["value", "another", "yet another"])

    # Then
    assert_that(
        row,
        has_properties(column_name="value",
                       Another_One="another",
                       a_3rd_Column="yet another"))
Exemplo n.º 5
0
def test_column_identifiers_deduplication_for_positional_row():
    # Given
    wrapper = RowWrapper(["column-name", "column-name", "column$name"])

    # When
    row = wrapper(["value", "another", "yet another"])

    # Then
    assert_that(
        row,
        has_properties(column_name="value",
                       column_name_2="another",
                       column_name_3="yet another"),
    )
Exemplo n.º 6
0
def test_identifiers_fixed_for_mapping_row():
    # Given
    wrapper = RowWrapper(["column-name", "Another One", "3rd Column"])

    # When
    row = wrapper({
        "column-name": "value",
        "Another One": "another-value",
        "3rd Column": "3rd value"
    })

    # Then
    assert_that(
        row,
        has_properties(column_name="value",
                       Another_One="another-value",
                       a_3rd_Column="3rd value"),
    )
Exemplo n.º 7
0
def test_lower_cased_identifiers():
    # Given
    wrapper = RowWrapper(["column-name", "Another One", "3rd Column"],
                         force_lower_case_ids=True)

    # When
    row = wrapper({
        "column-name": "value",
        "Another One": "another-value",
        "3rd Column": "3rd value"
    })

    # Then
    assert_that(
        row,
        has_properties(column_name="value",
                       another_one="another-value",
                       a_3rd_column="3rd value"),
    )
Exemplo n.º 8
0
 def _get_rows(conn: Connection, select: str):
     cursor = conn.cursor()
     cursor.execute(select)
     wrapper = RowWrapper(cursor.description)
     rows = [wrapper.wrap(row) for row in cursor.fetchall()]
     return rows