Exemple #1
0
def test_google_api_returns_coordinates_with_only_state():
    GOOGLE_API_KEY = os.getenv('GOOGLE_API_KEY')
    address = 'Colorado'
    params = {'key': GOOGLE_API_KEY, 'address': f'{address}'}
    service = GoogleService()
    response = service.get_coordinates(params)
    assert response == {'latitude': 39.5500507, 'longitude': -105.7820674}
Exemple #2
0
 def get_recommendation(self, params):
     restaurant_id = self.get_restaurant(params)
     if restaurant_id:
         url = 'https://api.yelp.com/v3/businesses/{}'.format(restaurant_id)
         response = self.connection(url)
         json_data = json.dumps(response.json())
         if 'coordinates' in response.json() and isinstance(
                 response.json()['coordinates']['latitude'], float):
             google_service = GoogleService()
             website = google_service.get_website(json_data)
         elif 'url' in response.json().keys(
         ):  # Will return the Restaurant's Yelp Business Page if no Coordinates available
             website = response.json()['url']
         else:
             website = ""
         recommendation = Restaurant.from_json(json_data, website)
         schema = RestaurantSchema()
         result = schema.dump(recommendation)
         return result
     elif 'radius' in params.keys() and params['radius'] == 16000:
         params.pop('radius', None)
         self.get_recommendation(params)
     else:
         return {
             'error':
             "It appears there aren't any restaurants open near you right now."
         }
Exemple #3
0
def test_google_api_returns_coordinates_with_only_city():
    GOOGLE_API_KEY = os.getenv('GOOGLE_API_KEY')
    address = 'Denver'
    params = {'key': GOOGLE_API_KEY, 'address': f'{address}'}
    service = GoogleService()
    response = service.get_coordinates(params)
    assert response == {'latitude': 39.7392358, 'longitude': -104.990251}
Exemple #4
0
def test_google_api_returns_coordinates_with_street_address():
    GOOGLE_API_KEY = os.getenv('GOOGLE_API_KEY')
    address = '1331 17th St LL100, Denver, CO'
    params = {'key': GOOGLE_API_KEY, 'address': f'{address}'}
    service = GoogleService()
    response = service.get_coordinates(params)
    assert response == {'latitude': 39.7508006, 'longitude': -104.9965947}
Exemple #5
0
def has_address(request_args):
    params = {'open_now': True, 'term': 'food'}
    google = GoogleService()
    location = {}
    new_address = request_args['address'].replace(",", "+")
    location.update({'address': f'{new_address}'})
    coordinates  = google.get_coordinates(location)
    params.update(coordinates)
    return params
Exemple #6
0
def test_google_api_returns_error_if_invalid_address_submitted():
    GOOGLE_API_KEY = os.getenv('GOOGLE_API_KEY')
    address = '123 Test Street'
    params = {'key': GOOGLE_API_KEY, 'input': f'{address}'}
    service = GoogleService()
    response = service.get_coordinates(params)
    assert response == {
        'Invalid Address': 'Please enter a street address, city, and state.'
    }
Exemple #7
0
def test_google_api_returns_successful_response():
    GOOGLE_API_KEY = os.getenv('GOOGLE_API_KEY')
    address = '1331 17th St LL100, Denver, CO'
    url = 'https://maps.googleapis.com/maps/api/geocode/json'
    params = {'key': GOOGLE_API_KEY, 'address': f'{address}'}
    service = GoogleService()
    response = service.connection(url, params)
    status = response.status_code
    assert response.status_code == 200
Exemple #8
0
def test_can_initialize():
    service = GoogleService()
    assert isinstance(service, GoogleService)