diff test/test_postgresql.py @ 6599:39189dd94f2c

issue2551189 - increase size of words in full text index. Increased indexed word maxlength to 50 DB migration code is written and tests work. Restructured some tests to allow for code reuse. Docs. If this passes CI without errors 2551189 should be done. However, testing on my system generates errors. Encoding (indexer unicode russian unicode string invalid) and collation errors (utf8_bin not valid) when running under python2. No issues with python3 and I haven't changed code that should cause these since the last successful build in CI. So if this fails in CI we will have more checkins.
author John Rouillard <rouilj@ieee.org>
date Wed, 26 Jan 2022 15:04:09 -0500
parents 5cb6e6b594b0
children 0d99ae7c8de6
line wrap: on
line diff
--- a/test/test_postgresql.py	Wed Jan 26 08:58:46 2022 -0500
+++ b/test/test_postgresql.py	Wed Jan 26 15:04:09 2022 -0500
@@ -68,6 +68,49 @@
         DBTest.tearDown(self)
         postgresqlOpener.tearDown(self)
 
+    def testUpgrade_6_to_7(self):
+
+        # load the database
+        self.db.issue.create(title="flebble frooz")
+        self.db.commit()
+
+        if self.db.database_schema['version'] != 7:
+            self.skipTest("This test only runs for database version 7")
+
+        self.db.database_schema['version'] = 6
+
+        # test by shrinking _words and trying to insert a long value
+        #    it should fail.
+        # run post-init
+        #    same test should succeed.
+
+        self.db.sql("alter table __words ALTER column _word type varchar(10)")
+
+        long_string = "a" * (self.db.indexer.maxlength + 5)
+
+        with self.assertRaises(psycopg2.DataError) as ctx:
+            # DataError : value too long for type character varying(10)
+            self.db.sql("insert into __words VALUES('%s',1)" % long_string)
+
+        self.assertIn("varying(10)", ctx.exception.args[0])
+
+        # clear the cursor error so it can be used again
+        self.db.rollback()
+
+        # test upgrade altering row
+        self.db.post_init()
+
+        # This insert with text of expected column size should succeed
+        self.db.sql("insert into __words VALUES('%s',1)" % long_string)
+
+        # verify it fails at one more than the expected column size
+        too_long_string = "a" * (self.db.indexer.maxlength + 6)
+        with self.assertRaises(psycopg2.DataError) as ctx:
+            self.db.sql("insert into __words VALUES('%s',1)" % too_long_string)
+
+        # clean db handle
+        self.db.rollback()
+
 
 @skip_postgresql
 class postgresqlROTest(postgresqlOpener, ROTest, unittest.TestCase):

Roundup Issue Tracker: http://roundup-tracker.org/