From 3426fc37d2cac97104a08b97cf1777f70a822bc8 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Sun, 14 Sep 2014 00:00:28 +0200 Subject: [PATCH 1/4] Fix author->songs relation Fixes: https://launchpad.net/bugs/1369139 --- openlp/plugins/songs/lib/db.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/songs/lib/db.py b/openlp/plugins/songs/lib/db.py index a9206a397..895dba4b5 100644 --- a/openlp/plugins/songs/lib/db.py +++ b/openlp/plugins/songs/lib/db.py @@ -31,8 +31,6 @@ The :mod:`db` module provides the database and schema that is the backend for the Songs plugin """ -import re - from sqlalchemy import Column, ForeignKey, Table, types from sqlalchemy.orm import mapper, relation, reconstructor from sqlalchemy.sql.expression import func, text @@ -329,7 +327,9 @@ def init_schema(url): Column('topic_id', types.Integer(), ForeignKey('topics.id'), primary_key=True) ) - mapper(Author, authors_table) + mapper(Author, authors_table, properties={ + 'songs': relation(Song, secondary=authors_songs_table, viewonly=True) + }) mapper(AuthorSong, authors_songs_table, properties={ 'author': relation(Author) }) From aef7bb55c4f2d3c90ab32a08d36d983c88d17a97 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Sun, 14 Sep 2014 00:00:43 +0200 Subject: [PATCH 2/4] Add test --- tests/functional/openlp_core_lib/test_ui.py | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/functional/openlp_core_lib/test_ui.py b/tests/functional/openlp_core_lib/test_ui.py index 591762947..6fe9a3938 100644 --- a/tests/functional/openlp_core_lib/test_ui.py +++ b/tests/functional/openlp_core_lib/test_ui.py @@ -154,6 +154,34 @@ class TestUi(TestCase): self.assertEqual('my tooltip', action.toolTip()) self.assertEqual('my statustip', action.statusTip()) + def test_create_action_2(self): + """ + Test creating an action + """ + # GIVEN: A dialog + dialog = QtGui.QDialog() + + # WHEN: We create an action with some properties + action = create_action(dialog, 'my_action', checked=True, enabled=False, visible=False) + + # THEN: These properties should be set + self.assertTrue(action.isChecked()) + self.assertFalse(action.isEnabled()) + self.assertFalse(action.isVisible()) + + def test_create_action_separator(self): + """ + Test creating an action as separator + """ + # GIVEN: A dialog + dialog = QtGui.QDialog() + + # WHEN: We create an action as a separator + action = create_action(dialog, 'my_action', separator=True) + + # THEN: The action should be a separator + self.assertTrue(action.isSeparator()) + def test_create_checked_enabled_visible_action(self): """ Test creating an action with the 'checked', 'enabled' and 'visible' properties. From e6a6015c21e01aaeef8ba73f464e98e4d5590304 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Sun, 14 Sep 2014 15:32:38 +0200 Subject: [PATCH 3/4] Fix tests --- tests/functional/openlp_core_lib/test_ui.py | 47 +++++++-------------- 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_ui.py b/tests/functional/openlp_core_lib/test_ui.py index 6fe9a3938..02f9ce4fa 100644 --- a/tests/functional/openlp_core_lib/test_ui.py +++ b/tests/functional/openlp_core_lib/test_ui.py @@ -40,7 +40,7 @@ class TestUi(TestCase): Test the functions in the ui module """ - def test_add_welcome_page(self): + def add_welcome_page_test(self): """ Test appending a welcome page to a wizard """ @@ -54,7 +54,7 @@ class TestUi(TestCase): self.assertEqual(1, len(wizard.pageIds()), 'The wizard should have one page.') self.assertIsInstance(wizard.page(0).pixmap(QtGui.QWizard.WatermarkPixmap), QtGui.QPixmap) - def test_create_button_box(self): + def create_button_box_test(self): """ Test creating a button box for a dialog """ @@ -82,7 +82,7 @@ class TestUi(TestCase): self.assertEqual(1, len(btnbox.buttons())) self.assertEqual(QtGui.QDialogButtonBox.HelpRole, btnbox.buttonRole(btnbox.buttons()[0])) - def test_create_horizontal_adjusting_combo_box(self): + def create_horizontal_adjusting_combo_box_test(self): """ Test creating a horizontal adjusting combo box """ @@ -97,7 +97,7 @@ class TestUi(TestCase): self.assertEqual('combo1', combo.objectName()) self.assertEqual(QtGui.QComboBox.AdjustToMinimumContentsLength, combo.sizeAdjustPolicy()) - def test_create_button(self): + def create_button_test(self): """ Test creating a button """ @@ -129,7 +129,7 @@ class TestUi(TestCase): self.assertEqual('my_btn', btn.objectName()) self.assertTrue(btn.isEnabled()) - def test_create_action(self): + def create_action_test(self): """ Test creating an action """ @@ -154,9 +154,9 @@ class TestUi(TestCase): self.assertEqual('my tooltip', action.toolTip()) self.assertEqual('my statustip', action.statusTip()) - def test_create_action_2(self): + def create_checked_disabled_invisible_action_test(self): """ - Test creating an action + Test that an invisible, disabled, checked action is created correctly """ # GIVEN: A dialog dialog = QtGui.QDialog() @@ -165,11 +165,11 @@ class TestUi(TestCase): action = create_action(dialog, 'my_action', checked=True, enabled=False, visible=False) # THEN: These properties should be set - self.assertTrue(action.isChecked()) - self.assertFalse(action.isEnabled()) - self.assertFalse(action.isVisible()) + self.assertTrue(action.isChecked(), 'The action should be checked') + self.assertFalse(action.isEnabled(), 'The action should be disabled') + self.assertFalse(action.isVisible(), 'The action should be invisble') - def test_create_action_separator(self): + def create_action_separator_test(self): """ Test creating an action as separator """ @@ -180,24 +180,9 @@ class TestUi(TestCase): action = create_action(dialog, 'my_action', separator=True) # THEN: The action should be a separator - self.assertTrue(action.isSeparator()) + self.assertTrue(action.isSeparator(), 'The action should be a separator') - def test_create_checked_enabled_visible_action(self): - """ - Test creating an action with the 'checked', 'enabled' and 'visible' properties. - """ - # GIVEN: A dialog - dialog = QtGui.QDialog() - - # WHEN: We create an action with some properties - action = create_action(dialog, 'my_action', checked=True, enabled=False, visible=False) - - # THEN: These properties should be set - self.assertEqual(True, action.isChecked()) - self.assertEqual(False, action.isEnabled()) - self.assertEqual(False, action.isVisible()) - - def test_create_valign_selection_widgets(self): + def create_valign_selection_widgets_test(self): """ Test creating a combo box for valign selection """ @@ -214,7 +199,7 @@ class TestUi(TestCase): for text in [UiStrings().Top, UiStrings().Middle, UiStrings().Bottom]: self.assertTrue(combo.findText(text) >= 0) - def test_find_and_set_in_combo_box(self): + def find_and_set_in_combo_box_test(self): """ Test finding a string in a combo box and setting it as the selected item if present """ @@ -241,7 +226,7 @@ class TestUi(TestCase): # THEN: The index should have changed self.assertEqual(2, combo.currentIndex()) - def test_create_widget_action(self): + def create_widget_action_test(self): """ Test creating an action for a widget """ @@ -255,7 +240,7 @@ class TestUi(TestCase): self.assertIsInstance(action, QtGui.QAction) self.assertEqual(action.objectName(), 'some action') - def test_set_case_insensitive_completer(self): + def set_case_insensitive_completer_test(self): """ Test setting a case insensitive completer on a widget """ From 48abd1793baeaed79f9bfe224fb515f7f8bbfe53 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Sun, 14 Sep 2014 15:35:55 +0200 Subject: [PATCH 4/4] Fix loading authors Fixes: https://launchpad.net/bugs/1366198 --- openlp/plugins/songs/lib/db.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openlp/plugins/songs/lib/db.py b/openlp/plugins/songs/lib/db.py index 895dba4b5..3afba1b66 100644 --- a/openlp/plugins/songs/lib/db.py +++ b/openlp/plugins/songs/lib/db.py @@ -339,7 +339,8 @@ def init_schema(url): # Use the authors_songs relation when you need access to the 'author_type' attribute # or when creating new relations 'authors_songs': relation(AuthorSong, cascade="all, delete-orphan"), - 'authors': relation(Author, secondary=authors_songs_table, viewonly=True), + # Use lazy='joined' to always load authors when the song is fetched from the database (bug 1366198) + 'authors': relation(Author, secondary=authors_songs_table, viewonly=True, lazy='joined'), 'book': relation(Book, backref='songs'), 'media_files': relation(MediaFile, backref='songs', order_by=media_files_table.c.weight), 'topics': relation(Topic, backref='songs', secondary=songs_topics_table)