Ejemplo n.º 1
0
def sites(redis, key_schema):
    site_dao = SiteDaoRedis(redis, key_schema)

    site1 = Site(id=1,
                 capacity=10.0,
                 panels=100,
                 address="100 SE Pine St.",
                 city="Portland",
                 state="OR",
                 postal_code="97202",
                 coordinate=Coordinate(lat=1, lng=1))

    site2 = Site(id=2,
                 capacity=25.0,
                 panels=110,
                 address="101 SW Ankeny",
                 city="Portland",
                 state="OR",
                 postal_code="97203",
                 coordinate=Coordinate(lat=1, lng=1))

    site3 = Site(id=3,
                 capacity=100.0,
                 panels=155,
                 address="201 SE Burnside",
                 city="Portland",
                 state="OR",
                 postal_code="97204",
                 coordinate=Coordinate(lat=1, lng=1))

    site_dao.insert_many(site1, site2, site3)

    yield [site1, site2, site3]
Ejemplo n.º 2
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
Ejemplo n.º 3
0
import datetime

import pytest

from redisolar.dao.base import SiteNotFound
from redisolar.dao.redis import CapacityReportDaoRedis
from redisolar.dao.redis import SiteGeoDaoRedis
from redisolar.models import Coordinate
from redisolar.models import GeoQuery
from redisolar.models import GeoUnit
from redisolar.models import MeterReading
from redisolar.models import Site

PORTLAND = Coordinate(lat=45.523064, lng=-122.676483)
BEAVERTON = Coordinate(lat=45.485168, lng=-122.804489)


@pytest.fixture
def site_geo_dao(redis, key_schema):
    yield SiteGeoDaoRedis(redis, key_schema)


@pytest.fixture
def capacity_dao(redis, key_schema):
    yield CapacityReportDaoRedis(redis, key_schema)


def test_does_not_exist(site_geo_dao):
    with pytest.raises(SiteNotFound):
        site_geo_dao.find_by_id(0)