Example #1
0
 def test_plugin_add_extra_options(self):
     with fixtures.cleaned_tempdir() as path:
         test_file = path + "/t1.py"
         open(test_file, 'w').write(SAMPLE_ARGUMENT_PLUGIN)
         optp = optparse.OptionParser()
         nonobot.plugins.plugins_add_extra_options(path, optp)
         self.assertTrue(optp.has_option('--blah'))
Example #2
0
 def test_get_all_plugin_modules_no__init__(self):
     with fixtures.cleaned_tempdir() as path:
         test_file = path + "__init__.py"
         open(test_file, 'w').write("")
         test_file2 = path + "/t2.py"
         open(test_file2, 'w').write("")
         ret = [x for x in nonobot.plugins.get_all_plugin_modules(path)]
         self.assertEqual(len(ret), 1)
Example #3
0
    def test_undefined_action_return(self):
        with fixtures.cleaned_tempdir() as path:
            test_file = path + "/tstream.py"
            open(test_file, 'w').write(SAMPLE_PLUGIN_METHOD)
            plugins = nonobot.plugins.get_plugins_methods(path, {'foo: bar'})
            cls = nonobot.base.NoNoBot(
                self.username, self.password, self.room,
                self.nick,
                plugins=plugins)
            msg = {'body': '%s: unknown' % (self.nick)}

            m = cls.message(msg)
            self.assertIsNone(m)
Example #4
0
    def test_message_stream_nothing_todo(self):
        with fixtures.cleaned_tempdir() as path:
            test_file = path + "/tstream.py"
            open(test_file, 'w').write(SAMPLE_PLUGIN_METHOD)
            plugins = nonobot.plugins.get_plugins_methods(path, {'foo: bar'})
            cls = nonobot.base.NoNoBot(
                self.username, self.password, self.room,
                self.nick,
                plugins=plugins)
            msg = {'body': 'hello moto'}

            m = cls.message(msg)
            self.assertIsNone(m)
Example #5
0
 def test_plugin_stream_method(self):
     with fixtures.cleaned_tempdir() as path:
         test_file = path + "/tstream.py"
         open(test_file, 'w').write(SAMPLE_PLUGIN_STREAM)
         plugins = nonobot.plugins.get_plugins_methods(path, {'foo: bar'})
         self.assertEqual(len(plugins), 2)
         for i in plugins:
             if type(i) != str:
                 first_plugin = plugins[i]
         self.assertEqual(len(first_plugin), 1)
         self.assertIn('stream', first_plugin)
         self.assertEqual(first_plugin['stream']['doc'],
                          'DOC STREAM')
         self.assertIn('help', plugins)
         self.assertEqual(len(plugins['help']), 1)
         self.assertEqual(plugins['help'], ['[tstream] DOC STREAM'])
Example #6
0
 def test_plugin_methods(self):
     with fixtures.cleaned_tempdir() as path:
         test_file = path + "/t1.py"
         open(test_file, 'w').write(SAMPLE_PLUGIN_METHOD)
         plugins = nonobot.plugins.get_plugins_methods(path, {'foo: bar'})
         self.assertEqual(len(plugins), 2)
         for i in plugins:
             if type(i) != str:
                 first_plugin = plugins[i]
         self.assertEqual(len(first_plugin), 2)
         self.assertIn('foo', first_plugin)
         self.assertIn('foo_doc', first_plugin)
         self.assertEqual(first_plugin['foo_doc']['doc'],
                          'THIS IS SOME DOC')
         self.assertIn('help', plugins)
         self.assertEqual(len(plugins['help']), 1)
         self.assertEqual(plugins['help'],
                          ['[t1] foo_doc: THIS IS SOME DOC'])
Example #7
0
    def test_stream(self, mocked):
        with fixtures.cleaned_tempdir() as path:
            test_file = path + "/teststream.py"
            open(test_file, 'w').write(SAMPLE_PLUGIN_STREAM)
            plugins = nonobot.plugins.get_plugins_methods(path, {'foo: bar'})
            cls = nonobot.base.NoNoBot(
                self.username, self.password, self.room,
                self.nick,
                plugins=plugins)

            msg = {'body': 'callstream',
                   'from': fixtures.FakeFrom}

            cls.message(msg)

            mocked.assert_called_with(mtype='groupchat',
                                      mbody='Hello Stream',
                                      mto='thedude')
Example #8
0
    def test_help(self, mocked):
        with fixtures.cleaned_tempdir() as path:
            class From(object):
                bare = 'thedude'
            test_file = path + "/testhelp.py"
            open(test_file, 'w').write(SAMPLE_PLUGIN_METHOD)
            plugins = nonobot.plugins.get_plugins_methods(path, {'foo: bar'})
            cls = nonobot.base.NoNoBot(
                self.username, self.password, self.room,
                self.nick,
                plugins=plugins)

            msg = {'body': self.nick + ': help',
                   'from': fixtures.FakeFrom}

            cls.message(msg)

            mbody = '[testhelp] foo_doc: THIS IS SOME DOC'
            mocked.assert_called_with(mtype='groupchat',
                                      mbody=mbody,
                                      mto='thedude')