def test_hook_settings_tabs_with_active_plugin_and_mocked_form(self): """ Test running the hook_settings_tabs() method with an active plugin and a mocked settings form """ # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active mocked_plugin = MagicMock() mocked_plugin.status = PluginStatus.Active plugin_manager = PluginManager() Registry().register('mock_plugin', mocked_plugin) mocked_settings_form = MagicMock() # Replace the autoloaded plugin with the version for testing in real code this would error mocked_settings_form.plugin_manager = plugin_manager State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Active) State().flush_preconditions() # WHEN: We run hook_settings_tabs() plugin_manager.hook_settings_tabs() # THEN: The create_media_manager_item() method should have been called with the mocked settings form assert 1 == mocked_plugin.create_settings_tab.call_count, \ 'The create_media_manager_item() method should have been called once.' assert plugin_manager.plugins == mocked_settings_form.plugin_manager.plugins, \ 'The plugins on the settings form should be the same as the plugins in the plugin manager'
def hook_settings_tabs_with_active_plugin_and_mocked_form_test(self): """ Test running the hook_settings_tabs() method with an active plugin and a mocked settings form """ # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active mocked_plugin = MagicMock() mocked_plugin.status = PluginStatus.Active plugin_manager = PluginManager() plugin_manager.plugins = [mocked_plugin] mocked_settings_form = MagicMock() # Replace the autoloaded plugin with the version for testing in real code this would error mocked_settings_form.plugin_manager = plugin_manager # WHEN: We run hook_settings_tabs() plugin_manager.hook_settings_tabs() # THEN: The create_media_manager_item() method should have been called with the mocked settings form self.assertEqual( 1, mocked_plugin.create_settings_tab.call_count, 'The create_media_manager_item() method should have been called once.' ) self.assertEqual( plugin_manager.plugins, mocked_settings_form.plugin_manager.plugins, 'The plugins on the settings form should be the same as the plugins in the plugin manager' )
def test_hook_settings_tabs_with_disabled_plugin_and_mocked_form(self): """ Test running the hook_settings_tabs() method with a disabled plugin and a mocked form """ # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled mocked_plugin = MagicMock() mocked_plugin.status = PluginStatus.Disabled plugin_manager = PluginManager() plugin_manager.plugins = [mocked_plugin] mocked_settings_form = MagicMock() # Replace the autoloaded plugin with the version for testing in real code this would error mocked_settings_form.plugin_manager = plugin_manager # WHEN: We run hook_settings_tabs() plugin_manager.hook_settings_tabs() # THEN: The create_settings_tab() method should not have been called, but the plugins lists should be the same self.assertEqual( 0, mocked_plugin.create_settings_tab.call_count, 'The create_media_manager_item() method should not have been called.' ) self.assertEqual( mocked_settings_form.plugin_manager.plugins, plugin_manager.plugins, 'The plugins on the settings form should be the same as the plugins in the plugin manager' )
def hook_settings_tabs_with_active_plugin_and_no_form_test(self): """ Test running the hook_settings_tabs() method with an active plugin and no settings form """ # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active mocked_plugin = MagicMock() mocked_plugin.status = PluginStatus.Active plugin_manager = PluginManager() plugin_manager.plugins = [mocked_plugin] # WHEN: We run hook_settings_tabs() plugin_manager.hook_settings_tabs() # THEN: The create_settings_tab() method should have been called mocked_plugin.create_settings_tab.assert_called_with(self.mocked_settings_form)
def test_hook_settings_tabs_with_active_plugin_and_no_form(self): """ Test running the hook_settings_tabs() method with an active plugin and no settings form """ # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active mocked_plugin = MagicMock() mocked_plugin.status = PluginStatus.Active plugin_manager = PluginManager() plugin_manager.plugins = [mocked_plugin] # WHEN: We run hook_settings_tabs() plugin_manager.hook_settings_tabs() # THEN: The create_settings_tab() method should have been called mocked_plugin.create_settings_tab.assert_called_with( self.mocked_settings_form)
def test_hook_settings_tabs_with_disabled_plugin_and_no_form(self): """ Test running the hook_settings_tabs() method with a disabled plugin and no form """ # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled mocked_plugin = MagicMock() mocked_plugin.status = PluginStatus.Disabled plugin_manager = PluginManager() plugin_manager.plugins = [mocked_plugin] # WHEN: We run hook_settings_tabs() plugin_manager.hook_settings_tabs() # THEN: The hook_settings_tabs() method should have been called assert 0 == mocked_plugin.create_media_manager_item.call_count, \ 'The create_media_manager_item() method should not have been called.'
def hook_settings_tabs_with_disabled_plugin_and_no_form_test(self): """ Test running the hook_settings_tabs() method with a disabled plugin and no form """ # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled mocked_plugin = MagicMock() mocked_plugin.status = PluginStatus.Disabled plugin_manager = PluginManager() plugin_manager.plugins = [mocked_plugin] # WHEN: We run hook_settings_tabs() plugin_manager.hook_settings_tabs() # THEN: The hook_settings_tabs() method should have been called self.assertEqual(0, mocked_plugin.create_media_manager_item.call_count, 'The create_media_manager_item() method should not have been called.')
def test_hook_settings_tabs_with_active_plugin_and_no_form(self): """ Test running the hook_settings_tabs() method with an active plugin and no settings form """ # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active mocked_plugin = MagicMock() mocked_plugin.status = PluginStatus.Active plugin_manager = PluginManager() Registry().register('mock_plugin', mocked_plugin) State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Active) State().flush_preconditions() # WHEN: We run hook_settings_tabs() plugin_manager.hook_settings_tabs() # THEN: The create_settings_tab() method should have been called mocked_plugin.create_settings_tab.assert_called_with( self.mocked_settings_form)
def test_hook_settings_tabs_with_disabled_plugin_and_no_form(self): """ Test running the hook_settings_tabs() method with a disabled plugin and no form """ # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled mocked_plugin = MagicMock() mocked_plugin.status = PluginStatus.Disabled plugin_manager = PluginManager() Registry().register('mock_plugin', mocked_plugin) State().add_service("mock", 1, is_plugin=True, status=PluginStatus.Active) State().flush_preconditions() # WHEN: We run hook_settings_tabs() plugin_manager.hook_settings_tabs() # THEN: The hook_settings_tabs() method should have been called assert 0 == mocked_plugin.create_media_manager_item.call_count, \ 'The create_media_manager_item() method should not have been called.'
def hook_settings_tabs_with_active_plugin_and_mocked_form_test(self): """ Test running the hook_settings_tabs() method with an active plugin and a mocked settings form """ # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active mocked_plugin = MagicMock() mocked_plugin.status = PluginStatus.Active plugin_manager = PluginManager() plugin_manager.plugins = [mocked_plugin] mocked_settings_form = MagicMock() # Replace the autoloaded plugin with the version for testing in real code this would error mocked_settings_form.plugin_manager = plugin_manager # WHEN: We run hook_settings_tabs() plugin_manager.hook_settings_tabs() # THEN: The create_media_manager_item() method should have been called with the mocked settings form self.assertEqual(1, mocked_plugin.create_settings_tab.call_count, 'The create_media_manager_item() method should have been called once.') self.assertEqual(plugin_manager.plugins, mocked_settings_form.plugin_manager.plugins, 'The plugins on the settings form should be the same as the plugins in the plugin manager')
def test_hook_settings_tabs_with_disabled_plugin_and_mocked_form(self): """ Test running the hook_settings_tabs() method with a disabled plugin and a mocked form """ # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled mocked_plugin = MagicMock() mocked_plugin.status = PluginStatus.Disabled plugin_manager = PluginManager() plugin_manager.plugins = [mocked_plugin] mocked_settings_form = MagicMock() # Replace the autoloaded plugin with the version for testing in real code this would error mocked_settings_form.plugin_manager = plugin_manager # WHEN: We run hook_settings_tabs() plugin_manager.hook_settings_tabs() # THEN: The create_settings_tab() method should not have been called, but the plugins lists should be the same self.assertEqual(0, mocked_plugin.create_settings_tab.call_count, 'The create_media_manager_item() method should not have been called.') self.assertEqual(mocked_settings_form.plugin_manager.plugins, plugin_manager.plugins, 'The plugins on the settings form should be the same as the plugins in the plugin manager')