Mercurial > p > roundup > code
comparison test/test_postgresql.py @ 5118:57452bc6d989
issue2550853 - better error handling and cleanup on some postgres
tests by Stuart McGraw.
My postgres tests passed both before and after I applied his patch,
but the code change seems rational.
issue2086536 - back_postgresql: fixing pg_command and prefering
psycopg2. Patch done by Philipp Gortan (mephinet). His patch
also improves handling of retryable errors. Applied and
edited by John Rouillard. Edits included removing support for
psycopg1. See:
https://sourceforge.net/p/roundup/mailman/message/32855027/
for rational for dropping it
Again all 137 postgres tests pass.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sat, 02 Jul 2016 21:15:23 -0400 |
| parents | 43a1f7fe39f5 |
| children | 917e45d9ba08 |
comparison
equal
deleted
inserted
replaced
| 5117:14abd0a67207 | 5118:57452bc6d989 |
|---|---|
| 23 from db_test_base import DBTest, ROTest, config, SchemaTest, ClassicInitTest | 23 from db_test_base import DBTest, ROTest, config, SchemaTest, ClassicInitTest |
| 24 from db_test_base import ConcurrentDBTest, HTMLItemTest, FilterCacheTest | 24 from db_test_base import ConcurrentDBTest, HTMLItemTest, FilterCacheTest |
| 25 from db_test_base import ClassicInitBase, setupTracker | 25 from db_test_base import ClassicInitBase, setupTracker |
| 26 | 26 |
| 27 from roundup.backends import get_backend, have_backend | 27 from roundup.backends import get_backend, have_backend |
| 28 from roundup.backends.back_postgresql import psycopg | |
| 28 | 29 |
| 29 if not have_backend('postgresql'): | 30 if not have_backend('postgresql'): |
| 30 # FIX: workaround for a bug in pytest.mark.skip(): | 31 # FIX: workaround for a bug in pytest.mark.skip(): |
| 31 # https://github.com/pytest-dev/pytest/issues/568 | 32 # https://github.com/pytest-dev/pytest/issues/568 |
| 32 from .pytest_patcher import mark_class | 33 from .pytest_patcher import mark_class |
| 98 self.id = db.issue.create(title='initial value') | 99 self.id = db.issue.create(title='initial value') |
| 99 db.commit() | 100 db.commit() |
| 100 db.close() | 101 db.close() |
| 101 | 102 |
| 102 def tearDown(self): | 103 def tearDown(self): |
| 103 self.db1.close() | 104 try: |
| 104 self.db2.close() | 105 self.db1.close() |
| 106 self.db2.close() | |
| 107 except psycopg.InterfaceError, exc: | |
| 108 if 'connection already closed' in str(exc): pass | |
| 109 else: raise | |
| 105 ClassicInitBase.tearDown(self) | 110 ClassicInitBase.tearDown(self) |
| 106 postgresqlOpener.tearDown(self) | 111 postgresqlOpener.tearDown(self) |
| 107 | 112 |
| 108 def _test_journal(self, expected_journal): | 113 def _test_journal(self, expected_journal): |
| 109 id = self.id | 114 id = self.id |
| 115 | 120 |
| 116 db1.issue.set (id, title='t1') | 121 db1.issue.set (id, title='t1') |
| 117 db1.commit() | 122 db1.commit() |
| 118 db1.close() | 123 db1.close() |
| 119 | 124 |
| 120 db2.issue.set (id, title='t2') | 125 # Test testConcurrentRepeatableRead is expected to raise |
| 121 db2.commit() | 126 # an error when the db2.issue.set() call is executed. |
| 122 db2.close() | 127 try: |
| 128 db2.issue.set (id, title='t2') | |
| 129 db2.commit() | |
| 130 finally: | |
| 131 # Make sure that the db2 connection is closed, even when | |
| 132 # an error is raised. | |
| 133 db2.close() | |
| 123 self.db = self.tracker.open('admin') | 134 self.db = self.tracker.open('admin') |
| 124 journal = self.db.getjournal('issue', id) | 135 journal = self.db.getjournal('issue', id) |
| 125 for n, line in enumerate(journal): | 136 for n, line in enumerate(journal): |
| 126 self.assertEqual(line[4], expected_journal[n]) | 137 self.assertEqual(line[4], expected_journal[n]) |
| 127 | 138 |
