Exemplo n.º 1
0
 def test_multi_massif(self):
     with connection_scope() as con:
         r1 = persist_massif(
             con,
             "CHABLAIS",
             {"name": "Haute-savoie", "number": "74"},
             "Alpes du Nord",
         )
         r2 = persist_massif(
             con,
             "MONT-BLANC",
             {"name": "Haute-savoie", "number": "74"},
             "Alpes du Nord",
         )
         assert isinstance(r1, UUID)
         assert isinstance(r2, UUID)
         req = (
             select([ZoneTable.c.z_id, DepartmentTable.c.d_id])
             .select_from(ZoneTable.join(DepartmentTable).join(MassifTable))
             .where(MassifTable.c.m_id == bindparam("massif"))
         )
         id1 = con.execute(req, massif=r1).first()
         id2 = con.execute(req, massif=r2).first()
         assert id1.z_id == id2.z_id
         assert id1.d_id == id2.d_id
Exemplo n.º 2
0
 def test_massif(self):
     with connection_scope() as con:
         r = persist_massif(
             con,
             "CHABLAIS",
             {"name": "Haute-savoie", "number": "74"},
             "Alpes du Nord",
         )
         assert isinstance(r, UUID)
Exemplo n.º 3
0
def import_massifs():
    massif_json = requests.get(Config.BRA_BASE_URL + "/massifs.json").json()
    with connection_scope() as con:
        # the 4th element of the massif is useless, and there are no BRA for it.
        for zone in massif_json[:4]:
            for dept in zone["departements"]:
                for massif in dept["massifs"]:
                    click.echo(f"Importing {massif}")
                    try:
                        persist_massif(
                            con,
                            massif,
                            {
                                "name": dept["nom_dep"],
                                "number": dept["num_dep"]
                            },
                            zone["zone"],
                        )
                    except ValueError:
                        log.warning(f"Do no import massif: {massif}")