Exemplo n.º 1
0
class GoogleTextSearch(CherryPickerBase):

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

    def __call__(self, caller_id, force=False):
        """
        Parse the google text search results and set the correct attributes.
        """
        google_text_search_results = self.source.text_search(caller_id, force) or []
        howdy_results = []

        for search_result in google_text_search_results:
            howdy_model = {}
            self.parse_result(search_result, howdy_model)
            howdy_results.append(howdy_model)
        return howdy_results

    def parse_result(self, result, howdy_model):
        howdy_model['google_places_id'] = result.get('place_id', None)
        howdy_model['name'] = result.get('name', None)
        geometry = result.get('geometry', None)
        howdy_model['location'] = geometry.get('location', None) if geometry else None
Exemplo n.º 2
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/')