Python responses.GET Examples

The following are 30 code examples of responses.GET(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module responses , or try the search function .
Example #1
Source File: test_elevation.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_elevation_along_path(self):
        responses.add(
            responses.GET,
            "https://maps.googleapis.com/maps/api/elevation/json",
            body='{"status":"OK","results":[]}',
            status=200,
            content_type="application/json",
        )

        path = [(40.714728, -73.998672), (-34.397, 150.644)]

        results = self.client.elevation_along_path(path, 5)

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://maps.googleapis.com/maps/api/elevation/json?"
            "path=enc:abowFtzsbMhgmiMuobzi@&"
            "key=%s&samples=5" % self.key,
            responses.calls[0].request.url,
        ) 
Example #2
Source File: test_geocoding.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_geocode_with_multiple_component_filters(self):
        responses.add(
            responses.GET,
            "https://maps.googleapis.com/maps/api/geocode/json",
            body='{"status":"OK","results":[]}',
            status=200,
            content_type="application/json",
        )

        results = self.client.geocode(
            "Torun", components={"administrative_area": "TX", "country": "US"}
        )

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://maps.googleapis.com/maps/api/geocode/json?"
            "key=%s&components=administrative_area%%3ATX%%7C"
            "country%%3AUS&address=Torun" % self.key,
            responses.calls[0].request.url,
        ) 
Example #3
Source File: test_geocoding.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_geocode_with_region_biasing(self):
        responses.add(
            responses.GET,
            "https://maps.googleapis.com/maps/api/geocode/json",
            body='{"status":"OK","results":[]}',
            status=200,
            content_type="application/json",
        )

        results = self.client.geocode("Toledo", region="es")

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://maps.googleapis.com/maps/api/geocode/json?"
            "region=es&key=%s&address=Toledo" % self.key,
            responses.calls[0].request.url,
        ) 
Example #4
Source File: test_geocoding.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_reverse_geocode(self):
        responses.add(
            responses.GET,
            "https://maps.googleapis.com/maps/api/geocode/json",
            body='{"status":"OK","results":[]}',
            status=200,
            content_type="application/json",
        )

        results = self.client.reverse_geocode((-33.8674869, 151.2069902))

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://maps.googleapis.com/maps/api/geocode/json?"
            "latlng=-33.8674869,151.2069902&key=%s" % self.key,
            responses.calls[0].request.url,
        ) 
Example #5
Source File: test_geocoding.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_simple_geocode(self):
        responses.add(
            responses.GET,
            "https://maps.googleapis.com/maps/api/geocode/json",
            body='{"status":"OK","results":[]}',
            status=200,
            content_type="application/json",
        )

        results = self.client.geocode("Sydney")

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://maps.googleapis.com/maps/api/geocode/json?"
            "key=%s&address=Sydney" % self.key,
            responses.calls[0].request.url,
        ) 
Example #6
Source File: test_distance_matrix.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_mixed_params(self):
        responses.add(
            responses.GET,
            "https://maps.googleapis.com/maps/api/distancematrix/json",
            body='{"status":"OK","rows":[]}',
            status=200,
            content_type="application/json",
        )

        origins = ["Bobcaygeon ON", [41.43206, -81.38992]]
        destinations = [
            (43.012486, -83.6964149),
            {"lat": 42.8863855, "lng": -78.8781627},
        ]

        matrix = self.client.distance_matrix(origins, destinations)

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://maps.googleapis.com/maps/api/distancematrix/json?"
            "key=%s&origins=Bobcaygeon+ON%%7C41.43206%%2C-81.38992&"
            "destinations=43.012486%%2C-83.6964149%%7C42.8863855%%2C"
            "-78.8781627" % self.key,
            responses.calls[0].request.url,
        ) 
Example #7
Source File: test_geocoding.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_geocoding_the_googleplex(self):
        responses.add(
            responses.GET,
            "https://maps.googleapis.com/maps/api/geocode/json",
            body='{"status":"OK","results":[]}',
            status=200,
            content_type="application/json",
        )

        results = self.client.geocode("1600 Amphitheatre Parkway, " "Mountain View, CA")

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://maps.googleapis.com/maps/api/geocode/json?"
            "key=%s&address=1600+Amphitheatre+Parkway%%2C+Mountain"
            "+View%%2C+CA" % self.key,
            responses.calls[0].request.url,
        ) 
