openlp/tests/interfaces/openlp_core/ui/test_projectoreditform.py

104 lines
4.4 KiB
Python
Raw Normal View History

2014-12-18 19:06:25 +00:00
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2016-12-31 11:01:36 +00:00
# Copyright (c) 2008-2017 OpenLP Developers #
2014-12-18 19:06:25 +00:00
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
"""
Interface tests to test the openlp.core.ui.projector.editform.ProjectorEditForm()
class and methods.
"""
2016-01-07 21:36:43 +00:00
import os
2014-12-18 19:06:25 +00:00
from unittest import TestCase
from unittest.mock import patch
2014-12-18 19:06:25 +00:00
2017-10-07 07:05:07 +00:00
from openlp.core.common.registry import Registry
2014-12-18 19:06:25 +00:00
from openlp.core.lib.projector.db import Projector, ProjectorDB
from openlp.core.ui import ProjectorEditForm
from tests.helpers.testmixin import TestMixin
2016-01-07 21:36:43 +00:00
from tests.resources.projector.data import TEST_DB, TEST1_DATA, TEST2_DATA
2014-12-18 19:06:25 +00:00
class TestProjectorEditForm(TestCase, TestMixin):
"""
Test the methods in the ProjectorEditForm class
"""
def setUp(self):
"""
Create the UI and setup necessary options
:return: None
"""
self.setup_application()
2017-06-03 23:27:19 +00:00
self.build_settings()
2014-12-18 19:06:25 +00:00
Registry.create()
with patch('openlp.core.lib.projector.db.init_url') as mocked_init_url:
2016-01-07 21:36:43 +00:00
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)
2014-12-18 19:06:25 +00:00
def tearDown(self):
"""
Close database session.
Delete all C++ objects at end so we don't segfault.
:return: None
"""
self.projectordb.session.close()
del self.projector_form
2014-12-18 19:06:25 +00:00
self.destroy_settings()
@patch('openlp.core.ui.projector.editform.QtWidgets.QDialog.exec')
def test_edit_form_add_projector(self, mocked_exec):
2014-12-18 19:06:25 +00:00
"""
Test projector edit form with no parameters creates a new entry.
:return: None
"""
# GIVEN: Mocked setup
# WHEN: Calling edit form with no parameters
self.projector_form.exec()
item = self.projector_form.projector
# THEN: Should be creating a new instance
self.assertTrue(self.projector_form.new_projector,
'Projector edit form should be marked as a new entry')
self.assertTrue((item.ip is None and item.name is None),
'Projector edit form should have a new Projector() instance to edit')
@patch('openlp.core.ui.projector.editform.QtWidgets.QDialog.exec')
def test_edit_form_edit_projector(self, mocked_exec):
2014-12-18 19:06:25 +00:00
"""
Test projector edit form with existing projector entry
:return:
"""
# GIVEN: Mocked setup
# WHEN: Calling edit form with existing projector instance
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']),
'Projector edit form should have TEST1_DATA() instance to edit')