def test_get_default_response_nothing(self): config = ServiceConfiguration.from_data("generic", "test", "category") service = Service(config) client = TestClient() client_context = client.create_client_context("testuser") self.assertEqual("Service failed to return valid response", service._get_default_response(client_context))
def test_init_empty_config(self): config = ServiceConfiguration.from_data("generic", "test", "category") service = Service(config) self.assertIsNotNone(service) self.assertEqual(service.configuration, config) self.assertEquals([], service.patterns()) self.assertIsNone(service.get_default_aiml_file())
def test_from_yaml_with_rest(self): yaml_data = yaml.load(""" service: type: rest name: test category: test_category service_class: service.TestService default_response: Default Response default_srai: DEFAULT_SRAI default_aiml: test.aiml rest: retries: [10, 50, 100] timeout: 900 """, Loader=yaml.FullLoader) config = ServiceConfiguration.new_from_yaml(yaml_data, "test.yaml") self.assertIsNotNone(config) self.assertIsInstance(config, ServiceRESTConfiguration) self.assertEqual("test", config.name) self.assertEqual("test_category", config.category) self.assertEqual("test.yaml", config.storage) self.assertEqual("service.TestService", config.service_class) self.assertEqual(config.default_response, "Default Response") self.assertEqual(config.default_srai, "DEFAULT_SRAI") self.assertEqual(config.default_aiml, "test.aiml") self.assertEqual(config.retries, [10, 50, 100]) self.assertEqual(config.timeout, 900)
def setUp(self): client = SraixTestClient() self._client_context = client.create_client_context("testid") config = ServiceConfiguration(service_type="library") self._client_context.brain.service_handler.add_service( 'REST', MockGenericRESTService(config))
def test_from_mongo_with_rest(self): service = { "type": 'rest', "name": "test", "category": "test_category", "service_class": "service.TestService", "default_response": "Default Response", "default_srai": "DEFAULT_SRAI", "default_aiml": "test.aiml", "rest": { "timeout": 900, "retries": [10, 50, 100] } } config = ServiceConfiguration.from_mongo(service) self.assertIsNotNone(config) self.assertIsInstance(config, ServiceRESTConfiguration) self.assertEqual("test", config.name) self.assertEqual("test_category", config.category) self.assertEqual("mongo", config.storage) self.assertEqual("service.TestService", config.service_class) self.assertEqual(config.default_response, "Default Response") self.assertEqual(config.default_srai, "DEFAULT_SRAI") self.assertEqual(config.default_aiml, "test.aiml") self.assertEqual(config.retries, [10, 50, 100]) self.assertEqual(config.timeout, 900)
def test_from_yaml(self): yaml_data = yaml.load(""" service: name: test category: test_category service_class: service.TestService default_response: Default Response default_srai: DEFAULT_SRAI default_aiml: test.aiml """, Loader=yaml.FullLoader) config = ServiceConfiguration.new_from_yaml(yaml_data, "test.yaml") self.assertIsNotNone(config) self.assertIsInstance(config, ServiceConfiguration) self.assertEqual(config.service_type, 'generic') self.assertEqual("test", config.name) self.assertEqual("test_category", config.category) self.assertEqual("test.yaml", config.storage) self.assertEqual("service.TestService", config.service_class) self.assertEqual(config.default_response, "Default Response") self.assertEqual(config.default_srai, "DEFAULT_SRAI") self.assertEqual(config.default_aiml, "test.aiml")
def test_from_sql(self): mock_dao = Mock() mock_dao.name = "test" mock_dao.type = 'generic' mock_dao.category = "test_category" mock_dao.service_class = "service.TestService" mock_dao.default_response = "Default Response" mock_dao.default_srai = "DEFAULT_SRAI" mock_dao.default_aiml = "test.aiml" mock_dao.rest_retries = None mock_dao.rest_timeout = None config = ServiceConfiguration.from_sql(mock_dao) self.assertIsNotNone(config) self.assertIsInstance(config, ServiceConfiguration) self.assertEqual("test", config.name) self.assertEqual("test_category", config.category) self.assertEqual("sql", config.storage) self.assertEqual("service.TestService", config.service_class) self.assertEqual(config.default_response, "Default Response") self.assertEqual(config.default_srai, "DEFAULT_SRAI") self.assertEqual(config.default_aiml, "test.aiml")
def test_from_mongo(self): service = { "type": 'library', "name": "test", "category": "test_category", "service_class": "service.TestService", "default_response": "Default Response", "default_srai": "DEFAULT_SRAI", "default_aiml": "test.aiml" } config = ServiceConfiguration.from_mongo(service) self.assertIsNotNone(config) self.assertIsInstance(config, ServiceLibraryConfiguration) self.assertEqual("test", config.name) self.assertEqual("test_category", config.category) self.assertEqual("mongo", config.storage) self.assertEqual("service.TestService", config.service_class) self.assertEqual(config.default_response, "Default Response") self.assertEqual(config.default_srai, "DEFAULT_SRAI") self.assertEqual(config.default_aiml, "test.aiml")
def _do_summary(self): service = WikipediaService( ServiceConfiguration.from_data("library", "wikipedia", "search")) self.assertIsNotNone(service) response = service.summary("8 Out of 10 Cats Does Countdown") payload = self.assertResponse(response, 'summary', 'wikipedia', 'search')
def test_get_default_response_default_srai(self): config = ServiceConfiguration.from_data( "generic", "test", "category", default_srai="TEST SERVICE FAILURE") service = Service(config) client = TestClient() client_context = client.create_client_context("testuser") self.assertEqual("Default srai response", service._get_default_response(client_context))
def do_search(self): service = GNewsService(ServiceConfiguration.from_data("rest", "gnews", "news")) client = GNewsServiceTestClient() service.initialise(client) self.assertIsNotNone(service) response = service.search("CHATBOTS") self.assertResponse(response, 'search', "gnews", "news")
def test_init(self): service = MicrosoftNewsService( ServiceConfiguration.from_data( "rest", "microsoft.news", "news", url="https://chatilly.cognitiveservices.azure.com/bing/v7.0")) self.assertIsNotNone(service)
def _do_5_day_forecast(self): service = MetOfficeService(ServiceConfiguration.from_data("library", "metoffice", "weather")) self.assertIsNotNone(service) client = MetOfficeTestClient() service.initialise(client) response = service.forecast(56.0712, -3.1743, metoffer.DAILY) payload = self.assertResponse(response, 'forecast', 'metoffice', 'weather')
def do_topics(self): service = GNewsService(ServiceConfiguration.from_data("rest", "gnews", "news")) client = GNewsServiceTestClient() service.initialise(client) self.assertIsNotNone(service) response = service.topics("technology") self.assertResponse(response, 'topics', "gnews", "news")
def _do_search(self): service = WikipediaService( ServiceConfiguration.from_data("library", "wikipedia", "search")) self.assertIsNotNone(service) response = service.search("CHATBOTS") payload = self.assertResponse(response, 'search', 'wikipedia', 'search')
def test_load_default_aiml_by_class(self): config = ServiceConfiguration.from_data("generic", "test", "category") service = Service(config) self.assertIsNotNone(service) mock_aiml_parser = Mock() mock_aiml_parser.parse_from_file.return_value = True self.assertTrue(service.load_default_aiml(mock_aiml_parser))
def _load_conf_file(self, client_context, conf_file): with open(conf_file, 'r+', encoding="utf-8") as yml_data_file: yaml_data = yaml.load(yml_data_file, Loader=yaml.FullLoader) config = ServiceConfiguration.new_from_yaml(yaml_data, conf_file) client_context.brain.service_handler.load_service(config) client_context.brain.service_handler.post_initialise(client_context.brain)
def _do_sources(self): service = NewsAPIService(ServiceConfiguration.from_data("rest", "newsapi", "news")) self.assertIsNotNone(service) client = NewsAPIServiceTestClient() service.initialise(client) response = service.get_sources() self.assertResponse(response, 'get_sources', "newsapi", "news")
def _do_title_search(self): service = OMDBService(ServiceConfiguration.from_data("rest", "omdb", "film")) self.assertIsNotNone(service) client = OMDBServiceTestClient() service.initialise(client) response = service.title_search("Aliens") self.assertResponse(response, 'title_search', "omdb", "film")
def _do_everything(self): service = NewsAPIService(ServiceConfiguration.from_data("rest", "newsapi", "news")) self.assertIsNotNone(service) client = NewsAPIServiceTestClient() service.initialise(client) response = service.get_everything("chatbot") self.assertResponse(response, 'get_everything', "newsapi", "news")
def _do_conditions(self): service = AccuWeatherService(ServiceConfiguration.from_data("rest", "accuweather", "weather")) self.assertIsNotNone(service) client = AccuWeatherServiceTestClient() service.initialise(client) response = service.conditions("3385695") self.assertResponse(response, 'conditions', 'accuweather', 'weather')
def _do_timemachine(self): service = DarkSkyService( ServiceConfiguration.from_data("rest", "darksky", "weather")) self.assertIsNotNone(service) client = DarkSkyServiceTestClient() service.initialise(client) response = service.timemachine(56.0712, -3.1743, "255657600") self.assertResponse(response, 'timemachine', 'darksky', 'weather')
def _do_directions(self): service = GoogleDirectionsService( ServiceConfiguration.from_data("rest", "google", "directions")) self.assertIsNotNone(service) client = GoogleDirectionsServiceTestClient() service.initialise(client) response = service.get_directions("London", "Brighton") self.assertResponse(response, 'get_directions', "google", "directions")
def _do_ask(self): service = PandoraService( ServiceConfiguration.from_data("rest", "pandora", "chatbot")) self.assertIsNotNone(service) client = PandoraServiceTestClient() service.initialise(client) response = service.ask("Hello") self.assertResponse(response, 'ask', "pandora", "chatbot")
def _do_scrape(self): service = DuckDuckGoService( ServiceConfiguration.from_data("rest", "duckduckgo", "search")) self.assertIsNotNone(service) client = DuckDuckGoServiceTestClient() service.initialise(client) response = service.scrape("CHATBOTS") self.assertResponse(response, 'scrape', 'duckduckgo', 'search')
def _do_vac(self): service = GetGuidelinesService( ServiceConfiguration.from_data("rest", "getguidelines", "health")) self.assertIsNotNone(service) client = GetGuidelinesServiceTestClient() service.initialise(client) response = service.vac("dm,chf") self.assertResponse(response, 'vac', "getguidelines", "health")
def _do_placename(self): service = GeoNamesService(ServiceConfiguration.from_data("rest", "geonames", "geocode")) self.assertIsNotNone(service) client = GeoNamesServiceTestClient() service.initialise(client) response = service.latlng_for_placename("KY3 9UR") self.assertResponse(response, 'latlng_for_placename', "geonames", "geocode")
def _do_forecast(self): service = DarkSkyService( ServiceConfiguration.from_data("rest", "darksky", "weather")) self.assertIsNotNone(service) client = DarkSkyServiceTestClient() service.initialise(client) response = service.forecast(56.0712, -3.1743) self.assertResponse(response, 'forecast', 'darksky', 'weather')
def _do_postcode(self): service = GoogleGeoCodeService(ServiceConfiguration.from_data("rest", "google", "geocode")) self.assertIsNotNone(service) client = GoogleGeoCodeServiceTestClient() service.initialise(client) response = service.latlng_for_postcode("KY3 9UR") self.assertResponse(response, 'latlng_for_postcode', "google", "geocode")
def _do_short(self): service = WolframAlphaService( ServiceConfiguration.from_data("rest", "wolframalpha", "search")) self.assertIsNotNone(service) client = WolframAlphaServiceTestClient() service.initialise(client) response = service.short("How far is Los Angeles from New York") self.assertResponse(response, 'short', "wolframalpha", "search")