Cleanups and more tests

This commit is contained in:
Tim Bentley 2013-04-05 20:37:15 +01:00
parent 25d74260ce
commit fc80e3d106
9 changed files with 129 additions and 11 deletions

View File

@ -103,7 +103,7 @@ class Plugin(QtCore.QObject):
``add_export_menu_Item(export_menu)``
Add an item to the Export menu.
``create_settings_Tab()``
``create_settings_tab()``
Creates a new instance of SettingsTabItem to be used in the Settings
dialog.
@ -252,7 +252,7 @@ class Plugin(QtCore.QObject):
"""
pass
def create_settings_Tab(self, parent):
def create_settings_tab(self, parent):
"""
Create a tab for the settings window to display the configurable options
for this plugin to the user.

View File

@ -153,7 +153,7 @@ class PluginManager(object):
"""
for plugin in self.plugins:
if plugin.status is not PluginStatus.Disabled:
plugin.create_settings_Tab(self.settings_form)
plugin.create_settings_tab(self.settings_form)
def hook_import_menu(self):
"""

View File

@ -54,7 +54,7 @@ class MediaPlugin(Plugin):
# passed with drag and drop messages
self.dnd_id = u'Media'
def create_settings_Tab(self, parent):
def create_settings_tab(self, parent):
"""
Create the settings Tab
"""

View File

@ -69,7 +69,7 @@ class PresentationPlugin(Plugin):
self.icon_path = u':/plugins/plugin_presentations.png'
self.icon = build_icon(self.icon_path)
def create_settings_Tab(self, parent):
def create_settings_tab(self, parent):
"""
Create the settings Tab
"""

View File

@ -74,7 +74,7 @@ class TestPluginManager(TestCase):
# WHEN: We run hook_settings_tabs()
plugin_manager.hook_settings_tabs()
# THEN: The create_settings_Tab() method should have been called
# THEN: The hook_settings_tabs() method should have been called
assert mocked_plugin.create_media_manager_item.call_count == 0, \
u'The create_media_manager_item() method should not have been called.'
@ -94,8 +94,8 @@ class TestPluginManager(TestCase):
# 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
assert mocked_plugin.create_settings_Tab.call_count == 0, \
# THEN: The create_settings_tab() method should not have been called, but the plugins lists should be the same
assert mocked_plugin.create_settings_tab.call_count == 0, \
u'The create_media_manager_item() method should not have been called.'
self.assertEqual(mocked_settings_form.plugin_manager.plugins, plugin_manager.plugins,
u'The plugins on the settings form should be the same as the plugins in the plugin manager')
@ -117,7 +117,7 @@ class TestPluginManager(TestCase):
plugin_manager.hook_settings_tabs()
# THEN: The create_media_manager_item() method should have been called with the mocked settings form
assert mocked_plugin.create_settings_Tab.call_count == 1, \
assert mocked_plugin.create_settings_tab.call_count == 1, \
u'The create_media_manager_item() method should have been called once.'
self.assertEqual(mocked_settings_form.plugin_manager.plugins, plugin_manager.plugins,
u'The plugins on the settings form should be the same as the plugins in the plugin manager')
@ -135,8 +135,8 @@ class TestPluginManager(TestCase):
# 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)
# THEN: The create_settings_tab() method should have been called
mocked_plugin.create_settings_tab.assert_called_with(self.mocked_settings_form)
def hook_import_menu_with_disabled_plugin_test(self):
"""

View File

@ -30,8 +30,10 @@ class TestAppLocation(TestCase):
mocked_get_directory.return_value = u'test/dir'
mocked_check_directory_exists.return_value = True
mocked_os.path.normpath.return_value = u'test/dir'
# WHEN: we call AppLocation.get_data_path()
data_path = AppLocation.get_data_path()
# THEN: check that all the correct methods were called, and the result is correct
mocked_settings.contains.assert_called_with(u'advanced/data path')
mocked_get_directory.assert_called_with(AppLocation.DataDir)
@ -49,8 +51,10 @@ class TestAppLocation(TestCase):
mocked_settings.contains.return_value = True
mocked_settings.value.return_value.toString.return_value = u'custom/dir'
mocked_os.path.normpath.return_value = u'custom/dir'
# WHEN: we call AppLocation.get_data_path()
data_path = AppLocation.get_data_path()
# THEN: the mocked Settings methods were called and the value returned was our set up value
mocked_settings.contains.assert_called_with(u'advanced/data path')
mocked_settings.value.assert_called_with(u'advanced/data path')
@ -100,8 +104,10 @@ class TestAppLocation(TestCase):
# GIVEN: A mocked out AppLocation.get_data_path()
mocked_get_data_path.return_value = u'test/dir'
mocked_check_directory_exists.return_value = True
# WHEN: we call AppLocation.get_data_path()
data_path = AppLocation.get_section_data_path(u'section')
# THEN: check that all the correct methods were called, and the result is correct
mocked_check_directory_exists.assert_called_with(u'test/dir/section')
assert data_path == u'test/dir/section', u'Result should be "test/dir/section"'
@ -112,8 +118,10 @@ class TestAppLocation(TestCase):
"""
with patch(u'openlp.core.utils.applocation._get_frozen_path') as mocked_get_frozen_path:
mocked_get_frozen_path.return_value = u'app/dir'
# WHEN: We call AppLocation.get_directory
directory = AppLocation.get_directory(AppLocation.AppDir)
# THEN:
assert directory == u'app/dir', u'Directory should be "app/dir"'
@ -130,8 +138,10 @@ class TestAppLocation(TestCase):
mocked_get_frozen_path.return_value = u'plugins/dir'
mocked_sys.frozen = 1
mocked_sys.argv = ['openlp']
# WHEN: We call AppLocation.get_directory
directory = AppLocation.get_directory(AppLocation.PluginsDir)
# THEN:
assert directory == u'plugins/dir', u'Directory should be "plugins/dir"'

