def test_geometry_returned(self): data = """ { "features": [ { "geometry": { "coordinates": [ [ [1,1],[1,2],[2,2],[2,1] ] ], "type": "Polygon" }, "properties": { "id": "OPP150", "label": "Renoso", "slug": "renoso" }, "type": "Feature" } ], "type": "FeatureCollection" } """ with patch("builtins.open", mock_open(read_data=data)): ret = get_massif_geom("ReNoSo") assert to_shape(ret).wkt == "POLYGON ((1 1, 1 2, 2 2, 2 1, 1 1))"
def persist_massif(con: Connection, name: str, department: Dict, zone: str) -> UUID: dept = persist_department(con, department["name"], department["number"], zone) try: geom = get_massif_geom(name) ins = insert(MassifTable).values(m_name=name, m_department=dept, the_geom=geom) ins = ins.on_conflict_do_nothing(index_elements=["m_name"]) con.execute(ins) res = select([MassifTable.c.m_id]).where(MassifTable.c.m_name == name) return con.execute(res).first().m_id except ValueError as e: # get massif may fail with unknown massif. log.warning(e) raise e
def test_known_massif(self): massif = get_massif_geom("CHABLAIS") assert isinstance(massif, WKBElement)
def test_case_sensivity(self): massif = get_massif_geom("ChAblAis") assert isinstance(massif, WKBElement)
def test_unknown_massif(self): with pytest.raises(ValueError) as e: get_massif_geom("xyz") assert e.type is ValueError assert str(e.value) == "Massif xyz geometry cannot be found."