def test_stations(self, repository: Repository): """Checks that a list of stations is returned properly.""" station_entries = repository.read_stations() station_statistics = repository.read_stations_statistics() self.assertEqual(len(station_entries), 2) self.assertEqual(len(station_statistics), 2) s1, s2 = zip(station_entries, station_statistics) self.check_station1(*s1) self.check_station2(*s2) # Now limit number of returned stations to just one. There should be only station-id 1. station_entries = repository.read_stations(limit=1) station_statistics = repository.read_stations_statistics(limit=1) self.assertEqual(len(station_entries), 1) self.assertEqual(len(station_statistics), 1) self.check_station1(station_entries[0], station_statistics[0] ) # This should return values for station-id 1 # Now skip the first station. Only station 2 should be returned. station_entries = repository.read_stations(offset=1) station_statistics = repository.read_stations_statistics(offset=1) self.assertEqual(len(station_entries), 1) self.assertEqual(len(station_statistics), 1) self.check_station2(station_entries[0], station_statistics[0] ) # This should return values for station-id 2
def stations(limit_and_offset): '''This function retrieves list of all registered ground stations.''' repository = Repository() stations = repository.read_stations(**limit_and_offset) statistics = repository.read_stations_statistics(**limit_and_offset) station_count = repository.count_stations() # Now convert the data to a list of objects that we can pass to the template. stationlist = [] for station, stat in zip(stations, statistics): x = {} x['station_id'] = station['station_id'] x['name'] = station['name'] x['coords'] = utils.coords(station['lon'], station['lat']) x['descr'] = station['descr'] x['config'] = station['config'] x['registered'] = station['registered'] x['lastobs'] = stat["last_los"] x['cnt'] = stat["observation_count"] stationlist.append(x) return 'stations.html', dict(stations=stationlist, item_count=station_count)