Пример #1
0
 def test_calculate(self):
     """Test calculate command
     """
     pushMessage('!calculate 1+2')
     self.assertEqual(popMessage(), '3')
     
     pushMessage('!calculate 1+2*(5-1)')
     self.assertEqual(popMessage(), '9')
Пример #2
0
    def test_help(self):
        pushMessage('!help ErrBot')
        response = popMessage()
        self.assertIn('Available commands for ErrBot', response)
        self.assertIn('!about', response)

        pushMessage('!help beurk')
        self.assertEqual('That command is not defined.', popMessage())
Пример #3
0
    def test_help(self):
        pushMessage('!help ErrBot')
        response = popMessage()
        self.assertIn('Available commands for ErrBot', response)
        self.assertIn('!about', response)

        pushMessage('!help beurk')
        self.assertEqual('That command is not defined.', popMessage())
Пример #4
0
    def setUp(self, extra_test_file=None):
        plugin_dir = os.path.dirname(os.path.realpath(__file__)) + os.sep + 'webhooks_tests'
        super(TestWebhooks, TestWebhooks).setUp(self, extra_test_file=plugin_dir)

        pushMessage("!config Webserver {'HOST': 'localhost', 'PORT': 3141, 'SSL':  None}")
        popMessage()
        while not webserver_ready('localhost', 3141):
            logging.debug("Webserver not ready yet, sleeping 0.1 second")
            sleep(0.1)
Пример #5
0
    def setUpClass(cls, extra_test_file=None):
        plugin_dir = os.path.dirname(
            os.path.realpath(__file__)) + os.sep + 'webhooks_tests'
        super(TestWebhooks, cls).setUpClass(extra_test_file=plugin_dir)

        pushMessage(
            "!config Webserver {'HOST': 'localhost', 'PORT': 3141, 'SSL':  None}"
        )
        popMessage()
        while not webserver_ready('localhost', 3141):
            logging.debug("Webserver not ready yet, sleeping 0.1 second")
            sleep(0.1)
Пример #6
0
    def test_unblacklist_and_blacklist(self):
        pushMessage('!unblacklist nosuchplugin')
        m = popMessage()
        self.assertIn("nosuchplugin isn't a valid plugin name. The current plugins are", m)
        self.assertIn('ChatRoom', m)

        pushMessage('!blacklist nosuchplugin')
        m = popMessage()
        self.assertIn("nosuchplugin isn't a valid plugin name. The current plugins are", m)
        self.assertIn('ChatRoom', m)

        pushMessage('!blacklist ChatRoom')
        self.assertEqual("Plugin ChatRoom is now blacklisted", popMessage())

        pushMessage('!blacklist ChatRoom')
        self.assertEqual("Plugin ChatRoom is already blacklisted", popMessage())

        pushMessage("!status")
        self.assertIn("[B,L] ChatRoom", popMessage())

        pushMessage('!unblacklist ChatRoom')
        self.assertEqual('Plugin ChatRoom removed from blacklist', popMessage())

        pushMessage('!unblacklist ChatRoom')
        self.assertEqual('Plugin ChatRoom is not blacklisted', popMessage())

        pushMessage("!status")
        self.assertIn("[L] ChatRoom", popMessage())
Пример #7
0
    def test_config_cycle(self):
        # test the full configuration cycle help, get set and export, import
        pushMessage('!zap configs')
        self.assertIn('Done', popMessage())

        pushMessage('!config Webserver')
        self.assertIn('Copy paste and adapt', popMessage())

        pushMessage("!config Webserver {'HOST': 'localhost', 'PORT': 3141, 'SSL':  None}")
        self.assertIn('Plugin configuration done.', popMessage())

        pushMessage('!config Webserver')
        self.assertIn('localhost', popMessage())

        pushMessage('!export configs')
        configs = popMessage()
        self.assertIn('localhost', configs)
        obj = literal_eval(configs)  # be sure it is parseable
        obj['Webserver']['HOST'] = 'localhost'

        pushMessage('!import configs ' + repr(obj))
        self.assertIn('Import is done correctly', popMessage())

        pushMessage('!config Webserver')
        self.assertIn('localhost', popMessage())
