Exemple #1
0
 def testGoogleDetails(self):
     google = Google(storage=DictionaryStorage())
     place_id = u'ChIJL9V5DTEQzkwR2Iz9nMnPGkc'
     details_response = google.details(place_id)
     self.assertIsNotNone(details_response)
     details_response_again = google.details(place_id)
     self.assertIsNotNone(details_response_again)
Exemple #2
0
class GoogleDetails(CherryPickerBase):

    def __init__(self, source=None, storage=None, request_handler=None):
        super(GoogleDetails, self).__init__(source, storage, request_handler)
        if not source:
            self.source = Google(storage=storage, request_handler=request_handler)

    def __call__(self, howdy_model, force=False):
        """
        Parse the google text search results and set the correct attributes.
        """
        google_details_result = self.source.details(howdy_model['google_places_id'], force)
        self.parse_result(google_details_result, howdy_model)

    def parse_result(self, result, howdy_model):
        """

        """
        website = result.get('website', None)
        domain = None
        if website:
            domain = urlparse(website).hostname

        howdy_model['website'] = website
        howdy_model['domain'] = domain
        howdy_model['utc_offset'] = result.get('utc_offset', None)
        howdy_model['formatted_address'] = result.get('formatted_address', None)
Exemple #3
0
class GooglePlacesTest(unittest.TestCase):

    def setUp(self):
        self.google = Google()

    ##############################
    #### GOOGLE PLACES SEARCH ####
    ##############################

    def test_search_caller_id(self):
        caller_id = 16132379329
        results = self.google.text_search(caller_id)
        self.assertIsNotNone(results)

    def test_search_caller_id_not_found(self):
        caller_id = 16133246100
        self.assertRaises(Exception, self.google.text_search, caller_id)

    def test_place_id_request(self):
        place_id = u'ChIJL9V5DTEQzkwR2Iz9nMnPGkc'
        result = self.google.details(place_id)
        self.assertIsNotNone(result)
        self.assertEqual(result.get('website', None), 'http://www.versature.com/')