Exemple #1
0
 def test_channel_receive_none(self):
     """Testing Channel: receive non-existant"""
     channel = Channel()
     channel.subscribe("test")
     channel.publish("bye")
     with self.assertRaises(KeyError):
         [x for x in channel.receive("bye")]
Exemple #2
0
 def test_channel_receive_none(self):
     """Testing Channel: receive non-existant"""
     channel = Channel()
     channel.subscribe("test")
     channel.publish("bye")
     with self.assertRaises(KeyError):
         [x for x in channel.receive("bye")]
Exemple #3
0
 def test_channel_publish(self):
     """Testing Channel: publish topic"""
     channel = Channel()
     channel.subscribe("test")
     channel.subscribe("test2")
     channel.publish("hello", topic="test")
     assert [x for x in channel.receive("test")][0] == "hello"
     assert channel.queues["test2"].qsize() == 0
Exemple #4
0
 def test_channel_publish(self):
     """Testing Channel: publish topic"""
     channel = Channel()
     channel.subscribe("test")
     channel.subscribe("test2")
     channel.publish("hello", topic="test")
     assert [x for x in channel.receive("test")][0] == "hello"
     assert channel.queues["test2"].qsize() == 0
Exemple #5
0
    def test_log_plugin(self):
        config = Config()
        channel = Channel()
        channel.subscribe("internal.log")
        channel.publish(Value("test", 0))

        kls = log.LogPlugin(config, channel)
        kls.plugin_name = "internal.log"
        kls.write(channel)
Exemple #6
0
 def test_channel_receive_empty(self):
     """Testing Channel: receive in empty queue"""
     channel = Channel()
     channel.subscribe("test")
     assert [x for x in channel.receive("test")] == []
Exemple #7
0
 def test_channel_broadcast(self):
     """Testing Channel: publish broadcast"""
     channel = Channel()
     channel.subscribe("test")
     channel.publish("hello")
     assert [x for x in channel.receive("test")][0] == "hello"
Exemple #8
0
 def test_channel_subscription(self):
     """Testing Channel: subscription"""
     channel = Channel()
     channel.subscribe("test")
     assert "test" in channel.queues
Exemple #9
0
class TestPlugin(unittest.TestCase):
    def setUp(self):
        self.config = Config()
        self.channel = Channel()
        self.channel.subscribe("test")

        self.config["plugin_dir"] = [
            os.path.join(os.path.dirname(drove.plugin.__file__), "plugins")
        ]
        self.config["read_interval"] = 0
        self.config["write_interval"] = 0

        self.testing_plugin = TestingPlugin(self.config, self.channel)
        self.testing_plugin.setup(self.config)

    def test_plugin_load(self):
        """testing plugin: load()"""
        x = Plugin.load("internal.log", self.config, self.channel)
        assert x.__class__.__name__ == "LogPlugin"

    def test_plugin_rw(self):
        """Testing Plugin: read() and write()"""
        self.testing_plugin._read()
        self.testing_plugin._write()

    def test_plugin_stop(self):
        """Testing Plugin: stop()"""
        self.testing_plugin.stop()

    def test_plugin_failed(self):
        """Testing Plugin: failing"""
        x = TestingFailedPlugin(self.config, self.channel)
        x.setup(self.config)
        x.log.error = x._mock_log

        with self.assertRaises(AssertionError):
            x._read()

        with self.assertRaises(AssertionError):
            x._write()

    def test_plugin_start(self):
        """Testing Plugin: start() with handlers"""
        with self.assertRaises(AssertionError):
            x = TestingStartPlugin(self.config, self.channel)
            x.start()
            assert "read" in x.value
            assert "write" in x.value

    def test_plugin_manager_loop(self):
        """Testing PluginManager: waiting loop"""
        x = PluginManager(self.config, self.channel)
        x.loop(1000, 0)

    def test_plugin_manager(self):
        """Testing PluginManager: basic behaviour"""
        self.config["plugin.internal.log"] = True
        x = PluginManager(self.config, self.channel)
        assert x.plugins[0].__class__.__name__ == "LogPlugin"
        x.plugins = [TestingPlugin(self.config, self.channel)]
        x.start_all()
        assert len(x) == 1
        assert len([i for i in x]) == 1
        x.stop_all()
Exemple #10
0
class TestPlugin(unittest.TestCase):
    def setUp(self):
        self.config = Config()
        self.channel = Channel()
        self.channel.subscribe("test")

        self.config["plugin_dir"] = [os.path.join(os.path.dirname(drove.plugin.__file__), "plugins")]
        self.config["read_interval"] = 0
        self.config["write_interval"] = 0

        self.testing_plugin = TestingPlugin(self.config, self.channel)
        self.testing_plugin.setup(self.config)

    def test_plugin_load(self):
        """testing plugin: load()"""
        x = Plugin.load("internal.log", self.config, self.channel)
        assert x.__class__.__name__ == "LogPlugin"

    def test_plugin_rw(self):
        """Testing Plugin: read() and write()"""
        self.testing_plugin._read()
        self.testing_plugin._write()

    def test_plugin_stop(self):
        """Testing Plugin: stop()"""
        self.testing_plugin.stop()

    def test_plugin_failed(self):
        """Testing Plugin: failing"""
        x = TestingFailedPlugin(self.config, self.channel)
        x.setup(self.config)
        x.log.error = x._mock_log

        with self.assertRaises(AssertionError):
            x._read()

        with self.assertRaises(AssertionError):
            x._write()

    def test_plugin_start(self):
        """Testing Plugin: start() with handlers"""
        with self.assertRaises(AssertionError):
            x = TestingStartPlugin(self.config, self.channel)
            x.start()
            assert "read" in x.value
            assert "write" in x.value

    def test_plugin_manager_loop(self):
        """Testing PluginManager: waiting loop"""
        x = PluginManager(self.config, self.channel)
        x.loop(1000, 0)

    def test_plugin_manager(self):
        """Testing PluginManager: basic behaviour"""
        self.config["plugin.internal.log"] = True
        x = PluginManager(self.config, self.channel)
        assert x.plugins[0].__class__.__name__ == "LogPlugin"
        x.plugins = [TestingPlugin(self.config, self.channel)]
        x.start_all()
        assert len(x) == 1
        assert len([i for i in x]) == 1
        x.stop_all()
Exemple #11
0
 def test_channel_subscription(self):
     """Testing Channel: subscription"""
     channel = Channel()
     channel.subscribe("test")
     assert "test" in channel.queues
Exemple #12
0
 def test_channel_receive_empty(self):
     """Testing Channel: receive in empty queue"""
     channel = Channel()
     channel.subscribe("test")
     assert [x for x in channel.receive("test")] == []
Exemple #13
0
 def test_channel_broadcast(self):
     """Testing Channel: publish broadcast"""
     channel = Channel()
     channel.subscribe("test")
     channel.publish("hello")
     assert [x for x in channel.receive("test")][0] == "hello"