def test_get_place_details_00(self, mocker): """Ensure the collector functions are called.""" c = CollectorClient(self.fake.pystr()) c.collector = mocker.Mock() c.get_place_details(self.fake.pystr()) c.collector.get_place_details.assert_called()
def test_lookup_place_01(self, mocker): """Ensure lookup returns details for a given place_id.""" fake_place_id = self.fake.pystr() c = CollectorClient(self.fake.pystr()) c.get_place_details = mocker.Mock() c.lookup_place(place_id=fake_place_id) c.get_place_details.assert_called_with(fake_place_id)
def collect_place_details_from_google(place_id): """Collect business information from Google.""" # Prepare client. client = CollectorClient( 'google', api_key=os.environ['RYR_COLLECTOR_GOOGLE_PLACES_API_KEY']) client.authenticate() # Retrieve detailed results. details = client.get_place_details(place_id) return details
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)
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