Example #8
Source File: test_geocoding.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_simple_reverse_geocode(self):
        responses.add(
            responses.GET,
            "https://maps.googleapis.com/maps/api/geocode/json",
            body='{"status":"OK","results":[]}',
            status=200,
            content_type="application/json",
        )

        results = self.client.reverse_geocode((40.714224, -73.961452))

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://maps.googleapis.com/maps/api/geocode/json?"
            "latlng=40.714224%%2C-73.961452&key=%s" % self.key,
            responses.calls[0].request.url,
        ) 
Example #9
Source File: test_geocoding.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_reverse_geocode_restricted_by_type(self):
        responses.add(
            responses.GET,
            "https://maps.googleapis.com/maps/api/geocode/json",
            body='{"status":"OK","results":[]}',
            status=200,
            content_type="application/json",
        )

        results = self.client.reverse_geocode(
            (40.714224, -73.961452),
            location_type="ROOFTOP",
            result_type="street_address",
        )

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://maps.googleapis.com/maps/api/geocode/json?"
            "latlng=40.714224%%2C-73.961452&result_type=street_address&"
            "key=%s&location_type=ROOFTOP" % self.key,
            responses.calls[0].request.url,
        ) 
Example #10
Source File: test_geocoding.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_reverse_geocode_multiple_location_types(self):
        responses.add(
            responses.GET,
            "https://maps.googleapis.com/maps/api/geocode/json",
            body='{"status":"OK","results":[]}',
            status=200,
            content_type="application/json",
        )

        results = self.client.reverse_geocode(
            (40.714224, -73.961452),
            location_type=["ROOFTOP", "RANGE_INTERPOLATED"],
            result_type="street_address",
        )

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://maps.googleapis.com/maps/api/geocode/json?"
            "latlng=40.714224%%2C-73.961452&result_type=street_address&"
            "key=%s&location_type=ROOFTOP%%7CRANGE_INTERPOLATED" % self.key,
            responses.calls[0].request.url,
        ) 
Example #11
Source File: test_geocoding.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_partial_match(self):
        responses.add(
            responses.GET,
            "https://maps.googleapis.com/maps/api/geocode/json",
            body='{"status":"OK","results":[]}',
            status=200,
            content_type="application/json",
        )

        results = self.client.geocode("Pirrama Pyrmont")

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://maps.googleapis.com/maps/api/geocode/json?"
            "key=%s&address=Pirrama+Pyrmont" % self.key,
            responses.calls[0].request.url,
        ) 
Example #12
Source File: test_geocoding.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_utf_results(self):
        responses.add(
            responses.GET,
            "https://maps.googleapis.com/maps/api/geocode/json",
            body='{"status":"OK","results":[]}',
            status=200,
            content_type="application/json",
        )

        results = self.client.geocode(components={"postal_code": "96766"})

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://maps.googleapis.com/maps/api/geocode/json?"
            "key=%s&components=postal_code%%3A96766" % self.key,
            responses.calls[0].request.url,
        ) 
Example #13
Source File: test_directions.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_simple_directions(self):
        responses.add(
            responses.GET,
            "https://maps.googleapis.com/maps/api/directions/json",
            body='{"status":"OK","routes":[]}',
            status=200,
            content_type="application/json",
        )

        # Simplest directions request. Driving directions by default.
        routes = self.client.directions("Sydney", "Melbourne")

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://maps.googleapis.com/maps/api/directions/json"
            "?origin=Sydney&destination=Melbourne&key=%s" % self.key,
            responses.calls[0].request.url,
        ) 