Пример #8
0
    def test_config_cycle(self):
        # test the full configuration cycle help, get set and export, import
        pushMessage('!zap configs')
        self.assertIn('Done', popMessage())

        pushMessage('!config Webserver')
        m = popMessage()
        self.assertIn('Default configuration for this plugin (you can copy and paste this directly as a command)', m)
        self.assertNotIn('Current configuration', m)

        pushMessage("!config Webserver {'HOST': 'localhost', 'PORT': 3141, 'SSL':  None}")
        self.assertIn('Plugin configuration done.', popMessage())

        pushMessage('!config Webserver')
        m = popMessage()
        self.assertIn('Current configuration', m)
        self.assertIn('localhost', m)

        pushMessage('!export configs')
        configs = popMessage()
        self.assertIn('localhost', configs)
        obj = literal_eval(configs)  # be sure it is parseable
        obj['Webserver']['HOST'] = 'localhost'

        pushMessage('!import configs ' + repr(obj))
        self.assertIn('Import is done correctly', popMessage())

        pushMessage('!config Webserver')
        self.assertIn('localhost', popMessage())
Пример #9
0
    def test_config_cycle(self):
        # test the full configuration cycle help, get set and export, import
        pushMessage('!zap configs')
        self.assertIn('Done', popMessage())

        pushMessage('!config Webserver')
        self.assertIn('Copy paste and adapt', popMessage())

        pushMessage(
            "!config Webserver {'HOST': 'localhost', 'PORT': 3141, 'SSL':  None}"
        )
        self.assertIn('Plugin configuration done.', popMessage())

        pushMessage('!config Webserver')
        self.assertIn('localhost', popMessage())

        pushMessage('!export configs')
        configs = popMessage()
        self.assertIn('localhost', configs)
        obj = literal_eval(configs)  # be sure it is parseable
        obj['Webserver']['HOST'] = 'localhost'

        pushMessage('!import configs ' + repr(obj))
        self.assertIn('Import is done correctly', popMessage())

        pushMessage('!config Webserver')
        self.assertIn('localhost', popMessage())
Пример #10
0
    def test_generate_certificate_creates_usable_cert(self):
        key_path = os.sep.join((BOT_DATA_DIR, "webserver_key.pem"))
        cert_path = os.sep.join((BOT_DATA_DIR, "webserver_certificate.pem"))

        pushMessage("!generate_certificate")
        self.assertTrue("Generating" in popMessage(timeout=1))

        # Generating a certificate could be slow on weak hardware, so keep a safe
        # timeout on the first popMessage()
        self.assertTrue("successfully generated" in popMessage(timeout=60))
        self.assertTrue("is recommended" in popMessage(timeout=1))
        self.assertTrue(key_path in popMessage(timeout=1))

        pushMessage(
            "!config Webserver {'HOST': 'localhost', 'PORT': 3141, 'SSL': {'certificate': '%s', 'key': '%s', 'host': 'localhost', 'port': 3142, 'enabled': True}}"
            % (cert_path, key_path))
        popMessage()

        while not webserver_ready('localhost', 3142):
            logging.debug("Webserver not ready yet, sleeping 0.1 second")
            sleep(0.1)

        self.assertEquals(
            requests.post('https://localhost:3142/webhook1/',
                          JSONOBJECT,
                          verify=False).text, repr(json.loads(JSONOBJECT)))
Пример #11
0
	def test_end_match(self):
		pushMessage('!start match Honduras vs. Poland')
		popMessage()
		pushMessage('!score 1-1 Honduras')
		popMessage()
		pushMessage('!end match 0-0 Honduras')
		self.assertIn('Closed match', popMessage())
		pushMessage('!scoreboard')
		self.assertIn('gbin:1', popMessage())
