Пример #1
0
    def test_geocoding_handler_with_empty_location_string(self):
        self.mock_site()
        self.mock_context('', '', '', '')
        self.mock_geosettings_registry()
        event = self.mocker.mock()
        self.replay()

        geocodeAddressHandler(self.context, event)
Пример #2
0
    def test_geocoding_handler_with_missing_adapter(self):
        self.mock_site()
        self.mock_context()
        # Unregister the IGeocodableLocation adapter
        gsm = getGlobalSiteManager()
        gsm.unregisterAdapter(SomeTypeLocationAdapter)
        event = self.mocker.mock()
        self.replay()

        # Handler should not fail even though there is no adapter
        geocodeAddressHandler(self.context, event)
Пример #3
0
    def test_geocoding_handler(self):
        self.mock_site()
        self.mock_context()
        self.mock_geomanager()
        self.mock_annotations()
        self.mock_geosettings_registry()
        self.replace_geopy_geocoders()
        self.replay()

        event = self.mocker.mock()
        geocodeAddressHandler(self.context, event)
Пример #4
0
    def test_geocoding_handler_with_api_key(self):
        self.mock_site()
        # Use different address values for context to avoid caching
        self.mock_context('Bahnhofplatz', '3000', 'Bern', 'Switzerland')
        self.mock_geomanager()
        self.mock_annotations()
        self.mock_geosettings_registry(api_key='API_KEY_123')
        self.replace_geopy_geocoders()
        event = self.mocker.mock()
        self.replay()

        geocodeAddressHandler(self.context, event)
Пример #5
0
    def test_geocoding_doesnt_swallow_conflict_error(self):
        self.mock_site()
        self.mock_context('Some Address')
        self.mock_annotations()
        self.mock_geosettings_registry()
        self.replace_geopy_geocoders()

        self.mocker.throw(ConflictError)
        event = self.mocker.mock()
        self.replay()

        # Make sure ConflictError always gets raised
        with self.assertRaises(ConflictError):
            geocodeAddressHandler(self.context, event)
Пример #6
0
    def test_geocoding_handler_with_invalid_location(self):
        self.mock_site()
        self.mock_statusmessage_adapter()
        self.mock_context('Bag End', '1234', 'The Shire', 'Middle Earth')
        self.mock_annotations()
        self.mock_geosettings_registry()
        self.replace_geopy_geocoders()
        self.mocker.throw(GeocoderQueryError)
        event = self.mocker.mock()
        self.replay()

        geocodeAddressHandler(self.context, event)
        # Expect the appropriate info message
        self.assertEquals(self.message_cache.info, 'msg_no_match')
Пример #7
0
    def test_geocoding_unhandled_exception(self):
        self.mock_site()
        self.mock_statusmessage_adapter()
        self.mock_context('Some Address')
        self.mock_annotations()
        self.mock_geosettings_registry()
        self.replace_geopy_geocoders()

        event = self.mocker.mock()
        self.mocker.throw(Exception('Something broke!'))
        self.replay()

        geocodeAddressHandler(self.context, event)
        # Expect the appropriate info message
        self.assertEquals(self.message_cache.info, 'msg_unhandled_exception')
Пример #8
0
    def test_geocoding_handler_with_network_error(self):
        self.mock_site()
        self.mock_statusmessage_adapter()
        self.mock_context('Some Address')
        self.mock_annotations()
        self.mock_geosettings_registry()
        self.replace_geopy_geocoders()

        event = self.mocker.mock()
        self.mocker.throw(URLError('foo'))
        self.replay()

        geocodeAddressHandler(self.context, event)
        # Expect the appropriate info message
        self.assertEquals(self.message_cache.info, 'msg_network_error')
Пример #9
0
    def test_geocoding_handler_with_too_many_queries(self):
        self.mock_site()
        self.mock_statusmessage_adapter()
        self.mock_context('Some Address')
        self.mock_annotations()
        self.mock_geosettings_registry()
        self.replace_geopy_geocoders()

        self.mocker.throw(GeocoderQuotaExceeded)
        event = self.mocker.mock()
        self.replay()

        geocodeAddressHandler(self.context, event)
        # Expect the appropriate info message
        self.assertEquals(self.message_cache.info, 'msg_too_many_queries')
Пример #10
0
    def test_geocoding_handler_with_same_location(self):
        self.mock_site()
        # Use different address values for context to avoid caching
        self.mock_context('Hirschengraben', '3000', 'Bern', 'Switzerland')
        # geo manager should only be called once since the second request
        # won't cause a lookup
        self.mock_geomanager(count=1)
        self.mock_annotations(count=2)
        self.mock_geosettings_registry()
        self.replace_geopy_geocoders()
        event = self.mocker.mock()
        self.replay()

        # Call the handler twice with the same context, shouldn't cause a
        # lookup since location didn't change.
        geocodeAddressHandler(self.context, event)
        geocodeAddressHandler(self.context, event)
Пример #11
0
    def test_multiple_results(self):
        self.mock_site()
        self.mock_statusmessage_adapter()
        self.mock_context('Hasslerstrasse', '3000', 'Bern', 'Switzerland')
        self.mock_geomanager()
        self.mock_annotations()
        self.mock_geosettings_registry()

        result = ((u'3001 Berne, Switzerland',
                   (46.958857500000001, 7.4273286000000001)),
                  (u'3000 Berne, Switzerland',
                   (46.958857500000002, 7.4273286000000002)), )
        self.replace_geopy_geocoders(result=result)
        self.replay()

        geocodeAddressHandler(self.context, None)
        # Expect the appropriate info message
        self.assertEquals(self.message_cache.info, 'msg_multiple_matches')
Пример #12
0
    def test_geocoding_handler_with_invalid_non_ascii_locatio(self):
        self.mock_site()
        self.mock_statusmessage_adapter()
        self.mock_context('Ober\xc3\xa4geri', '1234', 'The Shire', 'Middle Earth')
        self.mock_annotations()
        self.replace_geopy_geocoders()
        self.mocker.throw(GeocoderQueryError)
        event = self.mocker.mock()
        self.replay()

        geocodeAddressHandler(self.context, event)
        # Expect the appropriate info message
        self.assertEquals(self.message_cache.info, 'msg_no_match')

        msg = self.message_cache.info
        loc = msg.mapping['location']
        # Concatenate message (unicode) and location to force a possible
        # UnicodeDecodeError if string types don't match
        self.assertIsInstance(msg + loc, unicode)