class ObservationsEndpointTest(unittest.TestCase):

    _OBSERVATION = {'hello': 'world'}
    _ATTRIBUTION = Attribution()

    def setUp(self):
        self._provider = Mock()
        self._provider.latest_observations = Mock(return_value=self._OBSERVATION)
        self._provider.attribution = self._ATTRIBUTION
        self._endpoint = ObservationsEndpoint('weather', self._provider)

    def test_observations_included_in_response(self):
        response = self._get_response_json()
        self.assertEquals(self._OBSERVATION, response['observation'])

    def test_attribution_included_in_response(self):
        response = self._get_response_json()
        self.assertEquals(self._ATTRIBUTION._asdict(), response['attribution'])

    def test_self_included_in_response(self):
        response = self._get_response_json()
        self.assertEquals('http://mollyproject.org/apps/weather/observation', response['self'])

    def test_href_included_in_response(self):
        response = self._get_response_json()
        self.assertEquals('http://localhost/weatherobs', response['href'])

    def _get_response_json(self):
        app = Flask(__name__)
        app.add_url_rule('/weatherobs', 'weather.observation', self._endpoint.get)
        with app.test_request_context('/', headers=[('Accept', 'application/json')]):
            return json.loads(self._endpoint.get().data)
    def __init__(self, instance_name, config, providers, services):
        self.instance_name = instance_name
        self._provider = providers.pop()
        self._provider.cache = services.get('cache', NullCache())
        self._provider.statsd = services.get('statsd', NullStats())

        self._observations_endpoint = ObservationsEndpoint(self.instance_name, self._provider)

        self.blueprint = Blueprint(self.instance_name, __name__)
        self.blueprint.add_url_rule('/', 'observation', self._observations_endpoint.get)
class App(object):

    module = 'http://mollyproject.org/apps/weather'
    human_name = _('Weather')

    def __init__(self, instance_name, config, providers, services):
        self.instance_name = instance_name
        self._provider = providers.pop()
        self._provider.cache = services.get('cache', NullCache())
        self._provider.statsd = services.get('statsd', NullStats())

        self._observations_endpoint = ObservationsEndpoint(self.instance_name, self._provider)

        self.blueprint = Blueprint(self.instance_name, __name__)
        self.blueprint.add_url_rule('/', 'observation', self._observations_endpoint.get)

    @property
    def links(self):
        return [self._observations_endpoint.component()]
 def setUp(self):
     self._provider = Mock()
     self._provider.latest_observations = Mock(return_value=self._OBSERVATION)
     self._provider.attribution = self._ATTRIBUTION
     self._endpoint = ObservationsEndpoint('weather', self._provider)