Пример #12
0
    def test_history(self):
        from errbot.holder import bot

        pushMessage('!uptime')
        popMessage()
        pushMessage('!history')
        self.assertIn('uptime', popMessage())

        orig_sender = bot.sender
        try:
            # Pretend to be someone else. History should be empty
            bot.sender = 'non_default_person@localhost'
            pushMessage('!history')
            self.assertRaises(Empty, popMessage, block=False)
            pushMessage('!echo should be seperate history')
            popMessage()
            pushMessage('!history')
            self.assertIn('should be seperate history', popMessage())
        finally:
            bot.sender = orig_sender
        # Pretend to be the original person again. History should still contain uptime
        pushMessage('!history')
        self.assertIn('uptime', popMessage())
Пример #13
0
    def test_history(self):
        from errbot.holder import bot

        pushMessage('!uptime')
        popMessage()
        pushMessage('!history')
        self.assertIn('uptime', popMessage())

        orig_sender = bot.sender
        try:
            # Pretend to be someone else. History should be empty
            bot.sender = 'non_default_person@localhost'
            pushMessage('!history')
            self.assertRaises(Empty, popMessage, block=False)
            pushMessage('!echo should be seperate history')
            popMessage()
            pushMessage('!history')
            self.assertIn('should be seperate history', popMessage())
        finally:
            bot.sender = orig_sender
        # Pretend to be the original person again. History should still contain uptime
        pushMessage('!history')
        self.assertIn('uptime', popMessage())
Пример #14
0
    def test_generate_certificate_creates_usable_cert(self):
        key_path = os.sep.join((BOT_DATA_DIR, "webserver_key.pem"))
        cert_path = os.sep.join((BOT_DATA_DIR, "webserver_certificate.pem"))

        pushMessage("!generate_certificate")
        self.assertTrue("Generating" in popMessage(timeout=1))

        # Generating a certificate could be slow on weak hardware, so keep a safe
        # timeout on the first popMessage()
        self.assertTrue("successfully generated" in popMessage(timeout=60))
        self.assertTrue("is recommended" in popMessage(timeout=1))
        self.assertTrue(key_path in popMessage(timeout=1))

        pushMessage("!config Webserver {'HOST': 'localhost', 'PORT': 3141, 'SSL': {'certificate': '%s', 'key': '%s', 'host': 'localhost', 'port': 3142, 'enabled': True}}" % (cert_path, key_path))
        popMessage()

        while not webserver_ready('localhost', 3142):
            logging.debug("Webserver not ready yet, sleeping 0.1 second")
            sleep(0.1)

        self.assertEquals(
            requests.post('https://localhost:3142/webhook1/', JSONOBJECT, verify=False).text,
            repr(json.loads(JSONOBJECT))
        )
Пример #15
0
 def test_uptime(self):
     pushMessage('!uptime')
     self.assertIn('I\'ve been up for', popMessage())
Пример #16
0
 def test_battle(self):
     self.assertCommand('!battle toto vs titi', 'left')
     self.assertIn('WINNER', popMessage())
Пример #17
0
 def test_webserver_plugin_ok(self):
     pushMessage("!webstatus")
     self.assertIn("echo", popMessage())
Пример #18
0
 def test_logtail(self):
     pushMessage('!log tail')
     self.assertIn('DEBUG', popMessage())
Пример #19
0
 def test_root_help(self):
     pushMessage('!help')
     self.assertIn('Available help', popMessage())
Пример #20
0
 def test_uptime(self):
     pushMessage('!uptime')
     self.assertIn('I\'ve been up for', popMessage())
Пример #21
0
 def test_history(self):
     pushMessage('!uptime')
     popMessage()
     pushMessage('!history')
     self.assertIn('uptime', popMessage())
Пример #22
0
 def test_root_help(self):
     pushMessage('!help')
     self.assertIn('Available help', popMessage())
Пример #23
0
 def test_eliza(self):
     pushMessage('!eliza Hello')
     ref = self.assertRegex if PY3 else self.assertRegexpMatches
     ref(popMessage(), r"Hi|Hello")
Пример #24
0
 def test_logtail(self):
     pushMessage('!log tail')
     self.assertIn('DEBUG', popMessage())
