Exemplo n.º 1
0
def test_geolocate():
    # Test that the geolocate method calls the geocode method of the GoogleV3
    # class with the expected parameters
    with patch.object(geopy.geocoders.GoogleV3, "geocode") as mock_geocode:
        test_Greengraph = Greengraph(start, end)
        test_Greengraph.geolocate(start)
        mock_geocode.assert_called_with(start, exactly_one=False)
def test_geolocate():
	'''
	Test the geolocate function in the Greengraph() class. A MagicMock object is created for the geocoder.
	'''
	myGreengraph = Greengraph("London","Cambdrige")
	# defaultResp = ["London",(51.5073509, -0.1277583)]

	tGeocoder = MagicMock()
	# tGeocoder = mock.Mock()
	# attrs = {'geocode.return_value': defaultResp, 'other.side_effect': KeyError}
	# tGeocoder.configure_mock(**attrs)

	defaultResp = []
	defaultResp.append([])
	defaultResp[0].append("London")
	defaultResp[0].append((51.5073509, -0.1277583))

	tGeocoder.geocode.return_value = defaultResp
	myGreengraph.geocoder = tGeocoder

	tGeocoder.geocode.assert_not_called()

	startLocation = myGreengraph.geolocate(myGreengraph.start)
	# print(startLocation)
	# testLoc = tGeocoder.geocode("London", exactly_one=False)
	# print(testLoc)
	# print(tGeocoder.method_calls)

	assert_almost_equal(startLocation,(51.5073509, -0.1277583))

	tGeocoder.geocode.assert_called_with("London", exactly_one=False)
Exemplo n.º 3
0
def test_geolocate():
    with patch.object(geopy.geocoders.GoogleV3, 'geocode') as mock_get:
        trail_graph = Greengraph(start,end)
        trail_graph.geolocate(start)
        mock_get.assert_called_with('London', exactly_one=False)