Merge lp:~abompard/mailman/failing-test into lp:mailman

Proposed by Aurélien Bompard
Status: Merged
Approved by: Barry Warsaw
Approved revision: 7265
Merged at revision: 7265
Proposed branch: lp:~abompard/mailman/failing-test
Merge into: lp:mailman
Diff against target: 42 lines (+13/-8)
1 file modified
src/mailman/database/tests/test_factory.py (+13/-8)
To merge this branch: bzr merge lp:~abompard/mailman/failing-test
Reviewer Review Type Date Requested Status
Barry Warsaw Approve
Review via email: mp+243033@code.launchpad.net

Description of the change

Fix a failing schemamanager test

To post a comment you must log in.
Revision history for this message
Barry Warsaw (barry) wrote :

Thanks! I made a few small changes.

* in TestSchemaManager.setUp(), I used md.sorted_tables so I didn't have to call .values():

        for table in md.sorted_tables:
            table.drop(config.db.engine)

* In test_initial() I used assertIn() on md.tables (since if it's a mapping, `in` should automatically compare against .keys()):

        self.assertIn('alembic_version', md.tables)

I don't quite understand the code though, and I would like to add some comments to the test.

* After calling setup_database(), why would you expect that alembic.command.upgrade was not called?

* After calling setup_database(), would you expect alembic_version table to exist, or would it only exist after the md.reflect() call?

review: Approve
Revision history for this message
Aurélien Bompard (abompard) wrote :

> * After calling setup_database(), why would you expect that alembic.command.upgrade was not called?

Because when there is no existing database, I'm not using alembic.command.upgrade, I'm creating all tables in SQLAlchemy with Metadata.create_all and them I'm stamping the schema at Alembic's latest version with alembic.command.stamp. So I'm checking that I'm not going through a different code path.

> * After calling setup_database(), would you expect alembic_version table to exist, or would it only exist after the md.reflect() call?

The table is created by the Alembic stamp command, but it's not in Mailman's metadata (we have no model for it since we don't use it), so I have to detect its presence using md.reflect().

Does this answer your questions?

Revision history for this message
Barry Warsaw (barry) wrote :

On Nov 29, 2014, at 08:38 AM, Aurélien Bompard wrote:

>Does this answer your questions?

It does, thanks! I will update the comments.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/mailman/database/tests/test_factory.py'
--- src/mailman/database/tests/test_factory.py 2014-10-13 19:24:24 +0000
+++ src/mailman/database/tests/test_factory.py 2014-11-27 13:31:21 +0000
@@ -51,9 +51,9 @@
51 Model.metadata.drop_all(config.db.engine)51 Model.metadata.drop_all(config.db.engine)
52 md = MetaData()52 md = MetaData()
53 md.reflect(bind=config.db.engine)53 md.reflect(bind=config.db.engine)
54 for tablename in ('alembic_version', 'version'):54 # Drop leftover tables (alembic & storm schema versions)
55 if tablename in md.tables:55 for table in md.tables.values():
56 md.tables[tablename].drop(config.db.engine)56 table.drop(config.db.engine)
57 self.schema_mgr = SchemaManager(config.db)57 self.schema_mgr = SchemaManager(config.db)
5858
59 def tearDown(self):59 def tearDown(self):
@@ -114,15 +114,20 @@
114 self.assertFalse(alembic_command.stamp.called)114 self.assertFalse(alembic_command.stamp.called)
115 self.assertFalse(alembic_command.upgrade.called)115 self.assertFalse(alembic_command.upgrade.called)
116116
117 @patch('alembic.command')117 @patch('alembic.command.upgrade')
118 def test_initial(self, alembic_command):118 def test_initial(self, alembic_command_upgrade):
119 # No existing database.119 # No existing database.
120 self.assertFalse(self._table_exists('mailinglist'))120 self.assertFalse(self._table_exists('mailinglist'))
121 self.assertFalse(self._table_exists('alembic_version'))121 self.assertFalse(self._table_exists('alembic_version'))
122 self.schema_mgr.setup_database()122 head_rev = self.schema_mgr.setup_database()
123 self.assertFalse(alembic_command.upgrade.called)123 self.assertFalse(alembic_command_upgrade.called)
124 self.assertTrue(self._table_exists('mailinglist'))124 self.assertTrue(self._table_exists('mailinglist'))
125 self.assertTrue(self._table_exists('alembic_version'))125 md = MetaData()
126 md.reflect(bind=config.db.engine)
127 self.assertTrue('alembic_version' in md.tables.keys())
128 current_rev = config.db.engine.execute(
129 md.tables["alembic_version"].select()).scalar()
130 self.assertEqual(current_rev, head_rev)
126131
127 @patch('alembic.command.stamp')132 @patch('alembic.command.stamp')
128 def test_storm(self, alembic_command_stamp):133 def test_storm(self, alembic_command_stamp):