Python responses.calls() Examples

The following are 30 code examples of responses.calls(). 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_client.py    From google-maps-services-python with Apache License 2.0 8 votes vote down vote up
def test_key_sent(self):
        responses.add(
            responses.GET,
            "https://maps.googleapis.com/maps/api/geocode/json",
            body='{"status":"OK","results":[]}',
            status=200,
            content_type="application/json",
        )

        client = googlemaps.Client(key="AIzaasdf")
        client.geocode("Sesame St.")

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://maps.googleapis.com/maps/api/geocode/json?"
            "key=AIzaasdf&address=Sesame+St.",
            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_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 #3
Source File: test_jsonrpcwallet.py    From monero-python with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_address(self):
        responses.add(responses.POST, self.jsonrpc_url,
            json=self._read('test_address-00-get_accounts.json'),
            status=200)
        responses.add(responses.POST, self.jsonrpc_url,
            json=self._read('test_address-10-getaddress.json'),
            status=200)
        responses.add(responses.POST, self.jsonrpc_url,
            json=self._read('test_address-10-getaddress.json'),
            status=200)
        self.wallet = Wallet(JSONRPCWallet())
        waddr = self.wallet.address()
        a0addr = self.wallet.accounts[0].address()
        self.assertEqual(len(responses.calls), 3)
        self.assertEqual(waddr, a0addr)
        self.assertIsInstance(waddr, Address)
        self.assertEqual(
            waddr,
            '596ETuuDVZSNox73YLctrHaAv72fBboxy3atbEMnP3QtdnGFS9KWuHYGuy831SKWLUVCgrRfWLCxuCZ2fbVGh14X7mFrefy')
        self.assertEqual(waddr.label, 'Primary account')
        self.assertEqual(a0addr.label, 'Primary account') 
Example #4
Source File: test_directions.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_alternatives(self):
        responses.add(
            responses.GET,
            "https://maps.googleapis.com/maps/api/directions/json",
            body='{"status":"OK","routes":[]}',
            status=200,
            content_type="application/json",
        )

        routes = self.client.directions(
            "Sydney Town Hall", "Parramatta Town Hall", alternatives=True
        )

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://maps.googleapis.com/maps/api/directions/json?"
            "origin=Sydney+Town+Hall&destination=Parramatta+Town+Hall&"
            "alternatives=true&key=%s" % self.key,
            responses.calls[0].request.url,
        ) 
Example #5
Source File: test_roads.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_speedlimits(self):
        responses.add(
            responses.GET,
            "https://roads.googleapis.com/v1/speedLimits",
            body='{"speedLimits":["foo"]}',
            status=200,
            content_type="application/json",
        )

        results = self.client.speed_limits("id1")
        self.assertEqual("foo", results[0])
        self.assertEqual(
            "https://roads.googleapis.com/v1/speedLimits?"
            "placeId=id1&key=%s" % self.key,
            responses.calls[0].request.url,
        ) 
Example #6
Source File: test_roads.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_path(self):
        responses.add(
            responses.GET,
            "https://roads.googleapis.com/v1/speedLimits",
            body='{"speedLimits":["foo"]}',
            status=200,
            content_type="application/json",
        )

        results = self.client.snapped_speed_limits([(1, 2), (3, 4)])
        self.assertEqual("foo", results["speedLimits"][0])

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://roads.googleapis.com/v1/speedLimits?"
            "path=1%%2C2|3%%2C4"
            "&key=%s" % self.key,
            responses.calls[0].request.url,
        ) 
Example #7
Source File: test_utils.py    From Jike-Metro with MIT License 6 votes vote down vote up
def test_get_uptoken(self):
        params = {'bucket': 'jike'}
        success_reponse = {'uptoken': 'token'}
        responses.add(responses.GET, constants.ENDPOINTS['picture_uptoken'],
                      json=success_reponse, status=200)
        responses.add(responses.GET, constants.ENDPOINTS['picture_uptoken'],
                      status=404)
        # success call
        result = utils.get_uptoken()
        self.assertEqual(result, 'token')
        self.assertEqual(len(responses.calls), 1)
        self.assertEqual(responses.calls[0].request.url,
                         constants.ENDPOINTS['picture_uptoken'] + '?' + urlencode(params))
        self.assertEqual(responses.calls[0].response.json(), success_reponse)
        # failed call
        with self.assertRaises(requests.HTTPError) as cm:
            utils.get_uptoken()
        self.assertEqual(len(responses.calls), 2)
        self.assertEqual(cm.exception.response.status_code, 404) 
