Esempio n. 1
0
 def test_pelias(self):
     """
     Testing Pelias service
     """
     geocoder = service(service_type='geocoding',
                        service_name='pelias',
                        server_url=PELIAS_TEST_URL)
     self.assertEqual(geocoder.coder_type, 'pelias')
Esempio n. 2
0
 def test_google_search(self):
     """
     Testing Google geocoding
     """
     if settings.GEOCODER_GOOGLE_KEY:
         geocoder = service(service_type='geocoding', service_name='google')
         data = geocoder.search(address=TEST_ADDRESS,
                                key=settings.GEOCODER_GOOGLE_KEY)
         self.assertIsNotNone(data)
     else:
         print("GEOCODER_GOOGLE_KEY not set, skipping test")
Esempio n. 3
0
 def test_google_search_parse_countries(self):
     """
     Test with google search
     """
     if settings.GEOCODER_GOOGLE_KEY:
         geocoder = service(service_type='geocoding', service_name='google')
         data = geocoder.search(address=TEST_ADDRESS,
                                key=settings.GEOCODER_GOOGLE_KEY)
         self.assertIsNotNone(data)
         self.assertIn("FR", geocoder.parse_countries(data))
     else:
         print("GEOCODER_GOOGLE_KEY not set, skipping test")
Esempio n. 4
0
 def test_google_reverse(self):
     """
     Testing Google revrese geocoding
     """
     if settings.GEOCODER_GOOGLE_KEY:
         geocoder = service(service_type='geocoding', service_name='google')
         data = geocoder.reverse(lat=TEST_LAT,
                                 lng=TEST_LNG,
                                 key=settings.GEOCODER_GOOGLE_KEY)
         self.assertIsNotNone(data)
     else:
         print("GEOCODER_GOOGLE_KEY not set, skipping test")
Esempio n. 5
0
 def test_google_reverse_parse_countries(self):
     """
     Test with google reverse
     """
     if settings.GEOCODER_GOOGLE_KEY:
         geocoder = service(service_type='geocoding', service_name='google')
         data = geocoder.reverse(lat=TEST_LAT,
                                 lng=TEST_LNG,
                                 key=settings.GEOCODER_GOOGLE_KEY)
         self.assertIsNotNone(data)
         self.assertIn("FR", geocoder.parse_countries(data))
     else:
         print("GEOCODER_GOOGLE_KEY not set, skipping test")
Esempio n. 6
0
 def test_pelias_search(self):
     """
     Testing Pelias geocoding
     """
     if settings.GEOCODER_PELIAS_KEY:
         geocoder = service(service_type='geocoding',
                            service_name='pelias',
                            server_url=PELIAS_TEST_URL)
         data = geocoder.search(address=TEST_ADDRESS,
                                key=settings.GEOCODER_PELIAS_KEY)
         self.assertIsNotNone(data)
     else:
         print("GEOCODER_PELIAS_KEY not set, skipping test")
Esempio n. 7
0
 def test_pelias_reverse(self):
     """
     Testing Pelias reverse geocoding
     """
     if settings.GEOCODER_PELIAS_KEY:
         geocoder = service(service_type='geocoding',
                            service_name='pelias',
                            server_url=PELIAS_TEST_URL)
         data = geocoder.reverse(lat=TEST_LAT,
                                 lng=TEST_LNG,
                                 key=settings.GEOCODER_PELIAS_KEY)
         self.assertIsNotNone(data)
     else:
         print("GEOCODER_PELIAS_KEY not set, skipping test")
Esempio n. 8
0
 def reverse_geocode(self, request):
     """
     Find country by reverse geocoding (giving latitude and longitude)
     """
     if 'geocoding' not in getattr(settings, 'SERVICES'):
         return Response("Geocoding service not configured",
                         status=status.HTTP_412_PRECONDITION_FAILED)
     if not request.GET.get('geocoder', 'google') in \
            settings.SERVICES['geocoding']:
         return Response("Geocoder not found",
                         status=status.HTTP_404_NOT_FOUND)
     language = validate_language(
         request.GET.get('language', request.LANGUAGE_CODE))
     geocoder = service(service_type='geocoding',
                        service_name=request.GET.get(
                            'geocoder', settings.GEOCODING_SERVICE))
     try:
         data = geocoder.reverse(lat=request.GET.get('latitude'),
                                 lng=request.GET.get('longitude'),
                                 key=request.GET.get(
                                     'geocoder_api_key',
                                     settings.GEOCODER_GOOGLE_KEY),
                                 language=language)
     except TypeError as e:
         logging.error("Invalid parameters")
         logging.error(e)
         return Response(str(e), status=status.HTTP_400_BAD_REQUEST)
     except json.JSONDecodeError as e:
         logging.error("Invalid response")
         logging.error(e)
         return Response(str(e), status=status.HTTP_400_BAD_REQUEST)
     except ValueError as e:
         logging.error("Invalid API configuration")
         logging.error(e)
         return Response(str(e), status=status.HTTP_400_BAD_REQUEST)
     except IOError as e:
         logging.error("Invalid request")
         logging.error(e)
         return Response(str(e), status=status.HTTP_400_BAD_REQUEST)
     except GeocoderRequestError as e:
         return Response(str(e), status=status.HTTP_400_BAD_REQUEST)
     addresses = geocoder.addresses(data)
     serializer = AddressSerializer(addresses,
                                    many=True,
                                    context={'request': request})
     return Response(serializer.data)
Esempio n. 9
0
 def test_pelias_reverse_parse_countries(self):
     """
     Test with pelias reverse
     """
     if settings.GEOCODER_PELIAS_KEY:
         geocoder = service(service_type='geocoding',
                            service_name='pelias',
                            server_url=PELIAS_TEST_URL)
         data = geocoder.reverse(lat=TEST_LAT,
                                 lng=TEST_LNG,
                                 key=settings.GEOCODER_PELIAS_KEY)
         self.assertIsNotNone(data)
         if 'errors' in data:
             print("ERROR - Pelias service not available")
             return
         self.assertIn("FR", geocoder.parse_countries(data))
     else:
         print("GEOCODER_PELIAS_KEY not set, skipping test")
Esempio n. 10
0
 def test_google(self) -> None:
     """
     Testing Google service
     """
     geocoder = service(service_type='geocoding', service_name='google')
     self.assertEqual(geocoder.coder_type, 'google')