def test_verify_api_key_usage_inactive(self): arguments = MockArgumentParser() client = FlaskRestBotClient("flask", arguments) self.assertIsNotNone(client) client.configuration.client_configuration._use_api_keys = False request = unittest.mock.Mock() self.assertTrue(client.api_keys.verify_api_key_usage(request))
def test_get_api_key(self): arguments = MockArgumentParser() client = FlaskRestBotClient("flask", arguments) request = unittest.mock.Mock() request.args = {} request.args['apikey'] = '11111111' self.assertEqual('11111111', client.api_keys.get_api_key(request))
def test_get_userid(self): arguments = MockArgumentParser() client = FlaskRestBotClient("flask", arguments) self.assertIsNotNone(client) request = unittest.mock.Mock() request.data = b'{"userId": "1234567890"}' self.assertEqual("1234567890", client.get_userid(request))
def test_get_question(self): arguments = MockArgumentParser() client = FlaskRestBotClient("flask", arguments) self.assertIsNotNone(client) request = unittest.mock.Mock() request.args = {} request.args['question'] = 'Hello' self.assertEqual("Hello", client.get_question(request))
def test_format_success_response(self): arguments = MockArgumentParser() client = FlaskRestBotClient("flask", arguments) self.assertIsNotNone(client) response = client.format_success_response("1234567890", "Hello", "Hi") self.assertIsNotNone(response) self.assertEqual("1234567890", response['userid']) self.assertEqual("Hello", response['question']) self.assertEqual("Hi", response['answer'])
def test_get_userid(self): arguments = MockArgumentParser() client = FlaskRestBotClient("flask", arguments) self.assertIsNotNone(client) request = unittest.mock.Mock() request.args = {} request.args['userid'] = '1234567890' self.assertEqual("1234567890", client.get_userid(request))
def test_verify_api_key_usage_active(self): arguments = MockArgumentParser() client = FlaskRestBotClient("flask", arguments) self.assertIsNotNone(client) client.configuration.client_configuration._use_api_keys = True client.configuration.client_configuration._api_key_file = os.path.dirname(__file__) + os.sep + ".." + os.sep + ".." + os.sep + "api_keys.txt" client.initialise() request = unittest.mock.Mock() request.args = {} request.args['apikey'] = '11111111' self.assertTrue(client.api_keys.verify_api_key_usage(request))
def test_format_error_response(self): arguments = MockArgumentParser() client = FlaskRestBotClient("flask", arguments) self.assertIsNotNone(client) response = client.format_error_response("1234567890", "Hello", "Something Bad") self.assertIsNotNone(response) self.assertEquals("1234567890", response['userid']) self.assertEquals("Hello", response['question']) self.assertEquals("", response['answer']) self.assertEquals("Something Bad", response['error'])
def test_ask_question(self): arguments = MockArgumentParser() client = FlaskRestBotClient("yadlan", arguments) self.assertIsNotNone(client) client.configuration.client_configuration._debug = True request = unittest.mock.Mock() request.data = b'{"userId": "1234567890", "utterance": "Hello"}' response, _ = client.process_request(request) self.assertIsNotNone(response) self.assertEqual("1234567890", response['userId']) self.assertEqual("Hello.", response['utterance']) self.assertEqual("", response['response'])
def test_format_success_response(self): arguments = MockArgumentParser() client = FlaskRestBotClient("flask", arguments) self.assertIsNotNone(client) request = unittest.mock.Mock() request.data = b'{"userId": "1234567890"}' userInfo = UserInfo(client, request) response = client.format_success_response("1234567890", "Hello", "Hi", userInfo) self.assertIsNotNone(response) self.assertEqual("1234567890", response['userId']) self.assertEqual("Hello", response['utterance']) self.assertEqual("Hi", response['response']) self.assertEqual("None", response['topic'])
def test_rest_client_init(self): arguments = MockArgumentParser() client = FlaskRestBotClient("flask", arguments) self.assertIsNotNone(client)