diff options
| author | Barry Warsaw | 2012-07-25 23:40:46 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2012-07-25 23:40:46 -0400 |
| commit | 30ecd410ba83dc32ad021a2d2c841761befe3079 (patch) | |
| tree | c485245a23e3fee9af5f74a46bb9ee6a7d5888fd /src/mailman/database | |
| parent | b60f54fedab835f214f3c88e990ff3bb098e6cad (diff) | |
| download | mailman-30ecd410ba83dc32ad021a2d2c841761befe3079.tar.gz mailman-30ecd410ba83dc32ad021a2d2c841761befe3079.tar.zst mailman-30ecd410ba83dc32ad021a2d2c841761befe3079.zip | |
Working for SQLite:
include_list_post_header -> allow_list_posts
Also add a bunch more migration tests.
Diffstat (limited to 'src/mailman/database')
| -rw-r--r-- | src/mailman/database/schema/mm_20120407000000.py | 24 | ||||
| -rw-r--r-- | src/mailman/database/schema/sqlite_20120407000000_01.sql | 6 | ||||
| -rw-r--r-- | src/mailman/database/tests/test_migrations.py | 91 |
3 files changed, 105 insertions, 16 deletions
diff --git a/src/mailman/database/schema/mm_20120407000000.py b/src/mailman/database/schema/mm_20120407000000.py index 9ed99e225..95b56c939 100644 --- a/src/mailman/database/schema/mm_20120407000000.py +++ b/src/mailman/database/schema/mm_20120407000000.py @@ -76,20 +76,26 @@ def upgrade_sqlite(database, store, version, module_path): database.load_schema( store, version, 'sqlite_{0}_01.sql'.format(version), module_path) results = store.execute( - 'SELECT id, news_prefix_subject_too, news_moderation, ' + 'SELECT id, include_list_post_header, ' + 'news_prefix_subject_too, news_moderation, ' 'archive, archive_private FROM mailinglist;') for value in results: - id, news_prefix, news_moderation, archive, archive_private = value + (id, list_post, + news_prefix, news_moderation, + archive, archive_private) = value # Figure out what the new archive_policy column value should be. store.execute( 'UPDATE ml_backup SET ' - ' newsgroup_moderation = {0}, ' - ' nntp_prefix_subject_too = {1}, ' - ' archive_policy = {2} ' - 'WHERE id = {3};'.format(news_moderation, - news_prefix, - archive_policy(archive, archive_private), - id)) + ' allow_list_posts = {0}, ' + ' newsgroup_moderation = {1}, ' + ' nntp_prefix_subject_too = {2}, ' + ' archive_policy = {3} ' + 'WHERE id = {4};'.format( + list_post, + news_moderation, + news_prefix, + archive_policy(archive, archive_private), + id)) store.execute('DROP TABLE mailinglist;') store.execute('ALTER TABLE ml_backup RENAME TO mailinglist;') diff --git a/src/mailman/database/schema/sqlite_20120407000000_01.sql b/src/mailman/database/schema/sqlite_20120407000000_01.sql index 58201fb9b..e5d3a39ff 100644 --- a/src/mailman/database/schema/sqlite_20120407000000_01.sql +++ b/src/mailman/database/schema/sqlite_20120407000000_01.sql @@ -10,22 +10,26 @@ -- REM archive -- REM archive_private -- REM archive_volume_frequency +-- REM include_list_post_header -- REM news_moderation -- REM news_prefix_subject_too -- REM nntp_host -- -- THESE COLUMNS ARE ADDED BY THE PYTHON MIGRATION LAYER: +-- ADD allow_list_posts -- ADD archive_policy -- ADD newsgroup_moderation -- ADD nntp_prefix_subject_too + -- LP: #971013 +-- LP: #967238 CREATE TABLE ml_backup( id INTEGER NOT NULL, -- List identity list_name TEXT, mail_host TEXT, - include_list_post_header BOOLEAN, + allow_list_posts BOOLEAN, include_rfc2369_headers BOOLEAN, -- Attributes not directly modifiable via the web u/i created_at TIMESTAMP, diff --git a/src/mailman/database/tests/test_migrations.py b/src/mailman/database/tests/test_migrations.py index c0ff80f74..6ad648623 100644 --- a/src/mailman/database/tests/test_migrations.py +++ b/src/mailman/database/tests/test_migrations.py @@ -21,9 +21,9 @@ from __future__ import absolute_import, print_function, unicode_literals __metaclass__ = type __all__ = [ - 'TestMigration20120407ArchiveData', - 'TestMigration20120407Data', + 'TestMigration20120407MigratedData', 'TestMigration20120407Schema', + 'TestMigration20120407UnchangedData', ] @@ -38,6 +38,7 @@ from mailman.interfaces.domain import IDomainManager from mailman.interfaces.archiver import ArchivePolicy from mailman.interfaces.listmanager import IListManager from mailman.interfaces.mailinglist import IAcceptableAliasSet +from mailman.interfaces.nntp import NewsgroupModeration from mailman.testing.helpers import temporary_db from mailman.testing.layers import ConfigLayer @@ -51,6 +52,7 @@ class MigrationTestBase(unittest.TestCase): table mailinglist: * news_moderation -> newsgroup_moderation * news_prefix_subject_too -> nntp_prefix_subject_too + * include_list_post_header -> allow_list_posts * ADD archive_policy * REMOVE archive * REMOVE archive_private @@ -79,7 +81,8 @@ class TestMigration20120407Schema(MigrationTestBase): self._database.load_migrations('20120406999999') self._database.store.commit() # Verify that the database has not yet been migrated. - for missing in ('archive_policy', + for missing in ('allow_list_posts', + 'archive_policy', 'nntp_prefix_subject_too'): self.assertRaises(DatabaseError, self._database.store.execute, @@ -88,6 +91,7 @@ class TestMigration20120407Schema(MigrationTestBase): for present in ('archive', 'archive_private', 'archive_volume_frequency', + 'include_list_post_header', 'news_moderation', 'news_prefix_subject_too', 'nntp_host'): @@ -104,7 +108,8 @@ class TestMigration20120407Schema(MigrationTestBase): self._database.load_migrations('20120406999999') self._database.load_migrations('20120407000000') # Verify that the database has been migrated. - for present in ('archive_policy', + for present in ('allow_list_posts', + 'archive_policy', 'nntp_prefix_subject_too'): # This should not produce an exception. Is there some better test # that we can perform? @@ -113,6 +118,7 @@ class TestMigration20120407Schema(MigrationTestBase): for missing in ('archive', 'archive_private', 'archive_volume_frequency', + 'include_list_post_header', 'news_moderation', 'news_prefix_subject_too', 'nntp_host'): @@ -123,7 +129,7 @@ class TestMigration20120407Schema(MigrationTestBase): -class TestMigration20120407Data(MigrationTestBase): +class TestMigration20120407UnchangedData(MigrationTestBase): """Test non-migrated data.""" def setUp(self): @@ -186,7 +192,7 @@ class TestMigration20120407Data(MigrationTestBase): -class TestMigration20120407ArchiveData(MigrationTestBase): +class TestMigration20120407MigratedData(MigrationTestBase): """Test affected migration data.""" def setUp(self): @@ -254,3 +260,76 @@ class TestMigration20120407ArchiveData(MigrationTestBase): with temporary_db(self._database): mlist = getUtility(IListManager).get('test@example.com') self.assertEqual(mlist.archive_policy, ArchivePolicy.public) + + def test_news_moderation_none(self): + # Test that news_moderation becomes newsgroup_moderation. + self._database.store.execute( + 'UPDATE mailinglist SET news_moderation = 0 ' + 'WHERE id = 1;') + self._upgrade() + with temporary_db(self._database): + mlist = getUtility(IListManager).get('test@example.com') + self.assertEqual(mlist.newsgroup_moderation, + NewsgroupModeration.none) + + def test_news_moderation_open_moderated(self): + # Test that news_moderation becomes newsgroup_moderation. + self._database.store.execute( + 'UPDATE mailinglist SET news_moderation = 1 ' + 'WHERE id = 1;') + self._upgrade() + with temporary_db(self._database): + mlist = getUtility(IListManager).get('test@example.com') + self.assertEqual(mlist.newsgroup_moderation, + NewsgroupModeration.open_moderated) + + def test_news_moderation_moderated(self): + # Test that news_moderation becomes newsgroup_moderation. + self._database.store.execute( + 'UPDATE mailinglist SET news_moderation = 2 ' + 'WHERE id = 1;') + self._upgrade() + with temporary_db(self._database): + mlist = getUtility(IListManager).get('test@example.com') + self.assertEqual(mlist.newsgroup_moderation, + NewsgroupModeration.moderated) + + def test_nntp_prefix_subject_too_false(self): + # Test that news_prefix_subject_too becomes nntp_prefix_subject_too. + self._database.store.execute( + 'UPDATE mailinglist SET news_prefix_subject_too = {0} ' + 'WHERE id = 1;'.format(self._database.FALSE)) + self._upgrade() + with temporary_db(self._database): + mlist = getUtility(IListManager).get('test@example.com') + self.assertFalse(mlist.nntp_prefix_subject_too) + + def test_nntp_prefix_subject_too_true(self): + # Test that news_prefix_subject_too becomes nntp_prefix_subject_too. + self._database.store.execute( + 'UPDATE mailinglist SET news_prefix_subject_too = {0} ' + 'WHERE id = 1;'.format(self._database.TRUE)) + self._upgrade() + with temporary_db(self._database): + mlist = getUtility(IListManager).get('test@example.com') + self.assertTrue(mlist.nntp_prefix_subject_too) + + def test_allow_list_posts_false(self): + # Test that include_list_post_header -> allow_list_posts. + self._database.store.execute( + 'UPDATE mailinglist SET include_list_post_header = {0} ' + 'WHERE id = 1;'.format(self._database.FALSE)) + self._upgrade() + with temporary_db(self._database): + mlist = getUtility(IListManager).get('test@example.com') + self.assertFalse(mlist.allow_list_posts) + + def test_allow_list_posts_true(self): + # Test that include_list_post_header -> allow_list_posts. + self._database.store.execute( + 'UPDATE mailinglist SET include_list_post_header = {0} ' + 'WHERE id = 1;'.format(self._database.TRUE)) + self._upgrade() + with temporary_db(self._database): + mlist = getUtility(IListManager).get('test@example.com') + self.assertTrue(mlist.allow_list_posts) |
