summaryrefslogtreecommitdiff
path: root/src/mailman/database/tests/test_migrations.py
diff options
context:
space:
mode:
authorAurélien Bompard2016-02-12 15:24:00 +0100
committerBarry Warsaw2016-02-29 21:52:13 -0500
commit1236a9cfc1546180a4717f0c8b9ba0d3c1f72e36 (patch)
tree5c05e5c62ac7c30e680696e7b04bf12358ca978e /src/mailman/database/tests/test_migrations.py
parent7604ceaae42beb8d001e0ec6850bcd65164d56d7 (diff)
downloadmailman-1236a9cfc1546180a4717f0c8b9ba0d3c1f72e36.tar.gz
mailman-1236a9cfc1546180a4717f0c8b9ba0d3c1f72e36.tar.zst
mailman-1236a9cfc1546180a4717f0c8b9ba0d3c1f72e36.zip
Diffstat (limited to 'src/mailman/database/tests/test_migrations.py')
-rw-r--r--src/mailman/database/tests/test_migrations.py50
1 files changed, 29 insertions, 21 deletions
diff --git a/src/mailman/database/tests/test_migrations.py b/src/mailman/database/tests/test_migrations.py
index 1791a2453..560c10648 100644
--- a/src/mailman/database/tests/test_migrations.py
+++ b/src/mailman/database/tests/test_migrations.py
@@ -228,41 +228,49 @@ class TestMigrations(unittest.TestCase):
self.assertTrue(os.path.exists(bee.data_path))
def test_cb7fc8476779_header_match_action(self):
+ data = {
+ 'header-1': Action.accept,
+ 'header-2': Action.hold,
+ 'header-3': Action.discard,
+ 'header-4': Action.reject,
+ }
# Create a mailing list through the standard API.
with transaction():
ant = create_list('ant@example.com')
# Create header matches
header_matches = IHeaderMatchList(ant)
- header_matches.append('header-1', 'pattern', Action.accept)
- header_matches.append('header-2', 'pattern', Action.hold)
- header_matches.append('header-3', 'pattern', Action.discard)
- header_matches.append('header-4', 'pattern', Action.reject)
+ for header, action in data.items():
+ header_matches.append(header, 'pattern', action)
hm_table = sa.sql.table(
'headermatch',
+ sa.sql.column('header', sa.Unicode),
sa.sql.column('action', Enum(Action)),
- sa.sql.column('chain', sa.Unicode)
+ sa.sql.column('chain', sa.Unicode),
)
# Downgrade and verify that the chain names are correct.
with transaction():
alembic.command.downgrade(alembic_cfg, 'd4fbb4fd34ca')
- results = config.db.store.execute(
- hm_table.select()).fetchall()
- self.assertEqual(len(results), 4)
- for action, chain in results:
- self.assertEqual(action.name, chain)
- # Clear the previous values for testing.
with transaction():
- config.db.store.execute(
- hm_table.update().values(action=None))
- for action, chain in config.db.store.execute(
- hm_table.select()).fetchall():
- self.assertEqual(action, None)
+ results = config.db.store.execute(
+ sa.select([hm_table.c.header, hm_table.c.chain])).fetchall()
+ self.assertEqual(len(results), 4)
+ for header, chain in results:
+ self.assertEqual(chain, data[header].name)
+ if config.db.store.bind.dialect.name == 'sqlite':
+ # Clear the previous values for testing, since SQLite did not
+ # remove the column.
+ with transaction():
+ config.db.store.execute(
+ hm_table.update().values(action=None))
+ for action in config.db.store.execute(
+ sa.select([hm_table.c.action])).fetchall():
+ self.assertEqual(action[0], None)
# Upgrade and verify that the actions are back to normal.
with transaction():
alembic.command.upgrade(alembic_cfg, 'cb7fc8476779')
- results = config.db.store.execute(
- hm_table.select()).fetchall()
+ with transaction():
+ results = config.db.store.execute(
+ sa.select([hm_table.c.header, hm_table.c.action])).fetchall()
self.assertEqual(len(results), 4)
- for action, chain in results:
- self.assertIsNotNone(action)
- self.assertEqual(action.name, chain)
+ for header, action in results:
+ self.assertEqual(action, data[header])