class Test_StorePlugin(TestCase):
    """
    Tests for the StorePlugin class.
    """

    #: Topics that should be registered
    topics = ('get-store-manager', )

    def before(self):
        """
        Called before every test.
        """
        self.bus = mock.MagicMock()
        self.plugin = Plugin(self.bus)

    def after(self):
        """
        Called after every test.
        """
        self.bus = None
        self.plugin = None

    def test_store_plugin_start(self):
        """
        Verify start() subscribes the proper topics.
        """
        self.plugin.start()
        # subscribe should be called a specific number of times
        self.assertEquals(len(self.topics), self.bus.subscribe.call_count)
        # Each subscription should have it's own call to register a callback
        for topic in self.topics:
            self.bus.subscribe.assert_any_call(topic, mock.ANY)

    def test_store_plugin_stop(self):
        """
        Verify stop() unsubscribes the proper topics.
        """
        self.plugin.stop()
        # unsubscribe should be called a specific number of times
        self.assertEquals(len(self.topics), self.bus.unsubscribe.call_count)
        # Each unsubscription should have it's own call
        # to deregister a callback
        for topic in self.topics:
            self.bus.unsubscribe.assert_any_call(topic, mock.ANY)

    def test_get_store_manager(self):
        """
        Verify get_store_manager returns a store manager.
        """
        manager = self.plugin.get_store_manager()
        self.assertIsInstance(manager, StoreHandlerManager)