~barry/mailman/work1

« back to all changes in this revision

Viewing changes to src/mailman/database/tests/test_migrations.py

  • Committer: Barry Warsaw
  • Date: 2012-09-05 02:38:07 UTC
  • mfrom: (7167.1.3 bug-1024509)
  • Revision ID: barry@list.org-20120905023807-t3jb9q75m53sg93i
LP: #1024509 - Schema migration; link between members and mailing lists should
use List-ID.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
from mailman.interfaces.listmanager import IListManager
40
40
from mailman.interfaces.mailinglist import IAcceptableAliasSet
41
41
from mailman.interfaces.nntp import NewsgroupModeration
 
42
from mailman.interfaces.subscriptions import ISubscriptionService
42
43
from mailman.testing.helpers import temporary_db
43
44
from mailman.testing.layers import ConfigLayer
44
45
 
54
55
    * news_prefix_subject_too -> nntp_prefix_subject_too
55
56
    * include_list_post_header -> allow_list_posts
56
57
    * ADD archive_policy
 
58
    * ADD list_id
57
59
    * REMOVE archive
58
60
    * REMOVE archive_private
59
61
    * REMOVE archive_volume_frequency
60
62
    * REMOVE nntp_host
 
63
 
 
64
    table member:
 
65
    * mailing_list -> list_id
61
66
    """
62
67
 
63
68
    layer = ConfigLayer
83
88
        # Verify that the database has not yet been migrated.
84
89
        for missing in ('allow_list_posts',
85
90
                        'archive_policy',
 
91
                        'list_id',
86
92
                        'nntp_prefix_subject_too'):
87
93
            self.assertRaises(DatabaseError,
88
94
                              self._database.store.execute,
89
95
                              'select {0} from mailinglist;'.format(missing))
90
96
            self._database.store.rollback()
 
97
        self.assertRaises(DatabaseError,
 
98
                          self._database.store.execute,
 
99
                          'select list_id from member;')
91
100
        for present in ('archive',
92
101
                        'archive_private',
93
102
                        'archive_volume_frequency',
100
109
            # that we can perform?
101
110
            self._database.store.execute(
102
111
                'select {0} from mailinglist;'.format(present))
 
112
        # Again, this should not produce an exception.
 
113
        self._database.store.execute('select mailing_list from member;')
103
114
 
104
115
    def test_post_upgrade_columns_migration(self):
105
116
        # Test that after the migration, the old table columns are missing
111
122
        # Verify that the database has been migrated.
112
123
        for present in ('allow_list_posts',
113
124
                        'archive_policy',
 
125
                        'list_id',
114
126
                        'nntp_prefix_subject_too'):
115
127
            # This should not produce an exception.  Is there some better test
116
128
            # that we can perform?
117
129
            self._database.store.execute(
118
130
                'select {0} from mailinglist;'.format(present))
 
131
        self._database.store.execute('select list_id from member;')
119
132
        for missing in ('archive',
120
133
                        'archive_private',
121
134
                        'archive_volume_frequency',
128
141
                              self._database.store.execute,
129
142
                              'select {0} from mailinglist;'.format(missing))
130
143
            self._database.store.rollback()
 
144
        self.assertRaises(DatabaseError,
 
145
                          self._database.store.execute,
 
146
                          'select mailing_list from member;')
131
147
 
132
148
 
133
149
 
263
279
            mlist = getUtility(IListManager).get('test@example.com')
264
280
            self.assertEqual(mlist.archive_policy, ArchivePolicy.public)
265
281
 
 
282
    def test_list_id(self):
 
283
        # Test that the mailinglist table gets a list_id column.
 
284
        self._upgrade()
 
285
        with temporary_db(self._database):
 
286
            mlist = getUtility(IListManager).get('test@example.com')
 
287
            self.assertEqual(mlist.list_id, 'test.example.com')
 
288
 
 
289
    def test_list_id_member(self):
 
290
        # Test that the member table's mailing_list column becomes list_id.
 
291
        self._upgrade()
 
292
        with temporary_db(self._database):
 
293
            service = getUtility(ISubscriptionService)
 
294
            members = list(service.find_members(list_id='test.example.com'))
 
295
        self.assertEqual(len(members), 4)
 
296
 
266
297
    def test_news_moderation_none(self):
267
298
        # Test that news_moderation becomes newsgroup_moderation.
268
299
        self._database.store.execute(