ogn-python/tests/collect/test_takeoff_landing.py

47 wiersze
2.0 KiB
Python
Czysty Zwykły widok Historia

import datetime
2016-07-02 20:30:54 +00:00
import unittest
from tests.base import TestBaseDB, db
2016-07-02 20:30:54 +00:00
2019-08-31 08:14:41 +00:00
from app.model import TakeoffLanding
2016-07-02 20:30:54 +00:00
2019-08-31 08:14:41 +00:00
from app.collect.takeoff_landings import update_entries
2016-07-02 20:30:54 +00:00
class TestTakeoffLanding(TestBaseDB):
2016-07-02 20:30:54 +00:00
def test_broken_rope(self):
2020-05-16 20:57:21 +00:00
"""The algorithm should detect one takeoff and one landing."""
2020-05-16 20:57:21 +00:00
self.insert_airports_and_devices()
self.insert_aircraft_beacons_broken_rope()
2016-07-02 20:30:54 +00:00
2017-12-10 16:30:27 +00:00
# find the takeoff and the landing
update_entries(db.session, start=datetime.datetime(2016, 7, 2, 0, 0, 0), end=datetime.datetime(2016, 7, 2, 23, 59, 59))
2019-08-31 08:14:41 +00:00
takeoff_landing_query = db.session.query(TakeoffLanding).filter(db.between(TakeoffLanding.timestamp, datetime.datetime(2016, 7, 2, 0, 0, 0), datetime.datetime(2016, 7, 2, 23, 59, 59)))
self.assertEqual(len(takeoff_landing_query.all()), 2)
for entry in takeoff_landing_query.all():
2019-08-31 08:14:41 +00:00
self.assertEqual(entry.airport.name, "Koenigsdorf")
2017-12-10 16:30:27 +00:00
# we should not find the takeoff and the landing again
update_entries(db.session, start=datetime.datetime(2016, 7, 2, 0, 0, 0), end=datetime.datetime(2016, 7, 2, 23, 59, 59))
self.assertEqual(len(takeoff_landing_query.all()), 2)
def test_broken_rope_with_stall(self):
"""Here we have a broken rope where the glider passes again the threshold for take off."""
2020-05-16 20:57:21 +00:00
self.insert_airports_and_devices()
self.insert_aircraft_beacons_broken_rope_with_stall()
# find the takeoff and the landing
update_entries(db.session, start=datetime.datetime(2019, 4, 13, 0, 0, 0), end=datetime.datetime(2019, 4, 13, 23, 59, 59))
2019-08-31 08:14:41 +00:00
takeoff_landings = db.session.query(TakeoffLanding).filter(db.between(TakeoffLanding.timestamp, datetime.datetime(2019, 4, 13, 0, 0, 0), datetime.datetime(2019, 4, 13, 23, 59, 59))).all()
self.assertEqual(len(takeoff_landings), 2)
for entry in takeoff_landings:
2019-08-31 08:14:41 +00:00
self.assertEqual(entry.airport.name, "Koenigsdorf")
2016-07-02 20:30:54 +00:00
2019-08-31 08:14:41 +00:00
if __name__ == "__main__":
2016-07-02 20:30:54 +00:00
unittest.main()