Example #14
Source File: test_directions.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_transit_with_arrival_time(self):
        responses.add(
            responses.GET,
            "https://maps.googleapis.com/maps/api/directions/json",
            body='{"status":"OK","routes":[]}',
            status=200,
            content_type="application/json",
        )

        an_hour_from_now = datetime.now() + timedelta(hours=1)
        routes = self.client.directions(
            "Sydney Town Hall",
            "Parramatta, NSW",
            mode="transit",
            arrival_time=an_hour_from_now,
        )

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://maps.googleapis.com/maps/api/directions/json?"
            "origin=Sydney+Town+Hall&arrival_time=%d&"
            "destination=Parramatta%%2C+NSW&mode=transit&key=%s"
            % (time.mktime(an_hour_from_now.timetuple()), self.key),
            responses.calls[0].request.url,
        ) 
Example #15
Source File: test_geocoding.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_geocode_with_just_components(self):
        responses.add(
            responses.GET,
            "https://maps.googleapis.com/maps/api/geocode/json",
            body='{"status":"OK","results":[]}',
            status=200,
            content_type="application/json",
        )

        results = self.client.geocode(
            components={
                "route": "Annegatan",
                "administrative_area": "Helsinki",
                "country": "Finland",
            }
        )

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://maps.googleapis.com/maps/api/geocode/json?"
            "key=%s&components=administrative_area%%3AHelsinki"
            "%%7Ccountry%%3AFinland%%7Croute%%3AAnnegatan" % self.key,
            responses.calls[0].request.url,
        ) 
Example #16
Source File: test_elevation.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_short_latlng(self):
        responses.add(
            responses.GET,
            "https://maps.googleapis.com/maps/api/elevation/json",
            body='{"status":"OK","results":[]}',
            status=200,
            content_type="application/json",
        )

        results = self.client.elevation((40, -73))

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://maps.googleapis.com/maps/api/elevation/json?"
            "locations=40,-73&key=%s" % self.key,
            responses.calls[0].request.url,
        ) 
Example #17
Source File: test_elevation.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_elevation_single_list(self):
        responses.add(
            responses.GET,
            "https://maps.googleapis.com/maps/api/elevation/json",
            body='{"status":"OK","results":[]}',
            status=200,
            content_type="application/json",
        )

        results = self.client.elevation([(40.714728, -73.998672)])

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://maps.googleapis.com/maps/api/elevation/json?"
            "locations=enc:abowFtzsbM&key=%s" % self.key,
            responses.calls[0].request.url,
        ) 
Example #18
Source File: test_elevation.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_elevation_single(self):
        responses.add(
            responses.GET,
            "https://maps.googleapis.com/maps/api/elevation/json",
            body='{"status":"OK","results":[]}',
            status=200,
            content_type="application/json",
        )

        results = self.client.elevation((40.714728, -73.998672))

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://maps.googleapis.com/maps/api/elevation/json?"
            "locations=enc:abowFtzsbM&key=%s" % self.key,
            responses.calls[0].request.url,
        ) 
Example #19
Source File: test_places.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_autocomplete_query(self):
        url = "https://maps.googleapis.com/maps/api/place/queryautocomplete/json"
        responses.add(
            responses.GET,
            url,
            body='{"status": "OK", "predictions": []}',
            status=200,
            content_type="application/json",
        )

        self.client.places_autocomplete_query("pizza near New York")

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "%s?input=pizza+near+New+York&key=%s" % (url, self.key),
            responses.calls[0].request.url,
        ) 
Example #20
Source File: test_timezone.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_los_angeles_with_no_timestamp(self):
        responses.add(
            responses.GET,
            "https://maps.googleapis.com/maps/api/timezone/json",
            body='{"status":"OK"}',
            status=200,
            content_type="application/json",
        )

        timezone = self.client.timezone((39.603481, -119.682251))
        self.assertIsNotNone(timezone)

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://maps.googleapis.com/maps/api/timezone/json"
            "?location=39.603481,-119.682251&timestamp=%d"
            "&key=%s" % (1608, self.key),
            responses.calls[0].request.url,
        ) 
