From d42f64e044b29930012e41cd842d47f6c73f0f42 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Wed, 3 Apr 2013 12:33:29 +0200 Subject: [PATCH 1/8] An attempt to move from migrate to alembic. --- openlp/plugins/songs/lib/upgrade.py | 38 ++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/openlp/plugins/songs/lib/upgrade.py b/openlp/plugins/songs/lib/upgrade.py index abb2f9520..edff8d9f3 100644 --- a/openlp/plugins/songs/lib/upgrade.py +++ b/openlp/plugins/songs/lib/upgrade.py @@ -33,10 +33,18 @@ backend for the Songs plugin from sqlalchemy import Column, Table, types from sqlalchemy.sql.expression import func -from migrate.changeset.constraint import ForeignKeyConstraint +#from migrate.changeset.constraint import ForeignKeyConstraint +from alembic.migration import MigrationContext +from alembic.operations import Operations __version__ = 3 + +def get_alembic_operation(session): + context = MigrationContext(session.bind.connect()) + return Operations(context) + + def upgrade_setup(metadata): """ Set up the latest revision all tables, with reflection, needed for the @@ -67,13 +75,20 @@ def upgrade_1(session, metadata, tables): added to the media_files table, and a weight column so that the media files can be ordered. """ - Table(u'media_files_songs', metadata, autoload=True).drop(checkfirst=True) - Column(u'song_id', types.Integer(), default=None).create(table=tables[u'media_files']) - Column(u'weight', types.Integer(), default=0).create(table=tables[u'media_files']) + #Table(u'media_files_songs', metadata, autoload=True).drop(checkfirst=True) + #Column(u'song_id', types.Integer(), default=None).create(table=tables[u'media_files']) + #Column(u'weight', types.Integer(), default=0).create(table=tables[u'media_files']) + #if metadata.bind.url.get_dialect().name != 'sqlite': + # # SQLite doesn't support ALTER TABLE ADD CONSTRAINT + # ForeignKeyConstraint([u'song_id'], [u'songs.id'], + # table=tables[u'media_files']).create() + op = get_alembic_operation(session) + op.drop_table(u'media_files_songs') + op.add_column(u'media_files', Column(u'song_id', types.Integer(), default=None)) + op.add_column(u'media_files', Column(u'weight', types.Integer(), default=0)) if metadata.bind.url.get_dialect().name != 'sqlite': # SQLite doesn't support ALTER TABLE ADD CONSTRAINT - ForeignKeyConstraint([u'song_id'], [u'songs.id'], - table=tables[u'media_files']).create() + op.create_foreign_key(u'fk_media_files_song_id', u'media_files', u'songs', [u'song_id', u'id']) def upgrade_2(session, metadata, tables): @@ -82,8 +97,11 @@ def upgrade_2(session, metadata, tables): This upgrade adds a create_date and last_modified date to the songs table """ - Column(u'create_date', types.DateTime(), default=func.now()).create(table=tables[u'songs']) - Column(u'last_modified', types.DateTime(), default=func.now()).create(table=tables[u'songs']) + #Column(u'create_date', types.DateTime(), default=func.now()).create(table=tables[u'songs']) + #Column(u'last_modified', types.DateTime(), default=func.now()).create(table=tables[u'songs']) + op = get_alembic_operation(session) + op.add_column(u'songs', Column(u'create_date', types.DateTime(), default=func.now())) + op.add_column(u'songs', Column(u'last_modified', types.DateTime(), default=func.now())) def upgrade_3(session, metadata, tables): @@ -92,5 +110,7 @@ def upgrade_3(session, metadata, tables): This upgrade adds a temporary song flag to the songs table """ - Column(u'temporary', types.Boolean(), default=False).create(table=tables[u'songs']) + #Column(u'temporary', types.Boolean(), default=False).create(table=tables[u'songs']) + op = get_alembic_operation(session) + op.add_column(u'songs', Column(u'temporary', types.Boolean(), default=False)) From d88e8a0b02af2739f1da05a6cd1dc178244759d5 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Wed, 3 Apr 2013 21:46:41 +0200 Subject: [PATCH 2/8] Migrated to Alembic (if you'll excuse the pun) --- openlp/core/lib/db.py | 31 +++++++++------ openlp/plugins/bibles/lib/upgrade.py | 19 +-------- openlp/plugins/songs/lib/upgrade.py | 51 ++++--------------------- openlp/plugins/songusage/lib/upgrade.py | 23 +++-------- setup.py | 2 + 5 files changed, 37 insertions(+), 89 deletions(-) diff --git a/openlp/core/lib/db.py b/openlp/core/lib/db.py index c6bce2a00..b4e3af86e 100644 --- a/openlp/core/lib/db.py +++ b/openlp/core/lib/db.py @@ -38,6 +38,8 @@ from sqlalchemy import Table, MetaData, Column, types, create_engine from sqlalchemy.exc import SQLAlchemyError, InvalidRequestError, DBAPIError, OperationalError from sqlalchemy.orm import scoped_session, sessionmaker, mapper from sqlalchemy.pool import NullPool +from alembic.migration import MigrationContext +from alembic.operations import Operations from openlp.core.lib import translate, Settings from openlp.core.lib.ui import critical_error_message_box @@ -65,6 +67,17 @@ def init_db(url, auto_flush=True, auto_commit=False): return session, metadata +def get_upgrade_op(session): + """ + Create a migration context and an operations object for performing upgrades. + + ``session`` + The SQLAlchemy session object. + """ + context = MigrationContext(session.bind.connect()) + return Operations(context) + + def upgrade_db(url, upgrade): """ Upgrade a database. @@ -82,13 +95,7 @@ def upgrade_db(url, upgrade): Provides a class for the metadata table. """ pass - load_changes = False - tables = [] - try: - tables = upgrade.upgrade_setup(metadata) - load_changes = True - except (SQLAlchemyError, DBAPIError): - pass + metadata_table = Table(u'metadata', metadata, Column(u'key', types.Unicode(64), primary_key=True), Column(u'value', types.UnicodeText(), default=None) @@ -105,22 +112,22 @@ def upgrade_db(url, upgrade): if version > upgrade.__version__: return version, upgrade.__version__ version += 1 - if load_changes: + try: while hasattr(upgrade, u'upgrade_%d' % version): log.debug(u'Running upgrade_%d', version) try: upgrade_func = getattr(upgrade, u'upgrade_%d' % version) - upgrade_func(session, metadata, tables) + upgrade_func(session, metadata) session.commit() # Update the version number AFTER a commit so that we are sure the previous transaction happened version_meta.value = unicode(version) session.commit() version += 1 except (SQLAlchemyError, DBAPIError): - log.exception(u'Could not run database upgrade script ' - '"upgrade_%s", upgrade process has been halted.', version) + log.exception(u'Could not run database upgrade script "upgrade_%s", upgrade process has been halted.', + version) break - else: + except (SQLAlchemyError, DBAPIError): version_meta = Metadata.populate(key=u'version', value=int(upgrade.__version__)) session.commit() return int(version_meta.value), upgrade.__version__ diff --git a/openlp/plugins/bibles/lib/upgrade.py b/openlp/plugins/bibles/lib/upgrade.py index b4a358c45..a19582cd9 100644 --- a/openlp/plugins/bibles/lib/upgrade.py +++ b/openlp/plugins/bibles/lib/upgrade.py @@ -38,28 +38,13 @@ __version__ = 1 log = logging.getLogger(__name__) -def upgrade_setup(metadata): - """ - Set up the latest revision all tables, with reflection, needed for the - upgrade process. If you want to drop a table, you need to remove it from - here, and add it to your upgrade function. - """ - # Don't define the "metadata" table, as the upgrade mechanism already - # defines it. - tables = { - u'book': Table(u'book', metadata, autoload=True), - u'verse': Table(u'verse', metadata, autoload=True) - } - return tables - - -def upgrade_1(session, metadata, tables): +def upgrade_1(session, metadata): """ Version 1 upgrade. This upgrade renames a number of keys to a single naming convention. """ - metadata_table = metadata.tables[u'metadata'] + metadata_table = Table(u'metadata', metadata, autoload=True) # Copy "Version" to "name" ("version" used by upgrade system) # TODO: Clean up in a subsequent release of OpenLP (like 2.0 final) session.execute(insert(metadata_table).values( diff --git a/openlp/plugins/songs/lib/upgrade.py b/openlp/plugins/songs/lib/upgrade.py index edff8d9f3..47cf5df81 100644 --- a/openlp/plugins/songs/lib/upgrade.py +++ b/openlp/plugins/songs/lib/upgrade.py @@ -31,39 +31,14 @@ The :mod:`upgrade` module provides a way for the database and schema that is the backend for the Songs plugin """ -from sqlalchemy import Column, Table, types +from sqlalchemy import Column, types from sqlalchemy.sql.expression import func -#from migrate.changeset.constraint import ForeignKeyConstraint -from alembic.migration import MigrationContext -from alembic.operations import Operations +from openlp.core.lib.db import get_upgrade_op __version__ = 3 -def get_alembic_operation(session): - context = MigrationContext(session.bind.connect()) - return Operations(context) - - -def upgrade_setup(metadata): - """ - Set up the latest revision all tables, with reflection, needed for the - upgrade process. If you want to drop a table, you need to remove it from - here, and add it to your upgrade function. - """ - tables = { - u'authors': Table(u'authors', metadata, autoload=True), - u'media_files': Table(u'media_files', metadata, autoload=True), - u'song_books': Table(u'song_books', metadata, autoload=True), - u'songs': Table(u'songs', metadata, autoload=True), - u'topics': Table(u'topics', metadata, autoload=True), - u'authors_songs': Table(u'authors_songs', metadata, autoload=True), - u'songs_topics': Table(u'songs_topics', metadata, autoload=True) - } - return tables - - -def upgrade_1(session, metadata, tables): +def upgrade_1(session, metadata): """ Version 1 upgrade. @@ -75,14 +50,7 @@ def upgrade_1(session, metadata, tables): added to the media_files table, and a weight column so that the media files can be ordered. """ - #Table(u'media_files_songs', metadata, autoload=True).drop(checkfirst=True) - #Column(u'song_id', types.Integer(), default=None).create(table=tables[u'media_files']) - #Column(u'weight', types.Integer(), default=0).create(table=tables[u'media_files']) - #if metadata.bind.url.get_dialect().name != 'sqlite': - # # SQLite doesn't support ALTER TABLE ADD CONSTRAINT - # ForeignKeyConstraint([u'song_id'], [u'songs.id'], - # table=tables[u'media_files']).create() - op = get_alembic_operation(session) + op = get_upgrade_op(session) op.drop_table(u'media_files_songs') op.add_column(u'media_files', Column(u'song_id', types.Integer(), default=None)) op.add_column(u'media_files', Column(u'weight', types.Integer(), default=0)) @@ -91,26 +59,23 @@ def upgrade_1(session, metadata, tables): op.create_foreign_key(u'fk_media_files_song_id', u'media_files', u'songs', [u'song_id', u'id']) -def upgrade_2(session, metadata, tables): +def upgrade_2(session, metadata): """ Version 2 upgrade. This upgrade adds a create_date and last_modified date to the songs table """ - #Column(u'create_date', types.DateTime(), default=func.now()).create(table=tables[u'songs']) - #Column(u'last_modified', types.DateTime(), default=func.now()).create(table=tables[u'songs']) - op = get_alembic_operation(session) + op = get_upgrade_op(session) op.add_column(u'songs', Column(u'create_date', types.DateTime(), default=func.now())) op.add_column(u'songs', Column(u'last_modified', types.DateTime(), default=func.now())) -def upgrade_3(session, metadata, tables): +def upgrade_3(session, metadata): """ Version 3 upgrade. This upgrade adds a temporary song flag to the songs table """ - #Column(u'temporary', types.Boolean(), default=False).create(table=tables[u'songs']) - op = get_alembic_operation(session) + op = get_upgrade_op(session) op.add_column(u'songs', Column(u'temporary', types.Boolean(), default=False)) diff --git a/openlp/plugins/songusage/lib/upgrade.py b/openlp/plugins/songusage/lib/upgrade.py index a783ff8e3..9ea048261 100644 --- a/openlp/plugins/songusage/lib/upgrade.py +++ b/openlp/plugins/songusage/lib/upgrade.py @@ -30,30 +30,19 @@ The :mod:`upgrade` module provides a way for the database and schema that is the backend for the SongsUsage plugin """ +from openlp.core.lib.db import get_upgrade_op -from sqlalchemy import Column, Table, types +from sqlalchemy import Column, types __version__ = 1 -def upgrade_setup(metadata): - """ - Set up the latest revision all tables, with reflection, needed for the - upgrade process. If you want to drop a table, you need to remove it from - here, and add it to your upgrade function. - """ - tables = { - u'songusage_data': Table(u'songusage_data', metadata, autoload=True) - } - return tables - -def upgrade_1(session, metadata, tables): +def upgrade_1(session, metadata): """ Version 1 upgrade. This upgrade adds two new fields to the songusage database """ - Column(u'plugin_name', types.Unicode(20), default=u'') \ - .create(table=tables[u'songusage_data'], populate_default=True) - Column(u'source', types.Unicode(10), default=u'') \ - .create(table=tables[u'songusage_data'], populate_default=True) + op = get_upgrade_op(session) + op.add_column(u'songusage_data', Column(u'plugin_name', types.Unicode(20), server_default=u'')) + op.add_column(u'songusage_data', Column(u'source', types.Unicode(10), server_default=u'')) diff --git a/setup.py b/setup.py index a96259380..8ba2e0942 100755 --- a/setup.py +++ b/setup.py @@ -157,6 +157,8 @@ OpenLP (previously openlp.org) is free church presentation software, or lyrics p zip_safe=False, install_requires=[ # -*- Extra requirements: -*- + 'sqlalchemy', + 'alembic' ], entry_points=""" # -*- Entry points: -*- From 9430e569f4491b3b83b6c9fc4cf15aaaef7f1df5 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 4 Apr 2013 10:02:47 +0200 Subject: [PATCH 3/8] Fix one small issue with the songs upgrade scripts. --- openlp/core/lib/db.py | 2 +- openlp/plugins/songs/lib/upgrade.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/openlp/core/lib/db.py b/openlp/core/lib/db.py index b4e3af86e..dfc12608f 100644 --- a/openlp/core/lib/db.py +++ b/openlp/core/lib/db.py @@ -74,7 +74,7 @@ def get_upgrade_op(session): ``session`` The SQLAlchemy session object. """ - context = MigrationContext(session.bind.connect()) + context = MigrationContext.configure(session.bind.connect()) return Operations(context) diff --git a/openlp/plugins/songs/lib/upgrade.py b/openlp/plugins/songs/lib/upgrade.py index 47cf5df81..0aff8d0cb 100644 --- a/openlp/plugins/songs/lib/upgrade.py +++ b/openlp/plugins/songs/lib/upgrade.py @@ -32,7 +32,7 @@ backend for the Songs plugin """ from sqlalchemy import Column, types -from sqlalchemy.sql.expression import func +from sqlalchemy.sql.expression import func, false, null from openlp.core.lib.db import get_upgrade_op __version__ = 3 @@ -52,8 +52,8 @@ def upgrade_1(session, metadata): """ op = get_upgrade_op(session) op.drop_table(u'media_files_songs') - op.add_column(u'media_files', Column(u'song_id', types.Integer(), default=None)) - op.add_column(u'media_files', Column(u'weight', types.Integer(), default=0)) + op.add_column(u'media_files', Column(u'song_id', types.Integer(), server_default=null())) + op.add_column(u'media_files', Column(u'weight', types.Integer(), server_default=0)) if metadata.bind.url.get_dialect().name != 'sqlite': # SQLite doesn't support ALTER TABLE ADD CONSTRAINT op.create_foreign_key(u'fk_media_files_song_id', u'media_files', u'songs', [u'song_id', u'id']) @@ -66,8 +66,8 @@ def upgrade_2(session, metadata): This upgrade adds a create_date and last_modified date to the songs table """ op = get_upgrade_op(session) - op.add_column(u'songs', Column(u'create_date', types.DateTime(), default=func.now())) - op.add_column(u'songs', Column(u'last_modified', types.DateTime(), default=func.now())) + op.add_column(u'songs', Column(u'create_date', types.DateTime(), server_default=func.now())) + op.add_column(u'songs', Column(u'last_modified', types.DateTime(), server_default=func.now())) def upgrade_3(session, metadata): @@ -77,5 +77,5 @@ def upgrade_3(session, metadata): This upgrade adds a temporary song flag to the songs table """ op = get_upgrade_op(session) - op.add_column(u'songs', Column(u'temporary', types.Boolean(), default=False)) + op.add_column(u'songs', Column(u'temporary', types.Boolean(), server_default=false())) From e15865c117d37972a9a3b8ad4524814c4fae729b Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 4 Apr 2013 21:51:37 +0200 Subject: [PATCH 4/8] Finally have bullet-proof upgrade methods. --- openlp/plugins/songs/lib/upgrade.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/openlp/plugins/songs/lib/upgrade.py b/openlp/plugins/songs/lib/upgrade.py index 0aff8d0cb..2667a4f07 100644 --- a/openlp/plugins/songs/lib/upgrade.py +++ b/openlp/plugins/songs/lib/upgrade.py @@ -32,7 +32,7 @@ backend for the Songs plugin """ from sqlalchemy import Column, types -from sqlalchemy.sql.expression import func, false, null +from sqlalchemy.sql.expression import func, false, null, text from openlp.core.lib.db import get_upgrade_op __version__ = 3 @@ -53,7 +53,7 @@ def upgrade_1(session, metadata): op = get_upgrade_op(session) op.drop_table(u'media_files_songs') op.add_column(u'media_files', Column(u'song_id', types.Integer(), server_default=null())) - op.add_column(u'media_files', Column(u'weight', types.Integer(), server_default=0)) + op.add_column(u'media_files', Column(u'weight', types.Integer(), server_default=text(u'0'))) if metadata.bind.url.get_dialect().name != 'sqlite': # SQLite doesn't support ALTER TABLE ADD CONSTRAINT op.create_foreign_key(u'fk_media_files_song_id', u'media_files', u'songs', [u'song_id', u'id']) @@ -66,8 +66,8 @@ def upgrade_2(session, metadata): This upgrade adds a create_date and last_modified date to the songs table """ op = get_upgrade_op(session) - op.add_column(u'songs', Column(u'create_date', types.DateTime(), server_default=func.now())) - op.add_column(u'songs', Column(u'last_modified', types.DateTime(), server_default=func.now())) + op.add_column(u'songs', Column(u'create_date', types.DateTime(), default=func.now())) + op.add_column(u'songs', Column(u'last_modified', types.DateTime(), default=func.now())) def upgrade_3(session, metadata): @@ -77,5 +77,8 @@ def upgrade_3(session, metadata): This upgrade adds a temporary song flag to the songs table """ op = get_upgrade_op(session) - op.add_column(u'songs', Column(u'temporary', types.Boolean(), server_default=false())) + if metadata.bind.url.get_dialect().name == 'sqlite': + op.add_column(u'songs', Column(u'temporary', types.Boolean(create_constraint=False), server_default=false())) + else: + op.add_column(u'songs', Column(u'temporary', types.Boolean(), server_default=false())) From e6a1d931213d32297d8f8df571d9fb17da85c3f6 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Mon, 8 Apr 2013 23:08:28 +0200 Subject: [PATCH 5/8] Add tests around some of the functions in the db module - Fix some import ordering - Add tests for init_db and get_upgrade_op - Add an extra line for PEP8 compliance --- openlp/plugins/songs/lib/upgrade.py | 1 + tests/functional/openlp_core_lib/test_db.py | 84 ++++++++++++++++++++ tests/functional/openlp_core_lib/test_lib.py | 1 + 3 files changed, 86 insertions(+) create mode 100644 tests/functional/openlp_core_lib/test_db.py diff --git a/openlp/plugins/songs/lib/upgrade.py b/openlp/plugins/songs/lib/upgrade.py index 2667a4f07..471cc1b7c 100644 --- a/openlp/plugins/songs/lib/upgrade.py +++ b/openlp/plugins/songs/lib/upgrade.py @@ -33,6 +33,7 @@ backend for the Songs plugin from sqlalchemy import Column, types from sqlalchemy.sql.expression import func, false, null, text + from openlp.core.lib.db import get_upgrade_op __version__ = 3 diff --git a/tests/functional/openlp_core_lib/test_db.py b/tests/functional/openlp_core_lib/test_db.py new file mode 100644 index 000000000..ce1e9012b --- /dev/null +++ b/tests/functional/openlp_core_lib/test_db.py @@ -0,0 +1,84 @@ +""" +Package to test the openlp.core.lib package. +""" +from unittest import TestCase + +from mock import MagicMock, patch +from sqlalchemy.pool import NullPool +from sqlalchemy.orm import ScopedSession +from sqlalchemy import MetaData + +from openlp.core.lib.db import init_db, get_upgrade_op + + +class TestDB(TestCase): + """ + A test case for all the tests for the :mod:`~openlp.core.lib.db` module. + """ + def init_db_calls_correct_functions_test(self): + """ + Test that the init_db function makes the correct function calls + """ + # GIVEN: Mocked out SQLAlchemy calls and return objects, and an in-memory SQLite database URL + with patch(u'openlp.core.lib.db.create_engine') as mocked_create_engine, \ + patch(u'openlp.core.lib.db.MetaData') as MockedMetaData, \ + patch(u'openlp.core.lib.db.sessionmaker') as mocked_sessionmaker, \ + patch(u'openlp.core.lib.db.scoped_session') as mocked_scoped_session: + mocked_engine = MagicMock() + mocked_metadata = MagicMock() + mocked_sessionmaker_object = MagicMock() + mocked_scoped_session_object = MagicMock() + mocked_create_engine.return_value = mocked_engine + MockedMetaData.return_value = mocked_metadata + mocked_sessionmaker.return_value = mocked_sessionmaker_object + mocked_scoped_session.return_value = mocked_scoped_session_object + db_url = u'sqlite://' + + # WHEN: We try to initialise the db + session, metadata = init_db(db_url) + + # THEN: We should see the correct function calls + mocked_create_engine.assert_called_with(db_url, poolclass=NullPool) + MockedMetaData.assert_called_with(bind=mocked_engine) + mocked_sessionmaker.assert_called_with(autoflush=True, autocommit=False, bind=mocked_engine) + mocked_scoped_session.assert_called_with(mocked_sessionmaker_object) + self.assertIs(session, mocked_scoped_session_object, u'The ``session`` object should be the mock') + self.assertIs(metadata, mocked_metadata, u'The ``metadata`` object should be the mock') + + def init_db_defaults_test(self): + """ + Test that initialising an in-memory SQLite database via ``init_db`` uses the defaults + """ + # GIVEN: An in-memory SQLite URL + db_url = u'sqlite://' + + # WHEN: The database is initialised through init_db + session, metadata = init_db(db_url) + + # THEN: Valid session and metadata objects should be returned + self.assertIsInstance(session, ScopedSession, u'The ``session`` object should be a ``ScopedSession`` instance') + self.assertIsInstance(metadata, MetaData, u'The ``metadata`` object should be a ``MetaData`` instance') + + def get_upgrade_op_test(self): + """ + Test that the ``get_upgrade_op`` function creates a MigrationContext and an Operations object + """ + # GIVEN: Mocked out alembic classes and a mocked out SQLAlchemy session object + with patch(u'openlp.core.lib.db.MigrationContext') as MockedMigrationContext, \ + patch(u'openlp.core.lib.db.Operations') as MockedOperations: + mocked_context = MagicMock() + mocked_op = MagicMock() + mocked_connection = MagicMock() + MockedMigrationContext.configure.return_value = mocked_context + MockedOperations.return_value = mocked_op + mocked_session = MagicMock() + mocked_session.bind.connect.return_value = mocked_connection + + # WHEN: get_upgrade_op is executed with the mocked session object + op = get_upgrade_op(mocked_session) + + # THEN: The op object should be mocked_op, and the correction function calls should have been made + self.assertIs(op, mocked_op, u'The return value should be the mocked object') + mocked_session.bind.connect.assert_called_with() + MockedMigrationContext.configure.assert_called_with(mocked_connection) + MockedOperations.assert_called_with(mocked_context) diff --git a/tests/functional/openlp_core_lib/test_lib.py b/tests/functional/openlp_core_lib/test_lib.py index 66cb834f1..d6bc54b79 100644 --- a/tests/functional/openlp_core_lib/test_lib.py +++ b/tests/functional/openlp_core_lib/test_lib.py @@ -9,6 +9,7 @@ from mock import MagicMock, patch from openlp.core.lib import str_to_bool, translate, check_directory_exists, get_text_file_string, build_icon, \ image_to_byte, check_item_selected, validate_thumb, create_separated_list, clean_tags, expand_tags + class TestLib(TestCase): def str_to_bool_with_bool_test(self): From 8492ae6a4c9427277dccd9cc59095e9a3cb36cea Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Tue, 2 Jul 2013 22:27:28 +0200 Subject: [PATCH 6/8] Fix a bug in SQLAlchemy 0.8 --- tests/functional/openlp_core_lib/test_db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/openlp_core_lib/test_db.py b/tests/functional/openlp_core_lib/test_db.py index ce1e9012b..d9233117a 100644 --- a/tests/functional/openlp_core_lib/test_db.py +++ b/tests/functional/openlp_core_lib/test_db.py @@ -5,7 +5,7 @@ from unittest import TestCase from mock import MagicMock, patch from sqlalchemy.pool import NullPool -from sqlalchemy.orm import ScopedSession +from sqlalchemy.orm.scoping import ScopedSession from sqlalchemy import MetaData from openlp.core.lib.db import init_db, get_upgrade_op From 2e4b400cbce50da7157f5fad26a9ecad56f77115 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Tue, 2 Jul 2013 22:39:39 +0200 Subject: [PATCH 7/8] Removed a test that seemed in the wrong place, testing the wrong things, and committed at the wrong time. --- .../openlp_core_lib/test_serviceitem.py | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_serviceitem.py b/tests/functional/openlp_core_lib/test_serviceitem.py index 4e777b953..5ffb5e9b2 100644 --- a/tests/functional/openlp_core_lib/test_serviceitem.py +++ b/tests/functional/openlp_core_lib/test_serviceitem.py @@ -18,6 +18,7 @@ VERSE = u'The Lord said to {r}Noah{/r}: \n'\ '{r}C{/r}{b}h{/b}{bl}i{/bl}{y}l{/y}{g}d{/g}{pk}'\ 'r{/pk}{o}e{/o}{pp}n{/pp} of the Lord\n' FOOTER = [u'Arky Arky (Unknown)', u'Public Domain', u'CCLI 123456'] +TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'..', u'..', u'resources')) class TestServiceItem(TestCase): @@ -262,23 +263,3 @@ class TestServiceItem(TestCase): u'This service item should be able to be run in a can be made to Loop' assert service_item.is_capable(ItemCapabilities.CanAppend) is True, \ u'This service item should be able to have new items added to it' - - def serviceitem_migrate_test_20_22(self): - """ - Test the Service Item - migrating a media only service item from 2.0 to 2.2 format - """ - # GIVEN: A new service item and a mocked add icon function - service_item = ServiceItem(None) - service_item.add_icon = MagicMock() - - # WHEN: adding an media from a saved Service and mocked exists - line = self.convert_file_service_item(u'migrate_video_20_22.osd') - with patch('os.path.exists'): - service_item.set_from_service(line, TEST_PATH) - - # THEN: We should get back a converted service item - assert service_item.is_valid is True, u'The new service item should be valid' - assert service_item.processor is None, u'The Processor should have been set' - assert service_item.title is None, u'The title should be set to a value' - assert service_item.is_capable(ItemCapabilities.HasDetailedTitleDisplay) is False, \ - u'The Capability should have been removed' From cee5132b86033faec8b9c15c42914de063064d37 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Fri, 5 Jul 2013 09:47:09 +0200 Subject: [PATCH 8/8] Removed a remnant of Tim's test --- tests/functional/openlp_core_lib/test_serviceitem.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/functional/openlp_core_lib/test_serviceitem.py b/tests/functional/openlp_core_lib/test_serviceitem.py index fa14f2393..fdeb081b3 100644 --- a/tests/functional/openlp_core_lib/test_serviceitem.py +++ b/tests/functional/openlp_core_lib/test_serviceitem.py @@ -18,7 +18,6 @@ VERSE = u'The Lord said to {r}Noah{/r}: \n'\ '{r}C{/r}{b}h{/b}{bl}i{/bl}{y}l{/y}{g}d{/g}{pk}'\ 'r{/pk}{o}e{/o}{pp}n{/pp} of the Lord\n' FOOTER = [u'Arky Arky (Unknown)', u'Public Domain', u'CCLI 123456'] -TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'..', u'..', u'resources')) class TestServiceItem(TestCase):