Beispiel #1
0
def test_insert_check_exists_using_database(metadata, treedata):
    success = dataclasses_sql.insert(metadata, treedata)
    assert success

    del treedata._rowid
    del treedata.taxonomy._rowid
    success = dataclasses_sql.insert(metadata, treedata)
    assert not success
Beispiel #2
0
def metadata(treedata):
    engine = sqlalchemy.create_engine("sqlite:///:memory:")
    metadata = sqlalchemy.MetaData(engine)
    metadata.reflect()

    dataclasses_sql.insert(metadata, treedata)

    data = TaxonomyData("plantae", "rosales", "rosaceae", "rosa")
    dataclasses_sql.insert(metadata, data)

    return metadata
Beispiel #3
0
def test_update(metadata, treedata):
    # Insert
    assert treedata.diameter_m == pytest.approx(3.0, abs=1e-4)
    success = dataclasses_sql.insert(metadata, treedata)
    assert success

    # Update
    treedata.serial_number = 2  # key field
    treedata.diameter_m = 4.0  # non-key field

    success = dataclasses_sql.update(metadata, treedata)
    assert success

    # Check
    with metadata.bind.begin() as conn:
        rows = conn.execute("select * from treedata").fetchall()

    assert len(rows) == 1

    row = rows[0]
    assert row["serial_number"] == 2
    assert row["specie"] == "Hibiscus abelmoschus"
    assert row["diameter_m"] == pytest.approx(4.0, abs=1e-2)
    assert (
        row["long_description"]
        == b"Hibiscus is a genus of flowering plants in the mallow family, Malvaceae."
    )
    assert row["has_flower"]
    assert row["plantation_datetime"] == "2019-07-21 18:54:21.000000"
    assert row["last_pruning_date"] == "2019-08-01"
Beispiel #4
0
def test_insert(metadata, treedata):
    success = dataclasses_sql.insert(metadata, treedata)
    assert success

    # Check treedata table
    with metadata.bind.begin() as conn:
        rows = conn.execute("select * from treedata").fetchall()

    assert len(rows) == 1

    row = rows[0]
    assert row["serial_number"] == 1
    assert row["specie"] == "Hibiscus abelmoschus"
    assert row["diameter_m"] == pytest.approx(3.0, abs=1e-2)
    assert (
        row["long_description"] ==
        b"Hibiscus is a genus of flowering plants in the mallow family, Malvaceae."
    )
    assert row["has_flower"]
    assert row["plantation_datetime"] == "2019-07-21 18:54:21.000000"
    assert row["last_pruning_date"] == "2019-08-01"

    # Check taxonomy table
    with metadata.bind.begin() as conn:
        rows = conn.execute("select * from taxonomydata").fetchall()

    assert len(rows) == 1

    row = rows[0]

    assert row["kingdom"] == "plantae"
    assert row["order"] == "malvales"
    assert row["family"] == "malvaceae"
    assert row["genus"] == "hibiscus"
Beispiel #5
0
def test_delete(metadata, treedata):
    # Insert
    assert treedata.diameter_m == pytest.approx(3.0, abs=1e-4)
    success = dataclasses_sql.insert(metadata, treedata)
    assert success

    # Delete
    success = dataclasses_sql.delete(metadata, treedata)
    assert success

    # Check
    with metadata.bind.begin() as conn:
        rows = conn.execute("select * from treedata").fetchall()

    assert len(rows) == 0
Beispiel #6
0
def test_exists(metadata, treedata):
    assert not dataclasses_sql.exists(metadata, treedata)

    success = dataclasses_sql.insert(metadata, treedata)
    assert success
    assert dataclasses_sql.exists(metadata, treedata)
Beispiel #7
0
def test_insert_check_exists_using_rowid(metadata, treedata):
    success = dataclasses_sql.insert(metadata, treedata)
    assert success

    success = dataclasses_sql.insert(metadata, treedata)
    assert not success
Beispiel #8
0
 def add_apartment(self, apartment):
     return dataclasses_sql.insert(self.metadata,
                                   apartment,
                                   check_exists=True)