Пример #1
0
    def get(self, args):
        lng = args.get('lng')
        lat = args.get('lat')
        no_coordinates = lng is None and lat is None
        coordinates_provided = lng is not None and lat is not None

        if no_coordinates:
            return SiteSchema(many=True).dump(self.dao.find_all())
        if coordinates_provided:
            coord = Coordinate(lng=lng, lat=lat)
            query = GeoQuery(coordinate=coord,
                             radius=args['radius'],
                             radius_unit=GeoUnit(args['radius_unit']),
                             only_excess_capacity=args['only_excess_capacity'])
            return SiteSchema(many=True).dump(self.dao.find_by_geo(query))
        return 404
def test_find_by_geo(sites, client, geo_enabled_app):
    resp = client.get(
        f"/sites/geo?lat={PORTLAND.lat}&lng={PORTLAND.lng}&radius=1&radius_unit={GeoUnit.M.value}"
    ).json
    resp_sites = SiteSchema(many=True).load(resp)
    portland_sites = {
        Site(id=1,
             capacity=10.0,
             panels=100,
             address="100 SE Pine St.",
             city="Portland",
             state="OR",
             postal_code="97202",
             coordinate=PORTLAND),
        Site(id=2,
             capacity=25.0,
             panels=110,
             address="101 SW Ankeny",
             city="Portland",
             state="OR",
             postal_code="97203",
             coordinate=PORTLAND)
    }
    assert set(resp_sites) == set(portland_sites)
Пример #3
0
def test_find_all(sites, client):
    resp = client.get('/sites').json
    resp_sites = SiteSchema(many=True).load(resp)
    assert set(resp_sites) == set(sites)
Пример #4
0
def test_find_by_id(sites, client):
    site_id = 1
    found_site = client.get(f'/sites/{site_id}').json
    assert SiteSchema().load(found_site) == sites[0]
def test_find_all(sites, client, geo_enabled_app):
    resp = client.get('/sites/geo').json
    resp_sites = SiteSchema(many=True).load(resp)
    assert set(resp_sites) == set(sites)
def test_find_by_id(sites, client, geo_enabled_app):
    site_id = 1
    found_site = client.get(f'/sites/geo/{site_id}').json
    assert SiteSchema().load(found_site) == sites[0]
Пример #7
0
 def get(self, site_id):
     site = self.dao.find_by_id(site_id)
     if not site:
         return abort(404, message=f"Site {site_id} does not exist")
     return SiteSchema().dump(site)
Пример #8
0
 def get(self):
     return SiteSchema(many=True).dump(self.dao.find_all())