View File

@ -0,0 +1,108 @@
"""
This module contains tests for the lib submodule of the Remotes plugin.
"""
import os
from unittest import TestCase
from tempfile import mkstemp
from mock import patch
from openlp.core.lib import Settings
from openlp.plugins.remotes.lib.remotetab import RemoteTab
from PyQt4 import QtGui
__default_settings__ = {
u'remotes/twelve hour': True,
u'remotes/port': 4316,
u'remotes/https port': 4317,
u'remotes/https enabled': False,
u'remotes/user id': u'openlp',
u'remotes/password': u'password',
u'remotes/authentication enabled': False,
u'remotes/ip address': u'0.0.0.0'
}
ZERO_URL = u'0.0.0.0'
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'..', u'..', u'..', u'resources'))
class TestRemoteTab(TestCase):
"""
Test the functions in the :mod:`lib` module.
"""
def setUp(self):
"""
Create the UI
"""
fd, self.ini_file = mkstemp(u'.ini')
Settings().set_filename(self.ini_file)
self.application = QtGui.QApplication.instance()
Settings().extend_default_settings(__default_settings__)
self.parent = QtGui.QMainWindow()
self.form = RemoteTab(self.parent, u'Remotes', None, None)
def tearDown(self):
"""
Delete all the C++ objects at the end so that we don't have a segfault
"""
del self.application
del self.parent
del self.form
os.unlink(self.ini_file)
def set_basic_urls_test(self):
"""
Test the set_urls function with standard defaults
"""
# GIVEN: A mocked location
with patch(u'openlp.core.utils.applocation.Settings') as mocked_class, \
patch(u'openlp.core.utils.AppLocation.get_directory') as mocked_get_directory, \
patch(u'openlp.core.utils.applocation.check_directory_exists') as mocked_check_directory_exists, \
patch(u'openlp.core.utils.applocation.os') as mocked_os:
# GIVEN: A mocked out Settings class and a mocked out AppLocation.get_directory()
mocked_settings = mocked_class.return_value
mocked_settings.contains.return_value = False
mocked_get_directory.return_value = u'test/dir'
mocked_check_directory_exists.return_value = True
mocked_os.path.normpath.return_value = u'test/dir'
# WHEN: when the set_urls is called having reloaded the form.
self.form.load()
self.form.set_urls()
# THEN: the following screen values should be set
self.assertEqual(self.form.address_edit.text(), ZERO_URL, u'The default URL should be set on the screen')
self.assertEqual(self.form.https_settings_group_box.isEnabled(), False,
u'The Https box should not be enabled')
self.assertEqual(self.form.https_settings_group_box.isChecked(), False,
u'The Https checked box should note be Checked')
self.assertEqual(self.form.user_login_group_box.isChecked(), False,
u'The authentication box should not be enabled')
def set_certificate_urls_test(self):
"""
Test the set_urls function with certificate available
"""
# GIVEN: A mocked location
with patch(u'openlp.core.utils.applocation.Settings') as mocked_class, \
patch(u'openlp.core.utils.AppLocation.get_directory') as mocked_get_directory, \
patch(u'openlp.core.utils.applocation.check_directory_exists') as mocked_check_directory_exists, \
patch(u'openlp.core.utils.applocation.os') as mocked_os:
# GIVEN: A mocked out Settings class and a mocked out AppLocation.get_directory()
mocked_settings = mocked_class.return_value
mocked_settings.contains.return_value = False
mocked_get_directory.return_value = TEST_PATH
mocked_check_directory_exists.return_value = True
mocked_os.path.normpath.return_value = TEST_PATH
# WHEN: when the set_urls is called having reloaded the form.
self.form.load()
self.form.set_urls()
# THEN: the following screen values should be set
self.assertEqual(self.form.http_settings_group_box.isEnabled(), True,
u'The Http group box should be enabled')
self.assertEqual(self.form.https_settings_group_box.isChecked(), False,
u'The Https checked box should be Checked')
self.assertEqual(self.form.https_settings_group_box.isEnabled(), True,
u'The Https box should be enabled')

View File

View File