Example #21
Source File: test_timezone.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_los_angeles(self):
        responses.add(
            responses.GET,
            "https://maps.googleapis.com/maps/api/timezone/json",
            body='{"status":"OK"}',
            status=200,
            content_type="application/json",
        )

        ts = 1331766000
        timezone = self.client.timezone((39.603481, -119.682251), ts)
        self.assertIsNotNone(timezone)

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://maps.googleapis.com/maps/api/timezone/json"
            "?location=39.603481,-119.682251&timestamp=%d"
            "&key=%s" % (ts, self.key),
            responses.calls[0].request.url,
        ) 
Example #22
Source File: test_geocoding.py    From mapbox-cli-py with MIT License 6 votes vote down vote up
def test_cli_geocode_fwd_features():

    responses.add(
        responses.GET,
        'https://api.mapbox.com/geocoding/v5/mapbox.places/1600%20pennsylvania%20ave%20nw.json?access_token=bogus&limit=2',
        match_querystring=True,
        body='{"features": [{"name": "first"}, {"name": "second"}]}', status=200,
        content_type='application/json')

    runner = CliRunner()
    result = runner.invoke(
        main_group,
        ['--access-token', 'bogus', 'geocoding', '--limit', '2', '--features',
         '--forward', '1600 pennsylvania ave nw'],
        catch_exceptions=False)
    assert result.exit_code == 0
    assert result.output == '{"name": "first"}\n{"name": "second"}\n' 
Example #23
Source File: test_geocoding.py    From mapbox-cli-py with MIT License 6 votes vote down vote up
def test_cli_geocode_reverse_features():

    lon, lat = -77.4371, 37.5227
    res = {"query": [lon, lat],
           "features": [{"name": "first"}, {"name": "second"}]}
    body = json.dumps(res)

    responses.add(
        responses.GET,
        'https://api.mapbox.com/geocoding/v5/mapbox.places/{0},{1}.json?access_token=pk.test'.format(lon, lat),
        match_querystring=True,
        body=body,
        status=200,
        content_type='application/json')

    runner = CliRunner()
    result = runner.invoke(
        main_group,
        ['--access-token', 'pk.test', 'geocoding', '--reverse', '--features'],
        input='{0},{1}'.format(lon, lat))
    assert result.exit_code == 0
    assert result.output == '{"name": "first"}\n{"name": "second"}\n' 
Example #24
Source File: test_geocoding.py    From mapbox-cli-py with MIT License 6 votes vote down vote up
def test_cli_geocode_fwd_limit():

    responses.add(
        responses.GET,
        'https://api.mapbox.com/geocoding/v5/mapbox.places/1600%20pennsylvania%20ave%20nw.json?access_token=bogus&limit=2',
        match_querystring=True,
        body='{"features": [{"name": "first"}, {"name": "second"}]}', status=200,
        content_type='application/json')

    runner = CliRunner()
    result = runner.invoke(
        main_group,
        ['--access-token', 'bogus', 'geocoding', '--limit', '2',
         '--forward', '1600 pennsylvania ave nw'],
        catch_exceptions=False)
    assert result.exit_code == 0
    assert result.output == '{"features": [{"name": "first"}, {"name": "second"}]}\n' 
Example #25
Source File: test_geocoding.py    From mapbox-cli-py with MIT License 6 votes vote down vote up
def test_cli_geocode_rev_headers():

    lon, lat = -77.4371, 37.5227
    body = json.dumps({"query": [lon, lat]})

    responses.add(
        responses.GET,
        'https://api.mapbox.com/geocoding/v5/mapbox.places/{0},{1}.json'.format(lon, lat),
        body=body,
        status=200,
        content_type='application/json')

    runner = CliRunner()
    result = runner.invoke(
        main_group,
        ['geocoding', '-i', '--reverse'],
        input='{0},{1}'.format(lon, lat))
    assert result.exit_code == 0
    assert result.output.startswith('Content-Type') 
