Пример #1
0
 def test_google(self) -> None:
     """
     Testing Google service
     """
     if settings.GEOCODER_GOOGLE_KEY:
         geocoder = service(service_type='geocoding',
                            service_name='google',
                            key=settings.GEOCODER_GOOGLE_KEY)
         self.assertEqual(geocoder.coder_type, 'google')
     else:
         with self.assertRaises(ValueError):
             service(service_type='geocoding', service_name='google')
Пример #2
0
 def fetch_rates(self,
                 base_currency: str,
                 currency: str = None,
                 rate_service: str = None,
                 date_obj: date = date.today(),
                 to_obj: date = None) -> []:
     """
     Get rates from a service for a base currency
     and stores them in the database
     :param rate_service: Service class to fetch from
     :param currency: currency to obtain rate for
     :param base_currency: base currency to get rate from
     :param date_obj: date to fetch rates at
     :param to_obj: end of range
     :return: QuerySet of Rate
     """
     service_name = rate_service or settings.RATE_SERVICE
     try:
         rates = service(service_type='rates',
                         service_name=service_name).fetch_rates(
                             base_currency=base_currency,
                             currency=currency,
                             date_obj=date_obj,
                             to_obj=to_obj)
         if not rates:
             return False
     except RatesNotAvailableError:
         return False
     return self.__sync_rates__(rates=rates, base_currency=base_currency)
Пример #3
0
 def test_google_reverse(self):
     """
     Testing Google revrese geocoding
     """
     if settings.GEOCODER_GOOGLE_KEY:
         geocoder = service(service_type='geocoding',
                            service_name='google',
                            key=settings.GEOCODER_GOOGLE_KEY)
         data = geocoder.reverse(lat=TEST_LAT, lng=TEST_LNG)
         self.assertIsNotNone(data)
     else:
         print("GEOCODER_GOOGLE_KEY not set, skipping test")
Пример #4
0
 def test_google_search(self):
     """
     Testing Google geocoding
     """
     if settings.GEOCODER_GOOGLE_KEY:
         geocoder = service(service_type='geocoding',
                            service_name='google',
                            key=settings.GEOCODER_GOOGLE_KEY)
         data = geocoder.search(address=TEST_ADDRESS)
         self.assertIsNotNone(data)
     else:
         print("GEOCODER_GOOGLE_KEY not set, skipping test")
Пример #5
0
 def test_pelias(self):
     """
     Testing Pelias service
     """
     if settings.GEOCODER_PELIAS_KEY:
         geocoder = service(service_type='geocoding',
                            service_name='pelias',
                            server_url=PELIAS_TEST_URL,
                            key=settings.GEOCODER_PELIAS_KEY)
         self.assertEqual(geocoder.coder_type, 'pelias')
     else:
         print("GEOCODER_PELIAS_KEY not set, skipping test")
Пример #6
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',
                            key=settings.GEOCODER_GOOGLE_KEY)
         data = geocoder.reverse(lat=TEST_LAT, lng=TEST_LNG)
         self.assertIsNotNone(data)
         self.assertIn("FR", geocoder.parse_countries(data))
     else:
         print("GEOCODER_GOOGLE_KEY not set, skipping test")
Пример #7
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',
                            key=settings.GEOCODER_GOOGLE_KEY)
         data = geocoder.search(address=TEST_ADDRESS)
         self.assertIsNotNone(data)
         self.assertIn("FR", geocoder.parse_countries(data))
     else:
         print("GEOCODER_GOOGLE_KEY not set, skipping test")
Пример #8
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,
                            key=settings.GEOCODER_PELIAS_KEY)
         data = geocoder.reverse(lat=TEST_LAT, lng=TEST_LNG)
         self.assertIsNotNone(data)
     else:
         print("GEOCODER_PELIAS_KEY not set, skipping test")
Пример #9
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,
                            key=settings.GEOCODER_PELIAS_KEY)
         data = geocoder.search(address=TEST_ADDRESS)
         self.assertIsNotNone(data)
     else:
         print("GEOCODER_PELIAS_KEY not set, skipping test")
Пример #10
0
 def geocode(self, request):
     """
     Find country by geocoding (giving address or POI)
     """
     geocoder = service(service_type='geocoding',
                        service_name=request.GET.get(
                            'geocoder', settings.GEOCODING_SERVICE),
                        key=request.GET.get('geocoder_api_key',
                                            settings.GEOCODER_GOOGLE_KEY))
     data = geocoder.search(address=request.GET.get('address'))
     countries = geocoder.countries(data)
     serializer = CountrySerializer(countries,
                                    many=True,
                                    context={'request': request})
     return Response(serializer.data)
Пример #11
0
 def reverse_geocode(self, request):
     """
     Find country by reverse geocoding (giving latitude and longitude)
     """
     geocoder = service(service_type='geocoding',
                        service_name=request.GET.get(
                            'geocoder', settings.GEOCODING_SERVICE),
                        key=request.GET.get('geocoder_api_key',
                                            settings.GEOCODER_GOOGLE_KEY))
     data = geocoder.reverse(lat=request.GET.get('lat'),
                             lng=request.GET.get('lon'))
     countries = geocoder.countries(data)
     serializer = CountrySerializer(countries,
                                    many=True,
                                    context={'request': request})
     return Response(serializer.data)
Пример #12
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,
                            key=settings.GEOCODER_PELIAS_KEY)
         data = geocoder.reverse(lat=TEST_LAT, lng=TEST_LNG)
         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")