def __init__(self, instance_name, config, providers, services):
        self.instance_name = instance_name
        poi_service = PointsOfInterest(instance_name, services['kv'].db[instance_name], services['search'])

        for provider in providers:
            provider.poi_service = poi_service
            self._register_provider_as_importer(provider, services)

        self._poi_endpoint = PointOfInterestEndpoint(instance_name, poi_service)
        self._nearby_search_endpoint = NearbySearchEndpoint(instance_name, poi_service)
        self._search_endpoint = PointOfInterestSearchEndpoint(instance_name, poi_service)

        self.blueprint = Blueprint(self.instance_name, __name__)
        self.blueprint.add_url_rule('/<slug>/', 'poi', self._poi_endpoint.get)
        self.blueprint.add_url_rule(
            '/nearby/<float:lat>,<float:lon>/', 'nearby', self._nearby_search_endpoint.get_nearby
        )
        self.blueprint.add_url_rule(
            '/nearby/<float:lat>,<float:lon>/category/<slug>/', 'nearby_category',
            self._nearby_search_endpoint.get_category
        )
        self.blueprint.add_url_rule(
            '/nearby/<float:lat>,<float:lon>/amenity/<slug>/', 'nearby_amenity',
            self._nearby_search_endpoint.get_amenity
        )
        self.blueprint.add_url_rule(
            '/search', 'search',
            self._search_endpoint.get
        )
class PointOfInterestSearchEndpointTest(unittest.TestCase):

    def setUp(self):
        self._poi_service = Mock()
        self._poi_service.name_search = Mock(return_value=[])

        self._app = Flask(__name__)
        self._endpoint = PointOfInterestSearchEndpoint('test', self._poi_service)
        self._app.add_url_rule('/search', 'test.search', self._endpoint.get)
        self._app.add_url_rule('/<slug>', 'test.poi', self._endpoint.get)

    def test_making_search_passes_it_to_service(self):
        self._poi_service.search_name.return_value = []
        search_terms = "test search"
        self._make_search_request(search_terms)
        self._poi_service.search_name.assert_called_once_with(search_terms)

    def test_return_value_from_service_is_serialised_to_json(self):
        self._poi_service.search_name.return_value = [PointOfInterest(slug='test:test')]
        response = self._make_search_request("test")
        self.assertEquals('test:test', response['results'][0]['poi']['slug'])

    def _make_search_request(self, search_terms):
        with self._app.test_request_context(
            '/search?q={q}'.format(q=quote_plus(search_terms)), headers=[('Accept', 'application/json')]
        ):
            response = self._endpoint.get()
        return json.loads(response.data)
    def setUp(self):
        self._poi_service = Mock()
        self._poi_service.name_search = Mock(return_value=[])

        self._app = Flask(__name__)
        self._endpoint = PointOfInterestSearchEndpoint('test', self._poi_service)
        self._app.add_url_rule('/search', 'test.search', self._endpoint.get)
        self._app.add_url_rule('/<slug>', 'test.poi', self._endpoint.get)
class App(BaseApp):

    module = 'http://mollyproject.org/apps/places'
    human_name = _('Places')

    def __init__(self, instance_name, config, providers, services):
        self.instance_name = instance_name
        poi_service = PointsOfInterest(instance_name, services['kv'].db[instance_name], services['search'])

        for provider in providers:
            provider.poi_service = poi_service
            self._register_provider_as_importer(provider, services)

        self._poi_endpoint = PointOfInterestEndpoint(instance_name, poi_service)
        self._nearby_search_endpoint = NearbySearchEndpoint(instance_name, poi_service)
        self._search_endpoint = PointOfInterestSearchEndpoint(instance_name, poi_service)

        self.blueprint = Blueprint(self.instance_name, __name__)
        self.blueprint.add_url_rule('/<slug>/', 'poi', self._poi_endpoint.get)
        self.blueprint.add_url_rule(
            '/nearby/<float:lat>,<float:lon>/', 'nearby', self._nearby_search_endpoint.get_nearby
        )
        self.blueprint.add_url_rule(
            '/nearby/<float:lat>,<float:lon>/category/<slug>/', 'nearby_category',
            self._nearby_search_endpoint.get_category
        )
        self.blueprint.add_url_rule(
            '/nearby/<float:lat>,<float:lon>/amenity/<slug>/', 'nearby_amenity',
            self._nearby_search_endpoint.get_amenity
        )
        self.blueprint.add_url_rule(
            '/search', 'search',
            self._search_endpoint.get
        )

    @property
    def links(self):
        return [
            self.nearby_homepage_component,
            self.search_homepage_component
        ]

    @property
    def nearby_homepage_component(self):
        return {
            'self': 'http://mollyproject.org/apps/places/nearby',
            'href': self._get_url_template('nearby')
        }

    @property
    def search_homepage_component(self):
        return {
            'self': 'http://mollyproject.org/apps/places/search',
            'href': self._search_endpoint.href()
        }