Ejemplo n.º 1
0
    def test_retrieve_search_places_00(self, mocker):
        """Ensure the collector functions are called."""
        c = CollectorClient(self.fake.pystr())
        c.collector = mocker.Mock()

        c.search_places(self.fake.pystr())

        c.collector.search_places.assert_called()
Ejemplo n.º 2
0
def collect_place_details_from_yelp(name, address):
    """Collect business information from Yelp."""
    # Prepare client.
    client = CollectorClient('yelp',
                             api_key=os.environ['RYR_COLLECTOR_YELP_API_KEY'])
    client.authenticate()

    # Retrieve detailed results.
    client.search_places(address, terms=name, limit=1)
    place_summary = client.retrieve_search_summary(0)

    if not place_summary:
        raise ValueError('Yelp did not return any result.')

    # Extract the place_id.
    details = client.get_place_details(place_summary.place_id)
    return details
Ejemplo n.º 3
0
def integration_test_yelp_search_place():
    client_api_key = os.environ['RYR_COLLECTOR_YELP_API_KEY']

    client = CollectorClient('yelp', api_key=client_api_key)
    client.authenticate()
    search_result = client.search_places(
        '221 West North Loop Boulevard, Austin', terms='Epoch Coffee', limit=1)

    print(json.dumps(search_result))
Ejemplo n.º 4
0
    def test_lookup_place_02(self, mocker):
        """Ensure lookup returns details for a given name/address pair."""
        fake_place_id = self.fake.pystr()
        fake_name = self.fake.pystr()
        fake_address = self.fake.address()
        c = CollectorClient(self.fake.pystr())
        c.search_places = mocker.Mock()
        c.retrieve_search_summary = mocker.Mock(
            return_value=PlaceSearchSummary(place_id=fake_place_id))
        c.get_place_details = mocker.Mock()

        c.lookup_place(name=fake_name, address=fake_address)

        c.search_places.assert_called_with(address=fake_address,
                                           terms=fake_name,
                                           limit=1)
        c.get_place_details.assert_called_with(fake_place_id)