Пример #25
0
    def test_load_reload_and_unload(self):
        for command in ('load', 'reload', 'unload'):
            pushMessage("!{}".format(command))
            m = popMessage()
            self.assertIn('Please tell me which of the following plugins to reload', m)
            self.assertIn('ChatRoom', m)

            pushMessage('!{} nosuchplugin'.format(command))
            m = popMessage()
            self.assertIn("nosuchplugin isn't a valid plugin name. The current plugins are", m)
            self.assertIn('ChatRoom', m)

        pushMessage('!reload ChatRoom')
        self.assertEqual('Plugin ChatRoom deactivated', popMessage())
        self.assertEqual('Plugin ChatRoom activated', popMessage())

        pushMessage("!status")
        self.assertIn("[L] ChatRoom", popMessage())

        pushMessage('!unload ChatRoom')
        self.assertEqual('Plugin ChatRoom deactivated', popMessage())

        pushMessage("!status")
        self.assertIn("[U] ChatRoom", popMessage())

        pushMessage('!unload ChatRoom')
        self.assertEqual('ChatRoom is not currently loaded', popMessage())

        pushMessage('!load ChatRoom')
        self.assertEqual('Plugin ChatRoom activated', popMessage())

        pushMessage("!status")
        self.assertIn("[L] ChatRoom", popMessage())

        pushMessage('!load ChatRoom')
        self.assertEqual('ChatRoom is already loaded', popMessage())

        pushMessage('!unload ChatRoom')
        self.assertEqual('Plugin ChatRoom deactivated', popMessage())
        pushMessage('!reload ChatRoom')
        self.assertEqual('Plugin ChatRoom not in active list', popMessage())
        self.assertEqual('Plugin ChatRoom activated', popMessage())

        pushMessage('!blacklist ChatRoom')
        self.assertEqual("Plugin ChatRoom is now blacklisted", popMessage())

        pushMessage("!status")
        self.assertIn("[B,L] ChatRoom", popMessage())

        # Needed else configuration for this plugin gets saved which screws up
        # other tests
        pushMessage('!unblacklist ChatRoom')
        popMessage()
Пример #26
0
 def test_apropos(self):
     pushMessage('!apropos about')
     self.assertIn('!about: Returns some', popMessage())
Пример #27
0
 def test_encoding_preservation(self):
     pushMessage('!echo へようこそ')
     self.assertEquals('へようこそ', popMessage())
Пример #28
0
 def test_status(self):
     pushMessage('!status')
     self.assertIn('Yes I am alive', popMessage())
Пример #29
0
 def test_encoding_preservation(self):
     pushMessage('!echo へようこそ')
     self.assertEquals('へようこそ', popMessage())
Пример #30
0
 def test_eliza(self):
     pushMessage('!eliza Hello')
     ref = self.assertRegex if PY3 else self.assertRegexpMatches
     ref(popMessage(), r"Hi|Hello")
Пример #31
0
 def test_about(self):
     pushMessage('!about')
     self.assertIn('Err version', popMessage())
Пример #32
0
	def test_scoreboard_empty(self):
		pushMessage('!init')
		popMessage()
		pushMessage('!scoreboard')
		self.assertIn('Scoreboard is empty', popMessage())
Пример #33
0
 def test_status(self):
     pushMessage('!status')
     self.assertIn('Yes I am alive', popMessage())
Пример #34
0
	def test_start_match(self):
		pushMessage('!start match Honduras vs. Poland')
		self.assertIn('Started match', popMessage())
Пример #35
0
 def test_apropos(self):
     pushMessage('!apropos about')
     self.assertIn('!about: Returns some', popMessage())
Пример #36
0
 def test_battle(self):
     self.assertCommand('!battle toto vs titi', 'left')
     self.assertIn('WINNER', popMessage())
Пример #37
0
 def test_webserver_plugin_ok(self):
     pushMessage("!webstatus")
     self.assertIn("echo", popMessage())
Пример #38
0
 def test_borat(self):
     pushMessage('!borat')
     self.assertIn('DEVOPS_BORAT', popMessage())
