Fix author<->songs relation

bzr-revno: 2420
This commit is contained in:
Samuel Mehrbrodt 2014-09-17 21:42:28 +01:00 committed by Tim Bentley
commit 24e082cbf0
2 changed files with 23 additions and 9 deletions

View File

@ -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)
})
@ -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)

View File

@ -195,9 +195,9 @@ class TestUi(TestCase):
self.assertEqual(0, mocked_action.setIconVisibleInMenu.call_count,
'setIconVisibleInMenu should not have been called')
def create_checked_enabled_visible_action_test(self):
def create_checked_disabled_invisible_action_test(self):
"""
Test creating an action with the 'checked', 'enabled' and 'visible' properties.
Test that an invisible, disabled, checked action is created correctly
"""
# GIVEN: A dialog
dialog = QtGui.QDialog()
@ -206,9 +206,22 @@ class TestUi(TestCase):
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())
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 create_action_separator_test(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(), 'The action should be a separator')
def create_valign_selection_widgets_test(self):
"""