Example #26
Source File: test_geocoding.py    From mapbox-cli-py with MIT License 6 votes vote down vote up
def test_cli_geocode_rev_unauthorized():

    lon, lat = -77.4371, 37.5227

    responses.add(
        responses.GET,
        'https://api.mapbox.com/geocoding/v5/mapbox.places/{0},{1}.json'.format(lon, lat),
        body='{"message":"Not Authorized - Invalid Token"}', status=401,
        content_type='application/json')

    runner = CliRunner()
    result = runner.invoke(
        main_group,
        ['geocoding', '--reverse'],
        input='{0},{1}'.format(lon, lat))
    assert result.exit_code == 1
    assert result.output == 'Error: {"message":"Not Authorized - Invalid Token"}\n' 
Example #27
Source File: test_geocoding.py    From mapbox-cli-py with MIT License 6 votes vote down vote up
def test_cli_geocode_reverse():

    lon, lat = -77.4371, 37.5227
    body = json.dumps({"query": [lon, lat]})

    responses.add(
        responses.GET,
        'https://api.mapbox.com/geocoding/v5/mapbox.places/{0},{1}.json?access_token=pk.test'.format(lon, lat),
        match_querystring=True,
        body=body,
        status=200,
        content_type='application/json')

    runner = CliRunner()
    result = runner.invoke(
        main_group,
        ['--access-token', 'pk.test', 'geocoding', '--reverse'],
        input='{0},{1}'.format(lon, lat))
    assert result.exit_code == 0
    assert result.output.strip() == body 
Example #28
Source File: test_geocoding.py    From mapbox-cli-py with MIT License 6 votes vote down vote up
def test_cli_geocode_fwd_env_token():

    responses.add(
        responses.GET,
        'https://api.mapbox.com/geocoding/v5/mapbox.places/1600%20pennsylvania%20ave%20nw.json?access_token=bogus',
        match_querystring=True,
        body='{"query": ["1600", "pennsylvania", "ave", "nw"]}', status=200,
        content_type='application/json')

    runner = CliRunner()
    result = runner.invoke(
        main_group,
        ['geocoding', '--forward', '1600 pennsylvania ave nw'],
        env={'MAPBOX_ACCESS_TOKEN': 'bogus'})
    assert result.exit_code == 0
    assert result.output == '{"query": ["1600", "pennsylvania", "ave", "nw"]}\n' 
Example #29
Source File: test_geocoding.py    From mapbox-cli-py with MIT License 6 votes vote down vote up
def test_cli_geocode_fwd_bbox():

    responses.add(
        responses.GET,
        'https://api.mapbox.com/geocoding/v5/mapbox.places/1600%20pennsylvania%20ave%20nw.json?access_token=bogus&bbox=-78.3284%2C38.6039%2C-78.0428%2C38.7841',
        match_querystring=True,
        body='{"query": ["1600", "pennsylvania", "ave", "nw"]}', status=200,
        content_type='application/json')

    runner = CliRunner()
    result = runner.invoke(
        main_group,
        ['--access-token', 'bogus', 'geocoding', '--forward', '1600 pennsylvania ave nw', '--bbox', '[-78.3284,38.6039,-78.0428,38.7841]'],
        catch_exceptions=False)
    print(result.output)
    print(result.exception)
    print(result.exc_info)
    assert result.exit_code == 0
    assert result.output == '{"query": ["1600", "pennsylvania", "ave", "nw"]}\n' 
Example #30
Source File: test_geocoding.py    From mapbox-cli-py with MIT License 6 votes vote down vote up
def test_cli_geocode_fwd():

    responses.add(
        responses.GET,
        'https://api.mapbox.com/geocoding/v5/mapbox.places/1600%20pennsylvania%20ave%20nw.json?access_token=bogus',
        match_querystring=True,
        body='{"query": ["1600", "pennsylvania", "ave", "nw"]}', status=200,
        content_type='application/json')

    runner = CliRunner()
    result = runner.invoke(
        main_group,
        ['--access-token', 'bogus', 'geocoding', '--forward', '1600 pennsylvania ave nw'],
        catch_exceptions=False)
    print(result.output)
    print(result.exception)
    print(result.exc_info)
    assert result.exit_code == 0
    assert result.output == '{"query": ["1600", "pennsylvania", "ave", "nw"]}\n'