Пример #39
0
    def test_plugin_cycle(self):
        pushMessage('!repos install git://github.com/gbin/err-helloworld.git')
        self.assertIn('err-helloworld', popMessage())
        self.assertIn('reload', popMessage())

        pushMessage('!repos export')  # should appear in the export
        self.assertEqual("{'err-helloworld': 'git://github.com/gbin/err-helloworld.git'}", popMessage())

        pushMessage('!help hello')  # should appear in the help
        self.assertEqual("this command says hello", popMessage())

        pushMessage('!hello')  # should respond
        self.assertEqual('Hello World !', popMessage())

        pushMessage('!reload HelloWorld')
        self.assertEqual('Plugin HelloWorld deactivated / Plugin HelloWorld activated', popMessage())

        pushMessage('!hello')  # should still respond
        self.assertEqual('Hello World !', popMessage())

        pushMessage('!unload HelloWorld')
        self.assertEqual('Plugin HelloWorld deactivated', popMessage())

        pushMessage('!hello')  # should not respond
        self.assertIn('Command "hello" not found', popMessage())

        pushMessage('!load HelloWorld')
        self.assertEqual('Plugin HelloWorld activated', popMessage())

        pushMessage('!hello')  # should respond back
        self.assertEqual('Hello World !', popMessage())

        pushMessage('!repos uninstall err-helloworld')
        self.assertEqual('/me is unloading plugin HelloWorld', popMessage())
        self.assertEqual('Plugins unloaded and repo err-helloworld removed', popMessage())

        pushMessage('!hello')  # should not respond
        self.assertIn('Command "hello" not found', popMessage())
Пример #40
0
 def test_coderwall(self):
     pushMessage('!coderwall gbin')
     self.assertIn('24PullRequests', popMessage())
     self.assertIn('Forked 20', popMessage())
Пример #41
0
 def test_calculate_with_exception(self):
     """Test calculate command with exception
     """
     pushMessage('!calculate 1+2)')
     self.assertEqual(popMessage(), 'Input is error!')
Пример #42
0
 def setUpClass(cls, extra_test_file=None):
     super(TestWebhooks, cls).setUpClass()
     pushMessage("!config Webserver {'HOST': 'localhost', 'PORT': 3141, 'SSL':  None}")
     popMessage()
Пример #43
0
    def test_plugin_cycle(self):
        pushMessage('!repos install git://github.com/gbin/err-helloworld.git')
        self.assertIn('err-helloworld', popMessage())
        self.assertIn('reload', popMessage())

        pushMessage('!repos export')  # should appear in the export
        self.assertEqual(
            "{'err-helloworld': 'git://github.com/gbin/err-helloworld.git'}",
            popMessage())

        pushMessage('!help hello')  # should appear in the help
        self.assertEqual("this command says hello", popMessage())

        pushMessage('!hello')  # should respond
        self.assertEqual('Hello World !', popMessage())

        pushMessage('!reload HelloWorld')
        self.assertEqual(
            'Plugin HelloWorld deactivated / Plugin HelloWorld activated',
            popMessage())

        pushMessage('!hello')  # should still respond
        self.assertEqual('Hello World !', popMessage())

        pushMessage('!unload HelloWorld')
        self.assertEqual('Plugin HelloWorld deactivated', popMessage())

        pushMessage('!hello')  # should not respond
        self.assertIn('Command "hello" not found', popMessage())

        pushMessage('!load HelloWorld')
        self.assertEqual('Plugin HelloWorld activated', popMessage())

        pushMessage('!hello')  # should respond back
        self.assertEqual('Hello World !', popMessage())

        pushMessage('!repos uninstall err-helloworld')
        self.assertEqual('/me is unloading plugin HelloWorld', popMessage())
        self.assertEqual('Plugins unloaded and repo err-helloworld removed',
                         popMessage())

        pushMessage('!hello')  # should not respond
        self.assertIn('Command "hello" not found', popMessage())
Пример #44
0
 def test_about(self):
     pushMessage('!about')
     self.assertIn('Err version', popMessage())