openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #24841
Re: [Merge] lp:~alisonken1/openlp/bug-1386951 into lp:openlp
Review: Needs Fixing
See below
Diff comments:
> === modified file 'openlp/core/ui/projector/__init__.py'
> --- openlp/core/ui/projector/__init__.py 2014-10-31 19:47:36 +0000
> +++ openlp/core/ui/projector/__init__.py 2014-11-06 22:01:27 +0000
> @@ -27,5 +27,5 @@
> # Temple Place, Suite 330, Boston, MA 02111-1307 USA #
> ###############################################################################
> """
> -The Projector driver module.
> -"""
> \ No newline at end of file
> +The Projector network remote control module.
> +"""
>
> === modified file 'openlp/core/ui/projector/editform.py'
> --- openlp/core/ui/projector/editform.py 2014-10-22 00:49:21 +0000
> +++ openlp/core/ui/projector/editform.py 2014-11-06 22:01:27 +0000
> @@ -47,6 +47,15 @@
> from openlp.core.lib.projector.constants import PJLINK_PORT
>
>
> +def _dialog_exec(dialog):
> + """
> + Exec here to help with testing
> +
> + :param instance: Instance called from
> + """
> + return QDialog.exec_(dialog)
> +
> +
> class Ui_ProjectorEditForm(object):
> """
> The :class:`~openlp.core.lib.ui.projector.editform.Ui_ProjectorEditForm` class defines
> @@ -132,6 +141,8 @@
> self.location_label.setText(translate('OpenLP.ProjectorEditForm', 'Location'))
> self.location_text.setText(self.projector.location)
> self.notes_label.setText(translate('OpenLP.ProjectorEditForm', 'Notes'))
> + self.notes_text.selectAll()
> + self.notes_text.cut()
> self.notes_text.insertPlainText(self.projector.notes)
>
>
> @@ -158,7 +169,14 @@
> self.button_box.helpRequested.connect(self.help_me)
> self.button_box.rejected.connect(self.cancel_me)
>
> - def exec_(self, projector=None):
> + def exec_(self, projector=None, test=False):
> + """
> + Execute QDialog to add/edit a projector item
> +
> + :param projector: None: Create a new projector item to add
> + Projector() instance to edit (from ProjectorDB)
> + :param test: True - test in progress, do not reset self.projector item on exit
> + """
> if projector is None:
> self.projector = Projector()
> self.new_projector = True
> @@ -166,8 +184,9 @@
> self.projector = projector
> self.new_projector = False
> self.retranslateUi(self)
> - reply = QDialog.exec_(self)
> - self.projector = None
> + reply = _dialog_exec(self)
Why the change to a method? Is it really necessary?
> + if not test:
> + self.projector = None
> return reply
>
> @pyqtSlot()
>
> === modified file 'openlp/core/ui/projector/manager.py'
> --- openlp/core/ui/projector/manager.py 2014-10-23 02:40:22 +0000
> +++ openlp/core/ui/projector/manager.py 2014-11-06 22:01:27 +0000
> @@ -562,9 +562,8 @@
> return
> self.old_projector = projector
> projector.link.disconnect_from_host()
> - record = self.projectordb.get_projector_by_ip(projector.link.ip)
> - self.projector_form.exec_(record)
> - new_record = self.projectordb.get_projector_by_id(record.id)
> + self.projector_form.exec_(projector.db_item)
> + projector.db_item = self.projectordb.get_projector_by_id(self.old_projector.db_item.id)
>
> def on_poweroff_projector(self, opt=None):
> """
>
> === added file 'tests/interfaces/openlp_core_ui/test_projectoreditform.py'
> --- tests/interfaces/openlp_core_ui/test_projectoreditform.py 1970-01-01 00:00:00 +0000
> +++ tests/interfaces/openlp_core_ui/test_projectoreditform.py 2014-11-06 22:01:27 +0000
> @@ -0,0 +1,111 @@
> +# -*- coding: utf-8 -*-
> +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
> +
> +###############################################################################
> +# OpenLP - Open Source Lyrics Projection #
> +# --------------------------------------------------------------------------- #
> +# Copyright (c) 2008-2014 Raoul Snyman #
> +# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
> +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
> +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
> +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
> +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
> +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
> +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
> +# --------------------------------------------------------------------------- #
> +# 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 related methods.
> +"""
> +
> +import os
> +from unittest import TestCase
> +
> +from openlp.core.common import Registry, Settings
> +from tests.functional import patch
> +from tests.helpers.testmixin import TestMixin
> +
> +from openlp.core.ui import ProjectorEditForm
> +from openlp.core.lib.projector.db import Projector, ProjectorDB
> +
> +from tests.resources.projector.data import TEST1_DATA
> +
> +tmpfile = '/tmp/openlp-test-projectormanager.sql'
> +
> +
> +class TestProjectorEditForm(TestCase, TestMixin):
> + """
> + Test the functions in the ProjectorEditForm class
> + """
> + def setUp(self):
> + """
> + Create the UI and setup necessary options
> + """
> + self.build_settings()
> + self.setup_application()
> + Registry.create()
> + if not hasattr(self, 'projector_form'):
> + with patch('openlp.core.lib.projector.db.init_url') as mocked_init_url:
> + mocked_init_url.start()
> + mocked_init_url.return_value = 'sqlite:///%s' % tmpfile
> + self.projectordb = ProjectorDB()
> + if not hasattr(self, 'projector_editform'):
> + self.projector_form = ProjectorEditForm(projectordb=self.projectordb)
> +
> + def tearDown(self):
> + """
> + Close test database session.
> + Delete all the C++ objects at the end so that we don't have a segfault.
> + """
> + self.projectordb.session.close()
> + del self.projector_form
> + self.destroy_settings()
> +
> + def edit_form_add_projector_test(self):
> + """
> + Test that projector edit form with no parameter creates a new entry to edit
> + """
> + # GIVEN: Setup mocks
> + with patch('openlp.core.ui.projector.editform._dialog_exec') as mocked_dialog_exec:
> + # WHEN: Calling edit form without parameters
> + self.projector_form.exec_(test=True)
> +
> + # THEN: Entry should be marked as new item
> + self.assertTrue(self.projector_form.new_projector,
> + 'Projector edit form should be marked as new edit entry')
> +
> + # THEN: Projector instance should be an empty item
> + item = self.projector_form.projector
2 thens
> + self.assertTrue((item.ip is None and item.name is None),
> + 'Projector edit form should have new Projector() instance to edit')
> +
> + def edit_form_edit_projector_test(self):
> + """
> + Test that projector edit form with Projector() instance parameter uses existing entry to edit
> + """
> + # GIVEN: Setup mocks
> + with patch('openlp.core.ui.projector.editform._dialog_exec') as mocked_dialog_exec:
> + # WHEN: Calling edit form with parameters
> + self.projector_form.exec_(projector=TEST1_DATA, test=True)
> +
> + # THEN: Entry should be marked as edit item
> + self.assertFalse(self.projector_form.new_projector,
> + 'Projector edit form should be marked as previous edit entry')
> +
> + # THEN: Projector instance should be an existing item
2 thens?
> + item = self.projector_form.projector
> + 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')
>
--
https://code.launchpad.net/~alisonken1/openlp/bug-1386951/+merge/241004
Your team OpenLP Core is subscribed to branch lp:openlp.
Follow ups
References