コード例 #1
0
ファイル: test.py プロジェクト: imtapps/ggeocoder
    def test_get_results_returns_processed_response(self, process_response, get_url, urlopen):
        params = dict(address="New York", sensor="false")

        g = Geocoder(client_id=self.client_id, private_key=self.private_key)
        results = g._get_results(params)
        self.assertEqual(process_response.return_value, results)
        process_response.assert_called_once_with(urlopen.return_value, get_url.return_value)
コード例 #2
0
ファイル: test.py プロジェクト: imtapps/ggeocoder
    def test_get_results_opens_url_with_request_url_and_timeout(self, get_url, urlopen):
        params = dict(address="New York", sensor="false")

        g = Geocoder(client_id=self.client_id, private_key=self.private_key)
        g._get_results(params)
        get_url.assert_called_once_with(params)
        urlopen.assert_called_once_with(get_url.return_value, timeout=g.TIMEOUT_SECONDS)
コード例 #3
0
ファイル: test.py プロジェクト: imtapps/ggeocoder
    def test_process_response_raises_geocoder_error_when_status_not_ok(self):
        g = Geocoder()

        response = StringIO(no_results_response)
        url = "http://www.example.com"
        with self.assertRaises(GeocodeError) as ctx:
            g._process_response(response, url)
        self.assertEqual(GeocodeError.G_GEO_ZERO_RESULTS, ctx.exception.status)
        self.assertEqual(url, ctx.exception.url)
コード例 #4
0
ファイル: test.py プロジェクト: imtapps/ggeocoder
    def test_get_request_url_returns_url_with_params_when_not_premier(self, urlencode):
        params = dict(address="New York", sensor="false")
        urlencode.return_value = "address=New+York&sensor=false"

        g = Geocoder()
        request_url = g._get_request_url(params)

        self.assertEqual(g.GOOGLE_API_URL + urlencode.return_value, request_url)
        urlencode.assert_called_once_with(params)
コード例 #5
0
ファイル: test.py プロジェクト: imtapps/ggeocoder
    def test_gets_premier_url_when_supplied_credentials(self, get_premier_url, urlencode):
        params = dict(address="New York", sensor="false")
        urlencode.return_value = "address=New+York&sensor=false"

        g = Geocoder(client_id=self.client_id, private_key=self.private_key)
        request_url = g._get_request_url(params)

        self.assertEqual(get_premier_url.return_value, request_url)

        expected_url_to_pass = g.GOOGLE_API_URL + urlencode.return_value
        get_premier_url.assert_called_once_with(expected_url_to_pass)
コード例 #6
0
ファイル: test.py プロジェクト: imtapps/ggeocoder
    def test_process_response_returns_results_when_status_is_ok(self):
        success_json = """{
           "results" : [
              {"one": "the one"},
              {"two": "the two"}
           ],
           "status" : "OK"
        }"""
        response = StringIO(success_json)
        url = "http://www.example.com"
        expected_result = [dict(one="the one"), dict(two="the two")]

        g = Geocoder()
        self.assertEqual(expected_result, g._process_response(response, url))
コード例 #7
0
ファイル: test.py プロジェクト: imtapps/ggeocoder
 def test_get_premier_url_adds_client_and_signature_to_query_string(self):
     g = Geocoder(client_id=self.client_id, private_key=self.private_key)
     premier_url = g._get_premier_url(self.base_url)
     expected_url = self.base_url + "&client={0}&signature={1}".format(self.client_id, self.known_signature)
     self.assertEqual(expected_url, premier_url)
コード例 #8
0
ファイル: test.py プロジェクト: imtapps/ggeocoder
 def test_generate_signature_generates_proper_signature(self):
     # this is using a known signature from Google Documentation.
     # http://code.google.com/apis/maps/documentation/webservices/index.html#SignatureExamples
     g = Geocoder(client_id=self.client_id, private_key=self.private_key)
     base_url = self.base_url + "&client=clientID"
     self.assertEqual(self.known_signature, g._generate_signature(base_url, self.private_key))
コード例 #9
0
ファイル: test.py プロジェクト: imtapps/location-analysis
def test():
    address = ""
    ggeocoder = Geocoder()
    for d in ggeocoder.geocode(address).data:
        pprint(dict(orig=address, result=d.data))
コード例 #10
0
ファイル: test.py プロジェクト: imtapps/location-analysis
def geocodeit(address, fw):
    ggeocoder = Geocoder()
    for d in ggeocoder.geocode(address).data:
        print json.dumps(dict(orig=address, result=d.data))
        fw.write(json.dumps(dict(orig=address, result=d.data)) + '\n')