Exemplo n.º 1
0
 def test_verify_api_key_usage_inactive(self):
     arguments = MockArgumentParser()
     client = SanicRestBotClient("sanic", arguments)
     self.assertIsNotNone(client)
     client.configuration.client_configuration._use_api_keys = False
     request = unittest.mock.Mock()
     self.assertEquals((None, None),
                       client.verify_api_key_usage(request))
Exemplo n.º 2
0
        def test_get_api_key(self):
            arguments = MockArgumentParser()
            client = SanicRestBotClient("sanic", arguments)

            request = unittest.mock.Mock()
            request.raw_args = {}
            request.raw_args['apikey'] = '11111111'

            self.assertEquals('11111111', client.get_api_key(request))
Exemplo n.º 3
0
        def test_get_question(self):
            arguments = MockArgumentParser()
            client = SanicRestBotClient("sanic", arguments)
            self.assertIsNotNone(client)

            request = unittest.mock.Mock()
            request.raw_args = {}
            request.raw_args['question'] = 'Hello'

            self.assertEquals("Hello", client.get_question(request))
Exemplo n.º 4
0
        def test_get_userid(self):
            arguments = MockArgumentParser()
            client = SanicRestBotClient("sanic", arguments)
            self.assertIsNotNone(client)

            request = unittest.mock.Mock()
            request.raw_args = {}
            request.raw_args['userid'] = '1234567890'

            self.assertEquals("1234567890", client.get_userid(request))
Exemplo n.º 5
0
        def test_format_success_response(self):
            arguments = MockArgumentParser()
            client = SanicRestBotClient("sanic", arguments)
            self.assertIsNotNone(client)

            response = client.format_success_response("1234567890", "Hello",
                                                      "Hi")
            self.assertIsNotNone(response)
            self.assertEquals("1234567890", response['userid'])
            self.assertEquals("Hello", response['question'])
            self.assertEquals("Hi", response['answer'])
Exemplo n.º 6
0
 def test_verify_api_key_usage_active(self):
     arguments = MockArgumentParser()
     client = SanicRestBotClient("sanic", 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.load_api_keys()
     request = unittest.mock.Mock()
     request.raw_args = {}
     request.raw_args['apikey'] = '11111111'
     self.assertEquals((None, None),
                       client.verify_api_key_usage(request))
Exemplo n.º 7
0
 def test_rest_client_init(self):
     arguments = MockArgumentParser()
     client = SanicRestBotClient("sanic", arguments)
     self.assertIsNotNone(client)
Exemplo n.º 8
0
 def __init__(self, argument_parser=None):
     SanicRestBotClient.__init__(self, "sanic", argument_parser)
     self.aborted = False
     self.answer = None
     self.ask_question_exception = False