コード例 #1
0
    def test_station_owners(self, repository: Repository):
        """Tests that the owners of a station can be returned properly. This query is used on
           the station page to list its owners."""
        owners1 = repository.station_owners(1)  # List owners of station id 1
        owners5 = repository.station_owners(
            5
        )  # List owners of station id 5 (no such station, so should be empty list)

        # See tests/db-data.psql for details (station_owners table)
        self.assertEqual(len(owners1), 4)
        self.assertEqual(owners1[0]['username'], 'asimov')
        self.assertEqual(owners1[0]['id'], 1)
        self.assertEqual(owners1[1]['username'], 'baxter')
        self.assertEqual(owners1[1]['id'], 2)
        self.assertEqual(owners1[2]['username'], 'clarke')
        self.assertEqual(owners1[2]['id'], 3)
        self.assertEqual(owners1[3]['username'], 'admin')
        self.assertEqual(owners1[3]['id'], 5)

        # No such station, so no owners
        self.assertEqual(len(owners5), 0)
コード例 #2
0
ファイル: station.py プロジェクト: gut-space/svarog
def station(station_id=None):

    repository = Repository()
    station = repository.read_station(station_id)
    if station is None:
        abort(404, "Station not found")
    statistics = repository.read_station_statistics(station["station_id"])

    photos = repository.read_station_photos(station_id)

    owners = repository.station_owners(station_id)

    # Now get 3 latest observations from this station
    filters = {"station_id": station['station_id']}
    latest_obs = repository.read_observations(filters=filters,
                                              limit=3,
                                              offset=0)

    # Get the 3 observations with the best rating
    best_obs = repository.read_observations(filters=filters,
                                            limit=3,
                                            offset=0,
                                            order="r.rating DESC",
                                            expr="r.rating is not NULL")

    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'] = statistics["last_los"]
    x['firstobs'] = statistics["first_aos"]
    x['cnt'] = statistics["observation_count"]

    files = []
    for photo in photos:
        y = {}
        y['filename'] = photo['filename']
        y['descr'] = photo['descr']
        y['sort'] = photo['sort']
        files.append(y)

    return render_template('station.html',
                           station=x,
                           files=files,
                           owners=owners,
                           latest_obs=latest_obs,
                           best_obs=best_obs)