Пример #1
0
def test_query_check_on_pumpstation(session):
    connection_node1 = factories.ConnectionNodeFactory()
    connection_node2 = factories.ConnectionNodeFactory()
    factories.ManholeFactory(connection_node=connection_node1,
                             bottom_level=1.0)
    factories.ManholeFactory(connection_node=connection_node2,
                             bottom_level=-1.0)
    pumpstation_wrong = factories.PumpstationFactory(
        connection_node_start=connection_node1, lower_stop_level=0.0)
    factories.PumpstationFactory(connection_node_start=connection_node2,
                                 lower_stop_level=2.0)

    query = (
        Query(models.Pumpstation).join(
            models.ConnectionNode,
            models.Pumpstation.connection_node_start_id ==
            models.ConnectionNode.id,  # noqa: E501
        ).join(
            models.Manhole,
            models.Manhole.connection_node_id == models.ConnectionNode.id,
        ).filter(
            models.Pumpstation.lower_stop_level <=
            models.Manhole.bottom_level, ))
    check = QueryCheck(
        column=models.Pumpstation.lower_stop_level,
        invalid=query,
        message="Pumpstation lower_stop_level should be higher than Manhole "
        "bottom_level",
    )
    invalids = check.get_invalid(session)
    assert len(invalids) == 1
    assert invalids[0].id == pumpstation_wrong.id
Пример #2
0
def test_base_extra_filters_err(session):
    factories.ConnectionNodeFactory(id=1, storage_area=3.0)
    factories.ConnectionNodeFactory(id=2, storage_area=None)

    null_check = NotNullCheck(column=models.ConnectionNode.storage_area,
                              filters=models.ConnectionNode.id == 2)
    invalid_rows = null_check.get_invalid(session)
    assert len(invalid_rows) == 1
Пример #3
0
def test_geometry_type_check_invalid_geom_type(session):
    if session.bind.name == "postgresql":
        pytest.skip(
            "Not sure how to insert invalid geometry types in postgresql")
    factories.ConnectionNodeFactory(
        the_geom="SRID=4326;POINT(-71.064544 42.28787)")
    invalid_geom_type = factories.ConnectionNodeFactory(
        the_geom="SRID=4326;LINESTRING(71.0 42.2, 71.3 42.3)")

    geometry_type_check = GeometryTypeCheck(models.ConnectionNode.the_geom)
    invalid_rows = geometry_type_check.get_invalid(session)
    assert len(invalid_rows) == 1
    assert invalid_rows[0].id == invalid_geom_type.id
Пример #4
0
def test_geometry_check(session):
    factories.ConnectionNodeFactory(
        the_geom="SRID=4326;POINT(-371.064544 42.28787)")

    geometry_check = GeometryCheck(models.ConnectionNode.the_geom)
    invalid_rows = geometry_check.get_invalid(session)

    assert len(invalid_rows) == 0
Пример #5
0
def test_null_check_with_null_value(session):
    factories.ConnectionNodeFactory.create_batch(5, storage_area=3.0)
    null_node = factories.ConnectionNodeFactory(storage_area=None)

    null_check = NotNullCheck(models.ConnectionNode.storage_area)
    invalid_rows = null_check.get_invalid(session)
    assert len(invalid_rows) == 1
    assert invalid_rows[0].id == null_node.id
Пример #6
0
def test_fk_check_null_fk(session):
    conn_node = factories.ConnectionNodeFactory()
    factories.ManholeFactory.create_batch(5, manhole_indicator=conn_node.id)
    factories.ManholeFactory(manhole_indicator=None)

    fk_check = ForeignKeyCheck(models.ConnectionNode.id,
                               models.Manhole.manhole_indicator)
    invalid_rows = fk_check.get_invalid(session)
    assert len(invalid_rows) == 0
Пример #7
0
def test_run_spatial_function(session):
    """Example how to use spatial functions.

    Works on postgis and spatialite"""
    factories.ConnectionNodeFactory()
    from geoalchemy2 import func

    q = session.query(func.ST_AsGeoJSON(models.ConnectionNode.the_geom))
    q.first()
Пример #8
0
def test_fk_check_missing_fk(session):
    conn_node = factories.ConnectionNodeFactory()
    factories.ManholeFactory.create_batch(5, manhole_indicator=conn_node.id)
    missing_fk = factories.ManholeFactory(manhole_indicator=-1)

    fk_check = ForeignKeyCheck(models.ConnectionNode.id,
                               models.Manhole.manhole_indicator)
    invalid_rows = fk_check.get_invalid(session)
    assert len(invalid_rows) == 1
    assert invalid_rows[0].id == missing_fk.id
Пример #9
0
def test_conditional_check_storage_area(session):
    # if connection node is a manhole, then the storage area of the
    # connection_node must be > 0
    factories.ConnectionNodeFactory(storage_area=5)
    factories.ConnectionNodeFactory(storage_area=-3)
    conn_node_manhole_valid = factories.ConnectionNodeFactory(storage_area=4)
    conn_node_manhole_invalid = factories.ConnectionNodeFactory(
        storage_area=-5)
    factories.ManholeFactory(connection_node=conn_node_manhole_valid)
    factories.ManholeFactory(connection_node=conn_node_manhole_invalid)

    query = (Query(models.ConnectionNode).join(
        models.Manhole).filter(models.ConnectionNode.storage_area <= 0))
    query_check = QueryCheck(column=models.ConnectionNode.storage_area,
                             invalid=query,
                             message="")

    invalids = query_check.get_invalid(session)
    assert len(invalids) == 1
    assert invalids[0].id == conn_node_manhole_invalid.id
Пример #10
0
def test_range_check_invalid(session, min_value, max_value, left_inclusive,
                             right_inclusive):
    factories.ConnectionNodeFactory(storage_area=42)

    check = RangeCheck(
        min_value,
        max_value,
        left_inclusive,
        right_inclusive,
        column=models.ConnectionNode.storage_area,
    )
    invalid_rows = check.get_invalid(session)
    assert len(invalid_rows) == 1
Пример #11
0
def test_geometry_check_with_invalid_geoms(session):
    if session.bind.name == "postgresql":
        pytest.skip("Not sure how to insert invalid types in postgresql")

    inser_invalid_geom_q = """
    INSERT INTO v2_connection_nodes (id, code, the_geom)
    VALUES (2, 'the_code', 'invalid_geom')
    """
    session.execute(inser_invalid_geom_q)
    factories.ConnectionNodeFactory(
        the_geom="SRID=4326;POINT(-71.064544 42.28787)")

    geometry_check = GeometryCheck(models.ConnectionNode.the_geom)
    invalid_rows = geometry_check.get_invalid(session)
    assert len(invalid_rows) == 1