コード例 #1
0
 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))
コード例 #2
0
    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))
コード例 #3
0
    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))
コード例 #4
0
ファイル: test_client.py プロジェクト: tiagotrassi/webchatbot
    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))
コード例 #5
0
ファイル: test_client.py プロジェクト: tiagotrassi/webchatbot
    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'])
コード例 #6
0
ファイル: test_client.py プロジェクト: tiagotrassi/webchatbot
    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))
コード例 #7
0
 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))
コード例 #8
0
ファイル: test_client.py プロジェクト: whackur/chatbot
    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'])
コード例 #9
0
    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'])
コード例 #10
0
    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'])
コード例 #11
0
 def test_rest_client_init(self):
     arguments = MockArgumentParser()
     client = FlaskRestBotClient("flask", arguments)
     self.assertIsNotNone(client)