Mercurial > p > roundup > code
comparison test/test_postgresql.py @ 6638:e1588ae185dc issue2550923_computed_property
merge from default branch. Fix travis.ci so CI builds don't error out
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Thu, 21 Apr 2022 16:54:17 -0400 |
| parents | 2a3bd715bbeb |
| children | 09d9c646ca89 |
comparison
equal
deleted
inserted
replaced
| 6508:85db90cc1705 | 6638:e1588ae185dc |
|---|---|
| 45 @skip_postgresql | 45 @skip_postgresql |
| 46 class postgresqlOpener: | 46 class postgresqlOpener: |
| 47 if have_backend('postgresql'): | 47 if have_backend('postgresql'): |
| 48 module = get_backend('postgresql') | 48 module = get_backend('postgresql') |
| 49 | 49 |
| 50 def setup_class(cls): | |
| 51 # nuke the db once for the class. Handles the case | |
| 52 # where an aborted test run (^C during setUp for example) | |
| 53 # leaves the database in an unusable, partly configured state. | |
| 54 try: | |
| 55 cls.nuke_database(cls) | |
| 56 except: | |
| 57 # ignore failure to nuke the database. | |
| 58 pass | |
| 59 | |
| 50 def setUp(self): | 60 def setUp(self): |
| 51 pass | 61 pass |
| 52 | 62 |
| 53 def tearDown(self): | 63 def tearDown(self): |
| 54 self.nuke_database() | 64 self.nuke_database() |
| 66 | 76 |
| 67 def tearDown(self): | 77 def tearDown(self): |
| 68 DBTest.tearDown(self) | 78 DBTest.tearDown(self) |
| 69 postgresqlOpener.tearDown(self) | 79 postgresqlOpener.tearDown(self) |
| 70 | 80 |
| 81 def testUpgrade_6_to_7(self): | |
| 82 | |
| 83 # load the database | |
| 84 self.db.issue.create(title="flebble frooz") | |
| 85 self.db.commit() | |
| 86 | |
| 87 if self.db.database_schema['version'] != 7: | |
| 88 # consider calling next testUpgrade script to roll back | |
| 89 # schema to version 7. | |
| 90 self.skipTest("This test only runs for database version 7") | |
| 91 | |
| 92 # remove __fts table/index; shrink length of __words._words | |
| 93 # trying to insert a long word in __words._words should fail. | |
| 94 # trying to select from __fts should fail | |
| 95 # looking for the index should fail | |
| 96 # run post-init | |
| 97 # tests should succeed. | |
| 98 | |
| 99 self.db.sql("drop table __fts") # also drops __fts_idx | |
| 100 self.db.sql("alter table __words ALTER column _word type varchar(10)") | |
| 101 self.db.commit() | |
| 102 | |
| 103 self.db.database_schema['version'] = 6 | |
| 104 | |
| 105 long_string = "a" * (self.db.indexer.maxlength + 5) | |
| 106 with self.assertRaises(psycopg2.DataError) as ctx: | |
| 107 # DataError : value too long for type character varying(10) | |
| 108 self.db.sql("insert into __words VALUES('%s',1)" % long_string) | |
| 109 | |
| 110 self.assertIn("varying(10)", ctx.exception.args[0]) | |
| 111 self.db.rollback() # clear cursor error so db.sql can be used again | |
| 112 | |
| 113 with self.assertRaises(psycopg2.errors.UndefinedTable) as ctx: | |
| 114 self.db.sql("select * from _fts") | |
| 115 self.db.rollback() | |
| 116 | |
| 117 self.assertFalse(self.db.sql_index_exists('__fts', '__fts_idx')) | |
| 118 | |
| 119 if hasattr(self, "downgrade_only"): | |
| 120 return | |
| 121 | |
| 122 # test upgrade path | |
| 123 self.db.post_init() | |
| 124 | |
| 125 # This insert with text of expected column size should succeed | |
| 126 self.db.sql("insert into __words VALUES('%s',1)" % long_string) | |
| 127 | |
| 128 # verify it fails at one more than the expected column size | |
| 129 too_long_string = "a" * (self.db.indexer.maxlength + 6) | |
| 130 with self.assertRaises(psycopg2.DataError) as ctx: | |
| 131 self.db.sql("insert into __words VALUES('%s',1)" % too_long_string) | |
| 132 | |
| 133 # clean db handle | |
| 134 self.db.rollback() | |
| 135 | |
| 136 self.assertTrue(self.db.sql_index_exists('__fts', '__fts_idx')) | |
| 137 | |
| 138 self.db.sql("select * from __fts") | |
| 139 | |
| 140 self.assertEqual(self.db.database_schema['version'], | |
| 141 self.db.current_db_version) | |
| 71 | 142 |
| 72 @skip_postgresql | 143 @skip_postgresql |
| 73 class postgresqlROTest(postgresqlOpener, ROTest, unittest.TestCase): | 144 class postgresqlROTest(postgresqlOpener, ROTest, unittest.TestCase): |
| 74 def setUp(self): | 145 def setUp(self): |
| 75 postgresqlOpener.setUp(self) | 146 postgresqlOpener.setUp(self) |
