예제 #1
0
 def test_reverse_geo_lookup_bad_data(self, req_mock):
     req_mock.get(
         'http://service-location-service:1555/v1/location/reversegeo',
         text='{"addressComponents": {}}')
     loc = Location(coordinates=(50.0, 8.0))
     result = loc._reverse_geo_lookup()
     self.assertIsNone(loc._text)
예제 #2
0
 def test_forward_geo_lookup_ok(self, req_mock):
     req_mock.get('http://service-location-service:1555/v1/location/geo',
                  text='{"lat": 50.0, "lng": 8.0}')
     loc = Location('some place')
     result = loc._forward_geo_lookup()
     self.assertEqual(result, None)
     self.assertEqual(loc._coordinates, (50.0, 8.0))
예제 #3
0
 def test_reverse_geo_lookup_ok(self, req_mock):
     req_mock.get(
         'http://service-location-service:1555/v1/location/reversegeo',
         text='{"addressComponents": {"city": "some place"}}')
     loc = Location(coordinates=(50.0, 8.0))
     result = loc._reverse_geo_lookup()
     self.assertEqual(result, None)
     self.assertEqual(loc._text, 'some place')
예제 #4
0
 def test_timezone_with_data_from_location_service(self, req_mock):
     req_mock.get(
         'http://service-location-service:1555/v1/location/geo',
         text=
         '{"lat": 50.0, "lng": 8.0, "timeZone": "Europe/Berlin", "address":{"addressComponents": {"city": "some place"}}}'
     )
     loc = Location('some place')
     loc._forward_geo_lookup()
     self.assertEqual(loc.timezone, 'Europe/Berlin')
     self.assertEqual(loc.text, 'some place')
예제 #5
0
 def test_auth_header(self, req_mock, session_mock, config_mock, log_mock):
     config_mock['service-location'] = {'auth_header': 'true'}
     req_mock.json = {
         "context": {
             "attributes": {
                 'location': 'Berlin'
             },
             "intent": "TELEKOM_Demo_Intent",
             "locale": "de",
             "tokens": {
                 "cvi": "eyJ123"
             },
             "clientAttributes": {}
         }
     }
     loc = Location('some place')
     coordinates = loc.coordinates
     log_mock.assert_called_with(
         'Adding CVI token to authorization header.')
     session_mock.__enter__().get.assert_called_once_with(
         'http://service-location-service:1555/v1/location/geo',
         headers={
             'Accept': 'application/json',
             'Content-Type': 'application/json',
             'Authorization': 'Bearer eyJ123'
         },
         params={'text': 'some place'})
예제 #6
0
 def test_coordinates_text(self, req_mock):
     req_mock.get('http://service-location-service:1555/v1/location/geo',
                  text='''{
                  "lat": 50.0,
                  "lng": 8.0,
                  "timeZone": "Europe/Berlin",
                  "location":{
                     "addressComponents": {"city": "some place"}
                  }}''')
     self.assertEqual(Location('some place').coordinates, (50.0, 8.0))
예제 #7
0
 def test_reverse_geo_lookup_server_error(self, req_mock, log_mock):
     req_mock.get(
         'http://service-location-service:1555/v1/location/reversegeo',
         text='{}',
         status_code=500)
     loc = Location(coordinates=(50.0, 8.0))
     with self.assertRaises(BadHttpResponseCodeException):
         loc._reverse_geo_lookup()
     req_mock.get(
         'http://service-location-service:1555/v1/location/reversegeo',
         text='not a json')
     loc = Location('some place', coordinates=(50.0, 8.0))
     loc._reverse_geo_lookup()
     self.assertEqual(loc._text, 'some place')
예제 #8
0
 def test_forward_geo_lookup_bad_data(self, req_mock):
     req_mock.get('http://service-location-service:1555/v1/location/geo',
                  text='{}')
     loc = Location('some place')
     self.assertEqual(loc._text, 'some place')
     loc = Location(language='de')
     with self.assertRaises(ValueError):
         loc._forward_geo_lookup()
예제 #9
0
 def test_text_present(self):
     self.assertEqual(Location('some place').text, 'some place')
예제 #10
0
 def test_text_lookup_failed(self):
     loc = Location(coordinates=(50.0, 8.0))
     loc._reverse_lookup_failed = True
     from skill_sdk.services.location import GeoLookupError
     with self.assertRaises(GeoLookupError):
         loc.text
예제 #11
0
 def test_coordinates_present(self):
     self.assertEqual(
         Location(coordinates=(50.0, 8.0)).coordinates, (50.0, 8.0))
예제 #12
0
 def test_reverse_geo_lookup_no_coordinates(self):
     loc = Location('some place')
     with self.assertRaises(ValueError):
         loc._reverse_geo_lookup()
예제 #13
0
 def test_reverse_geo_lookup_failed_before(self):
     loc = Location(coordinates=(50.0, 8.0))
     loc._reverse_lookup_failed = True
     result = loc._reverse_geo_lookup()
     self.assertEqual(result, None)
     self.assertEqual(loc._text, None)
예제 #14
0
 def test_forward_geo_lookup_server_error(self, req_mock):
     req_mock.get('http://service-location-service:1555/v1/location/geo',
                  status_code=500)
     loc = Location('some place')
     with self.assertRaises(BadHttpResponseCodeException):
         loc._forward_geo_lookup()
예제 #15
0
 def test_forward_geo_lookup_not_valid_json(self, req_mock):
     req_mock.get('http://service-location-service:1555/v1/location/geo',
                  text='not a json')
     loc = Location('some place')
     loc._forward_geo_lookup()
     self.assertEqual(loc._text, 'some place')
예제 #16
0
 def test_text_coordinates(self, req_mock):
     req_mock.get(
         'http://service-location-service:1555/v1/location/reversegeo',
         text='{"addressComponents": {"city": "some place"}}')
     self.assertEqual(Location(coordinates=(50.0, 8.0)).text, 'some place')
예제 #17
0
 def test_coordinates_lookup_failed(self, req_mock):
     loc = Location('some place')
     loc._forward_lookup_failed = True
     self.assertIsNone(loc.coordinates)
예제 #18
0
 def test_timezone_with_no_data_from_location_service(self, req_mock):
     req_mock.get('http://service-location-service:1555/v1/location/geo',
                  text='{"lat": 50.0, "lng": 8.0}')
     loc = Location('some place')
     loc._forward_geo_lookup()
     self.assertEqual(loc.timezone, 'Europe/Berlin')