def test_converter(self): self.assertEqual(convert('2106-12-31T12:30', datetime.date), datetime.date(2106, 12, 31)) self.assertEqual(convert('2106-12-31T12:30', datetime.datetime), datetime.datetime(2106, 12, 31, 12, 30, 00)) self.assertEqual(convert('2106-12-31T12:30', datetime.time), datetime.time(12, 30, 00)) self.assertEqual(convert('2106-12-31T12:30', str), '2106-12-31T12:30') self.assertEqual(convert('12.30', float), 12.3) self.assertEqual(convert('off', bool), False) self.assertEqual(convert('1', bool), True) self.assertEqual(convert('ja', 'str'), 'ja') self.assertEqual(convert('some place', Location), Location('some place')) self.assertEqual(convert(Location('some place'), Location), Location('some place')) self.assertEqual(convert('PT1H5M6S', datetime.timedelta), datetime.timedelta(hours=1, minutes=5, seconds=6)) delta = convert('PT1H5M6S', datetime.timedelta) self.assertEqual(convert(delta, datetime.timedelta), delta) with self.assertRaises(ValueError): convert('Something', datetime.time) with self.assertRaises(ValueError): convert('12.30', int) with self.assertRaises(ValueError): convert('Ja', bool) with self.assertRaises(ValueError): convert(1, bool)
def test_setup_services(self, req_mock, config_mock, log_mock): config_mock['zipkin'] = {'sample_rate': '100'} config_mock['service-text'] = {'active': 'true'} config_mock['service-location'] = {'active': 'true'} with patch('skill_sdk.services.text.setup_service') as text_mock, \ patch('skill_sdk.services.zipkin.setup_service') as zipkin_mock: importlib.reload(skill_sdk.entities) from skill_sdk.entities import Location loc = Location('Berlin') self.assertEqual(loc.coordinates, None) setup_services() text_mock.assert_called_once() zipkin_mock.assert_called_once() req_mock.get( 'http://service-location-service:1555/v1/location/geo', text='{"lat": 50.0, "lng": 8.0}') from skill_sdk.services import location importlib.reload(skill_sdk.services.location) from skill_sdk.entities import Location loc = Location('Berlin') self.assertEqual(loc.coordinates, (50, 8))
def test_init_location_params(self): loc = Location(location_text='some place', language='DE', country='Deutschland', timezone='Europe/Berlin') self.assertEqual(loc.text, 'some place') self.assertEqual(loc.timezone, 'Europe/Berlin') self.assertEqual(loc.coordinates, None) self.assertEqual(loc._country, 'Deutschland') self.assertEqual(loc._language, 'DE')
def test_init_coordinates(self): loc = Location(coordinates=(50.0, 8.0)) self.assertEqual(loc.coordinates, (50.0, 8.0)) self.assertEqual(loc.text, None)
def test_init_text(self): loc = Location('some place') self.assertEqual(loc.text, 'some place') self.assertEqual(loc._text, 'some place') self.assertEqual(loc, Location('some place')) self.assertNotEqual(loc, 1)
def test_str_both(self): loc = Location('some place', coordinates=(50.0, 8.0)) self.assertEqual(str(loc), '<Location text="some place" coords=(50.0, 8.0)>')
def test_str_none(self): loc = Location('some place') loc._text = None self.assertEqual(str(loc), '<Location text="None" coords=None>')
def test_coordinates_present(self): self.assertEqual( Location(coordinates=(50.0, 8.0)).coordinates, (50.0, 8.0))
def test_text_present(self): self.assertEqual(Location('some place').text, 'some place')
def test_forward_geo_lookup_do_not_raise_error_if_text_is_None(self): loc = Location(language='DE') loc._text = '' self.assertEqual(loc._language, 'DE')
def test_init_none(self): with self.assertRaises(ValueError): Location()