Example #8
Source File: test_roads.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_snap(self):
        responses.add(
            responses.GET,
            "https://roads.googleapis.com/v1/snapToRoads",
            body='{"snappedPoints":["foo"]}',
            status=200,
            content_type="application/json",
        )

        results = self.client.snap_to_roads((40.714728, -73.998672))
        self.assertEqual("foo", results[0])

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://roads.googleapis.com/v1/snapToRoads?"
            "path=40.714728%%2C-73.998672&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_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 #10
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 #11
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 #12
Source File: test_geolocation.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_simple_geolocate(self):
        responses.add(
            responses.POST,
            "https://www.googleapis.com/geolocation/v1/geolocate",
            body='{"location": {"lat": 51.0,"lng": -0.1},"accuracy": 1200.4}',
            status=200,
            content_type="application/json",
        )

        results = self.client.geolocate()

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://www.googleapis.com/geolocation/v1/geolocate?" "key=%s" % self.key,
            responses.calls[0].request.url,
        ) 
Example #13
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 #14
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_result_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",
            result_type=["street_address", "route"],
        )

        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"
            "%%7Croute&key=%s&location_type=ROOFTOP" % 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_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 #16
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 #17
Source File: test_client.py    From SalesforcePy with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_context_manager_negative():

    testutil.add_response("login_response_200")
    testutil.add_response("query_response_200")

    client_args = {
        "username": testutil.username,
        "password": testutil.password,
        "client_id": testutil.client_id,
        "client_secret": testutil.client_secret,
        "version": "37.0"}

    def logout():
        raise Exception("Monkey patchin'...")

    with sfdc.client(**client_args) as client:
        client.query("SELECT Id, Name FROM Account LIMIT 10")
        client.logout = logout

    """
        The above should have made 2 calls: login, query
    """
    assert len(responses.calls) == 2 
Example #18
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 #19
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 #20
Source File: test_elevation.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_elevation_multiple(self):
        responses.add(
            responses.GET,
            "https://maps.googleapis.com/maps/api/elevation/json",
            body='{"status":"OK","results":[]}',
            status=200,
            content_type="application/json",
        )

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

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://maps.googleapis.com/maps/api/elevation/json?"
            "locations=enc:abowFtzsbMhgmiMuobzi@&key=%s" % self.key,
            responses.calls[0].request.url,
        ) 
Example #21
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 #22
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 #23
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 #24
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 #25
Source File: test_distance_matrix.py    From google-maps-services-python with Apache License 2.0 6 votes vote down vote up
def test_lang_param(self):
        responses.add(
            responses.GET,
            "https://maps.googleapis.com/maps/api/distancematrix/json",
            body='{"status":"OK","rows":[]}',
            status=200,
            content_type="application/json",
        )

        origins = ["Vancouver BC", "Seattle"]
        destinations = ["San Francisco", "Victoria BC"]

        matrix = self.client.distance_matrix(
            origins, destinations, language="fr-FR", mode="bicycling"
        )

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://maps.googleapis.com/maps/api/distancematrix/json?"
            "key=%s&language=fr-FR&mode=bicycling&"
            "origins=Vancouver+BC%%7CSeattle&"
            "destinations=San+Francisco%%7CVictoria+BC" % self.key,
            responses.calls[0].request.url,
        ) 
Example #26
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_component_filter(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("santa cruz", components={"country": "ES"})

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://maps.googleapis.com/maps/api/geocode/json?"
            "key=%s&components=country%%3AES&address=santa+cruz" % self.key,
            responses.calls[0].request.url,
        ) 
Example #27
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 #28
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 #29
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 #30
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,
        )