Exemplo n.º 1
0
    def testDefaultPluginIds(self):
        pcfg = PluginConfig().add('mockplugin')
        self.assertEqual('mockplugin', pcfg.ids[0])

        pcfg.add('mockplugin')
        pcfg.add('mockplugin')
        self.assertEqual('mockplugin1', pcfg.ids[1])
        self.assertEqual('mockplugin2', pcfg.ids[2])
Exemplo n.º 2
0
    def testDefaultPluginIds(self):
        pcfg = PluginConfig().add('mockplugin')
        self.assertEqual('mockplugin', pcfg.ids[0])

        pcfg.add('mockplugin')
        pcfg.add('mockplugin')
        self.assertEqual('mockplugin1', pcfg.ids[1])
        self.assertEqual('mockplugin2', pcfg.ids[2])
Exemplo n.º 3
0
    def testMessageHandlerFiltering(self):
        mockplugin = self._write_and_load('mockplugin', MOCK_PLUGIN_CODE)
        pcfg = PluginConfig().add('mockplugin', 'p1').add('mockplugin', 'p2')
        self.pmgr = PluginManager(pcfg, self.cli_proxy, self.srv_proxy)
        self.pmgr.filter(self.__class__.handshake_msg1, 'client')
        self.pmgr.filter(self.__class__.handshake_msg2, 'server')
        p1 = mockplugin.instances[0]
        p2 = mockplugin.instances[1]
        msg = {'msgtype': 0x03, 'chat_msg': 'foo!'}

        self.assertTrue(self.pmgr.filter(msg, 'client'))
        self.assertEquals(msg, p1.last_msg)
        self.assertEquals(msg, p2.last_msg)

        p1.drop_next_msg = True
        self.assertFalse(
            self.pmgr.filter({
                'msgtype': 0x03,
                'chat_msg': 'bar!'
            }, 'server'))
        self.assertEquals(msg, p2.last_msg)

        p1.drop_next_msg = True
        self.assertTrue(
            self.pmgr.filter({
                'msgtype': 0x04,
                'time': 42
            }, 'client'))
Exemplo n.º 4
0
 def testMissingPluginClass(self):
     self._write_and_load('empty', 'from mc4p.plugins import MC4Plugin\n')
     pcfg = PluginConfig().add('empty', 'p')
     self.pmgr = PluginManager(pcfg, self.cli_proxy, self.srv_proxy)
     self.pmgr._load_plugins()
     # Should log an error, but not raise an exception.
     self.pmgr._instantiate_all()
Exemplo n.º 5
0
 def testEmptyPluginConfig(self):
     mockplugin = self._write_and_load('mockplugin', MOCK_PLUGIN_CODE)
     pcfg = PluginConfig()
     self.pmgr = PluginManager(pcfg, self.cli_proxy, self.srv_proxy)
     self.pmgr._load_plugins()
     self.pmgr._instantiate_all()
     self.assertEqual(0, len(mockplugin.instances))
Exemplo n.º 6
0
 def testMultiplePluginClasses(self):
     code = MOCK_PLUGIN_CODE + "class AnotherPlugin(MC4Plugin): pass"
     mockplugin = self._write_and_load('mockplugin', code)
     pcfg = PluginConfig().add('mockplugin', 'p')
     self.pmgr = PluginManager(pcfg, self.cli_proxy, self.srv_proxy)
     self.pmgr._load_plugins()
     self.pmgr._instantiate_all()
     self.assertEqual(0, len(mockplugin.instances))
Exemplo n.º 7
0
    def testInstantiationAfterSuccessfulHandshake(self):
        mockplugin = self._write_and_load('mockplugin', MOCK_PLUGIN_CODE)
        pcfg = PluginConfig().add('mockplugin', 'p1').add('mockplugin', 'p2')
        self.pmgr = PluginManager(pcfg, self.cli_proxy, self.srv_proxy)
        self.assertEqual(0, len(mockplugin.instances))

        self.pmgr.filter(self.__class__.handshake_msg1, 'client')
        self.pmgr.filter(self.__class__.handshake_msg2, 'server')
        self.assertEqual(2, len(mockplugin.instances))
Exemplo n.º 8
0
 def testInstantiation(self):
     mockplugin = self._write_and_load('mockplugin', MOCK_PLUGIN_CODE)
     pcfg = PluginConfig().add('mockplugin', 'p1').add('mockplugin', 'p2')
     self.pmgr = PluginManager(pcfg, self.cli_proxy, self.srv_proxy)
     self.pmgr._load_plugins()
     self.pmgr._instantiate_all()
     self.assertEqual(2, len(mockplugin.instances))
     self.assertTrue(mockplugin.instances[0].initialized)
     self.assertTrue(mockplugin.instances[1].initialized)
Exemplo n.º 9
0
 def testLoadingPluginInPackage(self):
     pkgname = os.path.basename(self.__class__.pkgdir)
     mockplugin = self._write_and_load(pkgname + '.mockplugin',
                                       MOCK_PLUGIN_CODE)
     pcfg = PluginConfig().add('%s.mockplugin' % pkgname, 'p1')
     self.pmgr = PluginManager(pcfg, self.cli_proxy, self.srv_proxy)
     self.pmgr._load_plugins()
     self.pmgr._instantiate_all()
     self.assertEqual(1, len(mockplugin.instances))
     self.assertTrue(mockplugin.instances[0].initialized)