def test_fejlmeld_koordinat_midt_i_tidsserie(firedb: FireDb, sag: Sag, punkt: Punkt, srid: Srid): koordinater = [] for i in range(3): se = Sagsevent(id=str(uuid.uuid4()), sag=sag, eventtype=EventType.KOORDINAT_BEREGNET) koordinat = Koordinat( srid=srid, punkt=punkt, _registreringfra=dt.datetime(2020, 9, 22, 8, i), t=dt.datetime(2020, 5, 9, 22, i), x=i, y=i, z=i, sx=0, sy=0, sz=0, ) koordinater.append(koordinat) se.koordinater = [koordinat] firedb.session.add(se) firedb.session.commit() firedb.fejlmeld_koordinat( Sagsevent(sag=sag, eventtype=EventType.KOORDINAT_NEDLAGT), koordinater[1]) assert koordinater[1].fejlmeldt is True assert koordinater[1].registreringtil is not None
def canExecute(self): if FireDb is None: return ( False, "Dette plugin er afhængigt af API'et til Fikspunktregistret. Se venligst https://github.com/Septima/fire-qgis#installation", ) fire_connection_string = self.settings.value("fire_connection_string") if fire_connection_string is None: conf_message = "Kan ikke finde konfigurationsfil. Se venligst https://github.com/Kortforsyningen/fire-cli#konfigurationsfil for format og placering af konfigurationsfil" return False, conf_message else: try: fireDb = FireDb(fire_connection_string) fireDb.hent_observationstyper() return True, "OK" except Exception as ex: str_ex = str(ex) fire_connection_file_path = self.settings.value( "fire_connection_file_path") return ( False, "Fejl i forbindelse til Fikspunktregistret. Se venligst https://github.com/Kortforsyningen/fire-cli#konfigurationsfil for format og indhold af konfigurationsfil. Exception:[" + str_ex + "] Konfigurationsfil:[" + fire_connection_file_path + "]", )
def test_indset_observation(firedb: FireDb, sag: Sag, punkt: Punkt): obstype = firedb.session.query(ObservationsType).first() obs1 = Observation( antal=0, observationstype=obstype, observationstidspunkt=dt.datetime.utcnow(), opstillingspunkt=punkt, value1=0, value2=0, value3=0, value4=0, value5=0, value6=0, value7=0, value8=0, ) sagsevent = Sagsevent(sag=sag, id=uuid(), eventtype=EventType.OBSERVATION_INDSAT) sagseventtekst = "Ilægning af observation" sagseventinfo = SagseventInfo(beskrivelse=sagseventtekst) sagsevent.sagseventinfos.append(sagseventinfo) sagsevent.observationer = [obs1] firedb.indset_sagsevent(sagsevent)
def test_grafik_unikke_filnavne(firedb: FireDb, sag: Sag, sagsevent: Sagsevent): """Test at der ikke kan oprettes filnavnedupletter""" filnavn = f"{fire.uuid()}.png" sagsevent.eventtype = EventType.PUNKT_OPRETTET p1 = Punkt(sagsevent=sagsevent) p2 = Punkt(sagsevent=sagsevent) g1 = Grafik( punkt=p1, filnavn=filnavn, mimetype="image/png", type="skitse", grafik=b"\xf3\xf5\xf8\x98", ) g2 = Grafik( punkt=p2, filnavn=filnavn, mimetype="image/png", type="skitse", grafik=b"\xf3\xf5\xf8\x98", ) with pytest.raises(DatabaseError): firedb.indset_sagsevent( Sagsevent( sag=sag, sagseventinfos=[ SagseventInfo(beskrivelse="Test fejl ved filnavnduplet") ], eventtype=EventType.GRAFIK_INDSAT, grafikker=[g1, g2], ) ) firedb.session.rollback()
def test_hent_observationer(firedb: FireDb, observationer): firedb.session.commit() id1 = observationer[0].objectid id2 = observationer[1].objectid os = firedb.hent_observationer((id1, id2)) assert len(os) == 2 os = firedb.hent_observationer((-999, -998)) assert len(os) == 0
def test_luk_sag(firedb: FireDb, sag: Sag): assert sag.aktiv is True firedb.luk_sag(sag) s = firedb.hent_sag(sag.id) assert s.aktiv is False with pytest.raises(TypeError): firedb.luk_sag(4242)
def test_indset_punkt_with_invalid_sagsevent_eventtype(firedb: FireDb, sag: Sag): p = Punkt() go = GeometriObjekt() go.geometri = Point([1, 1]) p.geometriobjekter.append(go) with pytest.raises(Exception, match="KOMMENTAR"): firedb.indset_punkt(Sagsevent(sag=sag, eventtype=EventType.KOMMENTAR), p)
def test_hent_observationer(firedb: FireDb, observationer): firedb.session.commit() id1 = observationer[0].id id2 = observationer[1].id os = firedb.hent_observationer((id1, id2)) assert len(os) == 2 os = firedb.hent_observationer( ("60cd07f2-2c9a-471c-bc7e-ef3473098e85", "7e277296-2412-46ff-91f2-0841cf1cc3af") ) assert len(os) == 0
def test_indset_sagsevent(firedb: FireDb, sag: Sag): sagseventinfo = SagseventInfo(beskrivelse="Testing testing") firedb.indset_sagsevent( Sagsevent( sag=sag, eventtype=EventType.KOMMENTAR, sagseventinfos=[sagseventinfo], )) s = firedb.hent_sag(sag.id) assert s.sagsevents[0].sagseventinfos[0].beskrivelse == "Testing testing"
def test_indset_observationtype(firedb: FireDb): ot = ObservationType( name="absolut_tyngde", beskrivelse="Absolut gravimetrisk observation", value1="tyngdeacceleration", sigtepunkt="false", ) firedb.indset_observationtype(ot) typ = firedb.hent_observationtype("absolut_tyngde") assert typ.value1 == ot.value1
def test_soeg_punkter(firedb: FireDb): punkter = firedb.soeg_punkter("%rd%") for punkt in punkter: assert punkt.ident in ("RDIO", "RDO1") kun_et_punkt = firedb.soeg_punkter("K-63-%", antal=1) assert len(kun_et_punkt) == 1 with pytest.raises(NoResultFound): firedb.soeg_punkter("punkt der ikke findes")
def test_luk_koordinat(firedb: FireDb, koordinat: Koordinat, sagsevent: Sagsevent): firedb.session.commit() assert koordinat.registreringtil is None assert koordinat.sagsevent.eventtype == EventType.KOORDINAT_BEREGNET firedb.luk_koordinat(koordinat, sagsevent) assert koordinat.registreringtil is not None assert koordinat.sagsevent.eventtype == EventType.KOORDINAT_NEDLAGT with pytest.raises(TypeError): firedb.luk_koordinat(firedb)
def test_luk_observation(firedb: FireDb, observation: Observation, sagsevent: Sagsevent): firedb.session.commit() assert observation.registreringtil is None assert observation.sagsevent.eventtype == EventType.OBSERVATION_INDSAT firedb.luk_observation(observation, sagsevent) assert observation.registreringtil is not None assert observation.sagsevent.eventtype == EventType.OBSERVATION_NEDLAGT with pytest.raises(TypeError): firedb.luk_observation(9999)
def test_punktinfoanvendelsestype(firedb: FireDb, sagsevent: Sagsevent, punkt: Punkt): """ Tester validering af anvendelsestype i triggeren punktinfo_biu_trg """ infotype_flag = firedb.hent_punktinformationtype("ATTR:tabtgået") flaginfo = PunktInformation( infotype=infotype_flag, punkt=punkt, tekst="tekst", tal=999, ) sagsevent.punktinformationer = [flaginfo] firedb.session.add(sagsevent) with pytest.raises(DatabaseError): firedb.session.commit() firedb.session.rollback() infotype_tekst = firedb.hent_punktinformationtype("IDENT:GNSS") tekstinfo = PunktInformation( infotype=infotype_tekst, punkt=punkt, tekst=None, tal=None, ) sagsevent.punktinformationer = [tekstinfo] firedb.session.add(sagsevent) with pytest.raises(DatabaseError): firedb.session.commit() firedb.session.rollback() infotype_tal = PunktInformationType( name="ATTR:tal", anvendelse=PunktInformationTypeAnvendelse.TAL, beskrivelse="Test", infotypeid=999, ) talinfo = PunktInformation( infotype=infotype_tal, punkt=punkt, tekst=None, tal=None, ) sagsevent.punktinformationer = [talinfo] firedb.session.add(sagsevent) with pytest.raises(DatabaseError): firedb.session.commit() firedb.session.rollback()
def test_hent_punkt_liste(firedb: FireDb): identer = ["RDIO", "RDO1", "SKEJ"] punkter = firedb.hent_punkt_liste(identer) for ident, punkt in zip(identer, punkter): assert ident == punkt.ident with pytest.raises(ValueError): firedb.hent_punkt_liste(["SKEJ", "RDIO", "ukendt_ident"], ignorer_ukendte=False) punkter = firedb.hent_punkt_liste(["SKEJ", "RDIO", "ukendt_ident"], ignorer_ukendte=True) assert len(punkter) == 2
def test_indset_observationstype(firedb: FireDb): ot = ObservationsType( name="absolut_tyngde", beskrivelse="Absolut gravimetrisk observation", value1="tyngdeacceleration", sigtepunkt=Boolean.FALSE, ) firedb.indset_observationstype(ot) typ = firedb.hent_observationstype("absolut_tyngde") assert typ.value1 == ot.value1 firedb.session.delete(typ) firedb.session.commit()
def test_hent_observationer_naer_geometri(firedb: FireDb): go = firedb.hent_geometri_objekt( punktid="67e3987a-dc6b-49ee-8857-417ef35777af") os = firedb.hent_observationer_naer_geometri(go.geometri, 10000) assert len(os) == 68 point = Geometry("POINT (10.2112609352788 56.1567354902778)") os = firedb.hent_observationer_naer_geometri(point, 100) assert len(os) == 6 polygon = Geometry(("POLYGON ((10.209 56.155, " "10.209 56.158, " "10.215 56.158, " "10.215 56.155, " "10.209 56.155))")) os = firedb.hent_observationer_naer_geometri(polygon, 100) assert len(os) == 10
def test_indset_punkt(firedb: FireDb, sag: Sag): p = Punkt() go = GeometriObjekt() go.geometri = Point([1, 1]) p.geometriobjekter.append(go) firedb.indset_sagsevent( Sagsevent( sag=sag, sagseventinfos=[ SagseventInfo(beskrivelse="Testindsættelse af et punkt") ], eventtype=EventType.PUNKT_OPRETTET, punkter=[p], ))
def test_luk_beregning(firedb: FireDb, beregning: Beregning, sagsevent: Sagsevent): firedb.session.commit() assert beregning.registreringtil is None assert beregning.sagsevent.eventtype == EventType.KOORDINAT_BEREGNET firedb.luk_beregning(beregning, sagsevent) assert beregning.registreringtil is not None assert beregning.sagsevent.eventtype == EventType.KOORDINAT_NEDLAGT for koordinat in beregning.koordinater: assert koordinat.registreringtil is not None assert koordinat.sagsevent.eventtype == EventType.KOORDINAT_NEDLAGT with pytest.raises(TypeError): firedb.luk_beregning(234)
def test_luk_punktinfo( firedb: FireDb, punktinformationtype: PunktInformationType, punkt: Punkt, sagsevent: Sagsevent, ): punktinfo = PunktInformation( infotype=punktinformationtype, punkt=punkt, sagsevent=sagsevent ) firedb.session.add(punktinfo) firedb.session.commit() assert punktinfo.registreringtil is None firedb.luk_punktinfo(punktinfo, sagsevent) assert punktinfo.registreringtil is not None assert punktinfo.sagsevent.eventtype == EventType.PUNKTINFO_FJERNET
def test_cli(firedb: FireDb, sag: Sag): firedb.session.add(sag) firedb.session.commit() runner = CliRunner() title = "Read all points" args = [ "read", "-i", "test/gama/input/near_geometry.xml", "-c", sag.id, ] assert _run_cli(runner, title, args) sag = firedb.hent_sag(sag.id) for koordinat in sag.sagsevents[-1].koordinater: if koordinat.punkt.ident == "SKEJ": assert koordinat.z == approx(72.0285) if koordinat.punkt.ident == "RDIO": assert koordinat.z == approx(85.1816) if koordinat.punkt.ident == "RDO1": assert koordinat.z == approx(86.1778)
def _set_database(ctx, param, value): """ Vælg en specifik databaseforbindelse. """ if value is not None: new_firedb = FireDb(db=str(value).lower()) override_firedb(new_firedb)
def test_identer(firedb: FireDb): punkt = firedb.hent_punkt("8e5e57f8-d3c4-45f2-a2a9-492f52d7df1c") assert "SKEJ" in punkt.identer assert "102-08-00802" in punkt.identer assert len(punkt.identer) == 3 # kort uuid 8e5e57f8 er også en ident
def test_fejlmeld_koordinat_enlig_koordinat(firedb: FireDb, sag: Sag, sagsevent: Sagsevent, koordinat: Koordinat): sagsevent.eventtype = EventType.KOORDINAT_BEREGNET sagsevent.sagsid = sag.id koordinat.sagsevent = sagsevent firedb.session.add(sag) firedb.session.add(sagsevent) firedb.session.add(koordinat) firedb.session.commit() firedb.fejlmeld_koordinat( Sagsevent(eventtype=EventType.KOORDINAT_BEREGNET, sag=sag), koordinat) assert koordinat.fejlmeldt is True assert koordinat.registreringtil is not None
def test_indset_beregning( firedb: FireDb, sag: Sag, sagsevent: Sagsevent, punkt: Punkt, srid: Srid, observationstype: ObservationsType, ): o0 = Observation( sagsevent=sagsevent, observationstidspunkt=func.current_timestamp(), observationstype=observationstype, opstillingspunkt=punkt, ) firedb.indset_sagsevent( Sagsevent( sag=sag, sagseventinfos=[ SagseventInfo(beskrivelse="Testindsættelse af observation") ], eventtype=EventType.OBSERVATION_INDSAT, observationer=[o0], )) beregning = Beregning() beregning.observationer.append(o0) koordinat = Koordinat(srid=srid, punkt=punkt, x=0, y=0, z=0, sx=0, sy=0, sz=0) beregning.koordinater.append(koordinat) firedb.indset_sagsevent( Sagsevent( sag=sag, eventtype=EventType.KOORDINAT_BEREGNET, sagseventinfos=[SagseventInfo(beskrivelse="Testberegning")], beregninger=[beregning], koordinater=beregning.koordinater, )) assert koordinat.objektid is not None
def test_luk_punkt( firedb: FireDb, punkt: Punkt, sagsevent: Sagsevent, observationer: List[Observation], koordinat: Koordinat, punktinformationtype: PunktInformationType, ): # byg et punkt der har tilknyttet geometri, koordinat, # punktinfo og observationer geometri = GeometriObjekt(punkt=punkt, geometri=Point([10, 55]), sagsevent=sagsevent) firedb.session.add(geometri) observationer[0].opstillingspunkt = punkt observationer[1].sigtepunkt = punkt koordinat.punkt = punkt punkt.punktinformationer = [ PunktInformation(infotype=punktinformationtype, sagsevent=sagsevent) ] firedb.session.commit() firedb.luk_punkt(punkt, sagsevent) assert punkt.registreringtil is not None assert punkt.sagsevent.eventtype == EventType.PUNKT_NEDLAGT assert punkt.sagseventtilid == sagsevent.id assert geometri.registreringtil is not None assert geometri.sagsevent.eventtype == EventType.PUNKT_NEDLAGT for koordinat in punkt.koordinater: assert koordinat.registreringtil is not None assert koordinat.sagsevent.eventtype == EventType.PUNKT_NEDLAGT assert koordinat.sagseventtilid == sagsevent.id for punktinfo in punkt.punktinformationer: assert punktinfo.registreringtil is not None assert punktinfo.sagsevent.eventtype == EventType.PUNKT_NEDLAGT assert punktinfo.sagseventtilid == sagsevent.id for observation in chain(punkt.observationer_fra, punkt.observationer_til): assert observation.registreringtil is not None assert observation.sagsevent.eventtype == EventType.PUNKT_NEDLAGT assert observation.sagseventtilid == sagsevent.id with pytest.raises(TypeError): firedb.luk_punkt(999)
def test_indset_sagsevent_materiale(firedb: FireDb, sag: Sag): blob = os.urandom(1000) sagseventinfo = SagseventInfo( beskrivelse="Testing testing", materialer=[SagseventInfoMateriale(materiale=blob)], ) firedb.indset_sagsevent( Sagsevent( sag=sag, eventtype=EventType.KOMMENTAR, sagseventinfos=[sagseventinfo], )) s = firedb.hent_sag(sag.id) assert s.sagsevents[0].sagseventinfos[0].materialer[0].materiale == blob
def test_indset_observation(firedb: FireDb, sag: Sag, punkt: Punkt): obstype = firedb.session.query(ObservationType).first() observation = Observation( antal=0, observationstype=obstype, observationstidspunkt=dt.datetime.utcnow(), opstillingspunkt=punkt, value1=0, value2=0, value3=0, value4=0, value5=0, value6=0, value7=0, value8=0, ) firedb.indset_observation(Sagsevent(sag=sag), observation)
def test_hent_punkt(firedb: FireDb, punkt: Punkt): firedb.session.commit() # sørg for at punkt indsættes i databasen punktid = punkt.id print(punktid) print(punkt) p = firedb.hent_punkt(punktid) assert isinstance(p, Punkt) s = p.sagsevent assert isinstance(s, Sagsevent)
def test_grafik_luk(firedb: FireDb, punkt: Punkt, sagsevent: Sagsevent): """Test at et Grafik objekt kan lukkes korrekt""" filnavn = f"{fire.uuid()}.png" g = Grafik( punkt=punkt, filnavn=filnavn, mimetype="image/png", type="skitse", grafik=b"\xf3\xf5\xf8\x98", ) sagsevent.grafikker = [g] firedb.session.add(g) firedb.session.commit() assert g.registreringtil is None firedb.luk_grafik(g, sagsevent) assert g.registreringtil is not None assert g.sagsevent.eventtype == EventType.GRAFIK_NEDLAGT