diff test/test_mysql.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 778a9f455067
children 0d99ae7c8de6
line wrap: on
line diff
--- a/test/test_mysql.py	Wed Jan 26 08:58:46 2022 -0500
+++ b/test/test_mysql.py	Wed Jan 26 15:04:09 2022 -0500
@@ -65,6 +65,44 @@
         mysqlOpener.setUp(self)
         DBTest.setUp(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 change column "
+                    "_word _word varchar(10)")
+
+        long_string = "a" * (self.db.indexer.maxlength + 5)
+
+        with self.assertRaises(MySQLdb.DataError) as ctx:
+            # DataError : Data too long for column '_word' at row 1
+            self.db.sql("insert into __words VALUES('%s',1)" % long_string)
+
+        self.assertIn("Data too long for column '_word'",
+                      ctx.exception.args[1])
+ 
+        # 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(MySQLdb.DataError) as ctx:
+            self.db.sql("insert into __words VALUES('%s',1)" % too_long_string)
 
 @skip_mysql
 class mysqlROTest(mysqlOpener, ROTest, unittest.TestCase):

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