def test_satellites(self, repository: Repository): """Test that a list of satellites is returned properly.""" satellites = repository.read_satellites() self.assertEqual(len(satellites), 3) self.assertEqual(satellites[-1]['sat_id'], 33591) self.assertEqual(satellites[-2]['sat_id'], 28654) self.assertEqual(satellites[-3]['sat_id'], 25338) satellites = repository.read_satellites(limit=2) self.assertEqual(len(satellites), 2) self.assertEqual(satellites[-1]['sat_id'], 28654) self.assertEqual(satellites[-2]['sat_id'], 25338) satellites = repository.read_satellites(offset=2) self.assertEqual(len(satellites), 1) self.assertEqual(satellites[-1]['sat_id'], 33591)
def obslist(limit_and_offset, **filters): '''This function retrieves observations list from a local database and displays it.''' aos_before_org = filters.get("aos_before") if aos_before_org is not None: # Repository uses datetime.datetime structure to bound dates and it is # exact date. # User provides datetime.date (which not include hour) and it means that # list should contain observations from @los_after day 00:00:00 hour to # @aos_before day 23:59:59.999 hour. For handle it we add 1 day to # @aos_before day before send to repository. filters["aos_before"] = aos_before_org + timedelta(days=1) repository = Repository() obslist = repository.read_observations(filters, **limit_and_offset) satellites_list = repository.read_satellites() observation_count = repository.count_observations(filters) stations_list = repository.read_stations() satellites_dict = { sat["sat_id"]: sat["sat_name"] for sat in satellites_list } stations_dict = {s["station_id"]: s["name"] for s in stations_list} for obs in obslist: obs["sat_name"] = satellites_dict[obs["sat_id"]] obs["station_name"] = stations_dict[obs["station_id"]] if aos_before_org is not None: # We send back to user the same date as user provide. filters["aos_before"] = aos_before_org # When database will contain many satellites and stations then we need # refactor this code to lazy, async read satellites and stations. return 'obslist.html', dict(obslist=obslist, item_count=observation_count, satellites=satellites_list, stations=stations_list, filters=filters)