Fix up the projector interface tests

This commit is contained in:
Raoul Snyman 2016-01-07 23:36:43 +02:00
parent f2cccb90ae
commit 543d6898d3
2 changed files with 20 additions and 14 deletions

View File

@ -23,7 +23,7 @@
Interface tests to test the openlp.core.ui.projector.editform.ProjectorEditForm()
class and methods.
"""
import os
from unittest import TestCase
from openlp.core.common import Registry, Settings
@ -32,7 +32,7 @@ from openlp.core.ui import ProjectorEditForm
from tests.functional import patch
from tests.helpers.testmixin import TestMixin
from tests.resources.projector.data import TEST1_DATA, TEST2_DATA
from tests.resources.projector.data import TEST_DB, TEST1_DATA, TEST2_DATA
class TestProjectorEditForm(TestCase, TestMixin):
@ -49,7 +49,9 @@ class TestProjectorEditForm(TestCase, TestMixin):
self.setup_application()
Registry.create()
with patch('openlp.core.lib.projector.db.init_url') as mocked_init_url:
mocked_init_url.return_value = 'sqlite://'
if os.path.exists(TEST_DB):
os.unlink(TEST_DB)
mocked_init_url.return_value = 'sqlite:///' + TEST_DB
self.projectordb = ProjectorDB()
self.projector_form = ProjectorEditForm(projectordb=self.projectordb)
@ -93,11 +95,13 @@ class TestProjectorEditForm(TestCase, TestMixin):
with patch('openlp.core.ui.projector.editform.QDialog.exec'):
# WHEN: Calling edit form with existing projector instance
self.projector_form.exec(projector=TEST1_DATA)
self.projector_form.exec(projector=Projector(**TEST1_DATA))
item = self.projector_form.projector
# THEN: Should be editing an existing entry
self.assertFalse(self.projector_form.new_projector,
'Projector edit form should be marked as existing entry')
self.assertTrue((item.ip is TEST1_DATA.ip and item.name is TEST1_DATA.name),
self.assertTrue((item.ip is TEST1_DATA['ip'] and item.name is TEST1_DATA['name']),
'Projector edit form should have TEST1_DATA() instance to edit')

View File

@ -20,24 +20,24 @@
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
"""
:mod: `tests.interfaces.openlp_core_ui.test_projectorsourceform` module
:mod: `tests.interfaces.openlp_core_ui.test_projectorsourceform` module
Tests for the Projector Source Select form.
Tests for the Projector Source Select form.
"""
import logging
log = logging.getLogger(__name__)
log.debug('test_projectorsourceform loaded')
import os
from unittest import TestCase
from PyQt5.QtWidgets import QDialog
from tests.functional import patch
from tests.functional.openlp_core_lib.test_projectordb import tmpfile
from tests.helpers.testmixin import TestMixin
from tests.resources.projector.data import TEST_DB, TEST1_DATA
from openlp.core.common import Registry, Settings
from openlp.core.lib.projector.db import ProjectorDB
from openlp.core.lib.projector.db import ProjectorDB, Projector
from openlp.core.lib.projector.constants import PJLINK_DEFAULT_CODES, PJLINK_DEFAULT_SOURCES
from openlp.core.ui.projector.sourceselectform import source_group, SourceSelectSingle
@ -65,7 +65,9 @@ class ProjectorSourceFormTest(TestCase, TestMixin):
"""
Set up anything necessary for all tests
"""
mocked_init_url.return_value = 'sqlite:///{}'.format(tmpfile)
if os.path.exists(TEST_DB):
os.unlink(TEST_DB)
mocked_init_url.return_value = 'sqlite:///{}'.format(TEST_DB)
self.build_settings()
self.setup_application()
Registry.create()
@ -73,10 +75,10 @@ class ProjectorSourceFormTest(TestCase, TestMixin):
if not hasattr(self, 'projectordb'):
self.projectordb = ProjectorDB()
# Retrieve/create a database record
self.projector = self.projectordb.get_projector_by_ip(TEST1_DATA.ip)
self.projector = self.projectordb.get_projector_by_ip(TEST1_DATA['ip'])
if not self.projector:
self.projectordb.add_projector(projector=TEST1_DATA)
self.projector = self.projectordb.get_projector_by_ip(TEST1_DATA.ip)
self.projectordb.add_projector(projector=Projector(**TEST1_DATA))
self.projector = self.projectordb.get_projector_by_ip(TEST1_DATA['ip'])
self.projector.dbid = self.projector.id
self.projector.db_item = self.projector