Exemple #1
0
def integration_test_yelp_place_details():
    client_api_key = os.environ['RYR_COLLECTOR_YELP_API_KEY']

    client = CollectorClient('yelp', api_key=client_api_key)
    client.authenticate()
    place_details = client.place_details('krzzyozIVGC7pX1lfVO40w')
    print(json.dumps(place_details))
Exemple #2
0
    def test_lookup_place_00(self, mocker):
        """Ensure lookup fails when invoked without arguments."""
        c = CollectorClient(self.fake.pystr())
        with pytest.raises(ValueError):
            c.lookup_place()

        assert True
Exemple #3
0
    def test_to_business_info_00(self, mocker):
        """Ensure the collector functions are called."""
        c = CollectorClient(self.fake.pystr())
        c.collector = mocker.Mock()

        c.to_business_info()

        c.collector.to_business_info.assert_called()
Exemple #4
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()
Exemple #5
0
    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()
Exemple #6
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))
Exemple #7
0
    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)
Exemple #8
0
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
Exemple #9
0
def integration_test_yelp_retrieve_place_details():
    client_api_key = os.environ['RYR_COLLECTOR_YELP_API_KEY']

    client = CollectorClient('yelp', api_key=client_api_key)
    client.authenticate()
    epoch_search_summary = PlaceSearchSummary(
        'krzzyozIVGC7pX1lfVO40w',
        'Epoch Coffee',
        '221 West North Loop Boulevard, Austin',
    )
    place_details = client.retrieve_place_details(
        epoch_search_summary.id,
        epoch_search_summary.name,
        epoch_search_summary.address,
    )

    print(json.dumps(place_details))
Exemple #10
0
def integration_test_full_google_yelp_workflow():
    """"""
    places_api_key = os.environ['RYR_COLLECTOR_GOOGLE_PLACES_API_KEY']
    yelp_api_key = os.environ['RYR_COLLECTOR_YELP_API_KEY']

    epoch_latlong = (30.3186037, -97.72454019999999)

    gmaps_places = GoogleCollector()
    gmaps_places.authenticate(api_key=places_api_key)
    s = gmaps_places.search_places(epoch_latlong)

    epoch_search_summary = gmaps_places.retrieve_search_summary(1)

    yelp = CollectorClient('yelp', api_key=yelp_api_key)
    yelp.authenticate()
    place_details = yelp.retrieve_place_details(
        epoch_search_summary.id,
        epoch_search_summary.name,
        epoch_search_summary.address,
    )
    print(json.dumps(place_details))
Exemple #11
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)

    # Extract the place_id.
    details = client.get_place_details(place_summary.id)
    return details
Exemple #12
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(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)
Exemple #13
0
def integration_test_full_google_yelp_workflow_with_generic():
    """"""
    places_api_key = os.environ['RYR_COLLECTOR_GOOGLE_PLACES_API_KEY']
    yelp_api_key = os.environ['RYR_COLLECTOR_YELP_API_KEY']

    # Simulate a click Epoch Coffee Shop - Northloop on the map.
    epoch_latlong = (30.3186037, -97.72454019999999)
    epoch_latlong = (30.319136, -97.724303)
    # Retrieve the places nearby the location clicked on the map.
    gmap = GoogleCollector()
    gmap.authenticate(api_key=places_api_key)
    places_nearby = gmap.search_places_nearby(epoch_latlong)

    # Act like a user chose Epoch Coffee Shop - Northloop in the result list.
    epoch_search_summary = gmap.retrieve_search_summary(1)
    print(epoch_search_summary)

    # Lookup the place on Google Maps.
    google = CollectorClient('google', api_key=places_api_key)
    google.authenticate()
    google_place_details = google.lookup_place(epoch_search_summary.id)
    gb = google.to_business_info()
    print('*** Google:')
    print(gb)

    # Lookup the place on Yelp.
    yelp = CollectorClient('yelp', api_key=yelp_api_key, weight=10)
    yelp.authenticate()
    yelp_place_details = yelp.lookup_place(None, epoch_search_summary.name,
                                           epoch_search_summary.address)
    yb = yelp.to_business_info()
    print('*** Yelp:')
    print(yb)

    # Merge the results.
    print('*** Merged:')
    print(gb.merge(yb))
Exemple #14
0
 def test_authenticate_02(self):
     """Ensure the generic client can authenticate to google."""
     c = CollectorClient('google', api_key=self.fake.pystr())
     with pytest.raises(ValueError):
         c.authenticate()
     assert True
Exemple #15
0
 def test_authenticate_01(self):
     """Ensure the generic client can authenticate to yelp."""
     c = CollectorClient('yelp', api_key=self.fake.pystr())
     c.authenticate()
     assert True
Exemple #16
0
 def test_authenticate_00(self):
     """Ensure an invalid provider raises an error."""
     c = CollectorClient(self.fake.pystr())
     with pytest.raises(ValueError):
         c.authenticate()
     assert True