Пример #1
0
 def test_xmpp_bot_client_init(self):
     arguments = MockArgumentParser()
     client = XmppBotClient(arguments)
     self.assertIsNotNone(client)
     self.assertIsNotNone(client.get_client_configuration())
     self.assertIsInstance(client.get_client_configuration(),
                           XmppConfiguration)
Пример #2
0
    def test_get_server_port(self):
        arguments = MockArgumentParser()
        client = XmppBotClient(arguments)
        self.assertIsNotNone(client)

        client.configuration.client_configuration._server = "Server"
        client.configuration.client_configuration._port = 8080

        server, port = client.get_server_port(client.configuration)
        self.assertIsNotNone(server)
        self.assertEqual("Server", server)
        self.assertEqual(8080, port)
Пример #3
0
    def test_message(self):
        arguments = MockArgumentParser()
        bot_client = XmppBotClient(arguments)
        self.assertIsNotNone(bot_client)
        xmpp_client = MockXmppClient(bot_client, "userid", "password")

        bot_client._bot = MockBot()
        bot_client.bot.answer = "Hiya"

        xmpp_client.message({"type": "chat", "from": "user123", "body": "Hello"})
        self.assertIsNotNone(xmpp_client.response)
        self.assertEqual("Hiya", xmpp_client.response)
Пример #4
0
    def test_get_username_password(self):
        arguments = MockArgumentParser()
        client = XmppBotClient(arguments)
        self.assertIsNotNone(client)

        bot = MockBot()
        bot.license_keys = MockLicenseKeys({"XMPP_USERNAME": "******", "XMPP_PASSWORD": "******"})

        username, password = client.get_username_password(bot.license_keys)
        self.assertIsNotNone(username)
        self.assertEquals("Username", username)
        self.assertIsNotNone(password)
        self.assertEquals("Password", password)
Пример #5
0
    def test_get_userid(self):
        arguments = MockArgumentParser()
        bot_client = XmppBotClient(arguments)
        self.assertIsNotNone(bot_client)
        xmpp_client = MockXmppClient(bot_client, "userid", "password")

        self.assertEqual("user123", xmpp_client.get_userid({"from": "user123"}))
Пример #6
0
    def test_get_question(self):
        arguments = MockArgumentParser()
        bot_client = XmppBotClient(arguments)
        self.assertIsNotNone(bot_client)
        xmpp_client = MockXmppClient(bot_client, "userid", "password")

        self.assertEqual("this is text", xmpp_client.get_question({"body": "this is text"}))
Пример #7
0
    def test_is_valid_message(self):
        arguments = MockArgumentParser()
        bot_client = XmppBotClient(arguments)
        self.assertIsNotNone(bot_client)
        xmpp_client = MockXmppClient(bot_client, "userid", "password")

        self.assertTrue(xmpp_client.is_valid_message({"type": "chat"}))
        self.assertTrue(xmpp_client.is_valid_message({"type": "normal"}))
Пример #8
0
 def test_xmpp_client_init(self):
     arguments = MockArgumentParser()
     bot_client = XmppBotClient(arguments)
     self.assertIsNotNone(bot_client)
     xmpp_client = MockXmppClient(bot_client, "userid", "password")
     self.assertIsNotNone(xmpp_client)
     self.assertEqual(bot_client, xmpp_client.bot_client)
     self.assertTrue(bool("session_start" in xmpp_client.event_handlers))
     self.assertTrue(bool("message" in xmpp_client.event_handlers))
Пример #9
0
    def test_register_plugins(self):
        arguments = MockArgumentParser()
        bot_client = XmppBotClient(arguments)
        self.assertIsNotNone(bot_client)
        xmpp_client = MockXmppClient(bot_client, "userid", "password")

        bot_client.configuration.client_configuration._xep_0030 = True
        bot_client.configuration.client_configuration._xep_0004 = True
        bot_client.configuration.client_configuration._xep_0060 = True
        bot_client.configuration.client_configuration._xep_0199 = True

        xmpp_client.register_xep_plugins(bot_client.configuration)

        self.assertTrue(bool("xep_0030" in xmpp_client.registered_plugins))
        self.assertTrue(bool("xep_0004" in xmpp_client.registered_plugins))
        self.assertTrue(bool("xep_0060" in xmpp_client.registered_plugins))
        self.assertTrue(bool("xep_0199" in xmpp_client.registered_plugins))
Пример #10
0
 def __init__(self, argument_parser=None):
     XmppBotClient.__init__(self, argument_parser)
     self.mock_xmpp_client = None
Пример #11
0
 def test_xmpp_client(self):
     arguments = MockArgumentParser()
     client = XmppBotClient(arguments)
     self.assertIsNotNone(client)