comparison test/test_liveserver.py @ 6915:9ff091537f43

postgresql native-fts; more indexer tests 1) Make postgresql native-fts actually work. 2) Add simple stopword filtering to sqlite native-fts indexer. 3) Add more tests for indexer_common get_indexer Details: 1) roundup/backends/indexer_postgresql_fts.py: ignore ValueError raised if we try to index a string with a null character in it. This could happen due to an incorrect text/ mime type on a file that has nulls in it. Replace ValueError raised by postgresql with customized IndexerQueryError if a search string has a null in it. roundup/backends/rdbms_common.py: Make postgresql native-fts work. When specified it was using using whatever was returned from get_indexer(). However loading the native-fts indexer backend failed because there was no connection to the postgresql database when this call was made. Simple solution, move the call after the open_connection call in Database::__init__(). However the open_connection call creates the schema for the database if it is not there. The schema builds tables for indexer=native type indexing. As part of the build it looks at the indexer to see the min/max size of the indexed tokens. No indexer define, we get a crash. So it's a a chicken/egg issue. I solved it by setting the indexer to the Indexer from indexer_common which has the min/max token size info. I also added a no-op save_indexer to this Indexer class. I claim save_indexer() isn't needed as a commit() on the db does all the saving required. Then after open_connection is called, I call get_indexer to retrieve the correct indexer and indexer_postgresql_fts woks since the conn connection property is defined. roundup/backends/indexer_common.py: add save_index() method for indexer. It does nothing but is needed in rdbms backends during schema initialization. 2) roundup/backends/indexer_sqlite_fts.py: when this indexer is used, the indexer test in DBTest on the word "the" fail. This is due to missing stopword filtering. Implement basic stopword filtering for bare stopwords (like 'the') to make the test pass. Note: this indexer is not currently automatically run by the CI suite, it was found during manual testing. However there is a FIXME to extract the indexer tests from DBTest and run it using this backend. roundup/configuration.py, roundup/doc/admin_guide.txt: update doc on stopword use for sqlite native-fts. test/db_test_base.py: DBTest::testStringBinary creates a file with nulls in it. It was breaking postgresql with native-fts indexer. Changed test to assign mime type application/octet-stream that prevents it from being processed by any text search indexer. add test to exclude indexer searching in specific props. This code path was untested before. test/test_indexer.py: add test to call find with no words. Untested code path. add test to index and find a string with a null \x00 byte. it was tested inadvertently by testStringBinary but this makes it explicit and moves it to indexer testing. (one version each for: generic, postgresql and mysql) Renamed Get_IndexerAutoSelectTest to Get_IndexerTest and renamed autoselect tests to include autoselect. Added tests for an invalid indexer and using native-fts with anydbm (unsupported combo) to make sure the code does something useful if the validation in configuration.py is broken. test/test_liveserver.py: add test to load an issue add test using text search (fts) to find the issue add tests to find issue using postgresql native-fts test/test_postgresql.py, test/test_sqlite.py: added explanation on how to setup integration test using native-fts. added code to clean up test environment if native-fts test is run.
author John Rouillard <rouilj@ieee.org>
date Mon, 05 Sep 2022 16:25:20 -0400
parents d9c9f5b81d4d
children cb2ed1e8c852
comparison
equal deleted inserted replaced
6914:6010c20dc104 6915:9ff091537f43
87 87
88 # enable static precompressed files 88 # enable static precompressed files
89 cls.db.config.WEB_USE_PRECOMPRESSED_FILES = 1 89 cls.db.config.WEB_USE_PRECOMPRESSED_FILES = 1
90 90
91 cls.db.config.save() 91 cls.db.config.save()
92
93 # add an issue to allow testing retrieval.
94 # also used for text searching.
95 result = cls.db.issue.create(title="foo bar RESULT")
92 96
93 cls.db.commit() 97 cls.db.commit()
94 cls.db.close() 98 cls.db.close()
95 99
96 # Force locale config to find locales in checkout not in 100 # Force locale config to find locales in checkout not in
555 # use dict comprehension to remove fields like date, etag 559 # use dict comprehension to remove fields like date, etag
556 # etc. from f.headers. 560 # etc. from f.headers.
557 self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected) 561 self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected)
558 562
559 563
564 def test_load_issue1(self):
565 f = requests.get(self.url_base() + '/issue1>',
566 headers = { 'Accept-Encoding': 'gzip',
567 'Accept': '*/*'})
568
569 self.assertIn(b'foo bar RESULT', f.content)
570 self.assertEqual(f.status_code, 200)
571
560 def test_bad_path(self): 572 def test_bad_path(self):
561 f = requests.get(self.url_base() + '/_bad>', 573 f = requests.get(self.url_base() + '/_bad>',
562 headers = { 'Accept-Encoding': 'gzip, foo', 574 headers = { 'Accept-Encoding': 'gzip, foo',
563 'Accept': '*/*'}) 575 'Accept': '*/*'})
564 576
1081 headers = {'x-requested-with': "rest", 1093 headers = {'x-requested-with': "rest",
1082 'Origin': "http://localhost:9001"} 1094 'Origin': "http://localhost:9001"}
1083 ) 1095 )
1084 self.assertEqual(r.status_code, 201) 1096 self.assertEqual(r.status_code, 201)
1085 print(r.status_code) 1097 print(r.status_code)
1098
1099 def test_fts(self):
1100 f = requests.get(self.url_base() + "?@search_text=RESULT")
1101 self.assertIn("foo bar", f.text)
1086 1102
1087 class TestFeatureFlagCacheTrackerOn(BaseTestCases, WsgiSetup): 1103 class TestFeatureFlagCacheTrackerOn(BaseTestCases, WsgiSetup):
1088 """Class to run all test in BaseTestCases with the cache_tracker 1104 """Class to run all test in BaseTestCases with the cache_tracker
1089 feature flag enabled when starting the wsgi server 1105 feature flag enabled when starting the wsgi server
1090 """ 1106 """
1095 return validator(RequestDispatcher(self.dirname, feature_flags=ff)) 1111 return validator(RequestDispatcher(self.dirname, feature_flags=ff))
1096 else: 1112 else:
1097 # wsgiref/validator.py InputWrapper::readline is broke and 1113 # wsgiref/validator.py InputWrapper::readline is broke and
1098 # doesn't support the max bytes to read argument. 1114 # doesn't support the max bytes to read argument.
1099 return RequestDispatcher(self.dirname, feature_flags=ff) 1115 return RequestDispatcher(self.dirname, feature_flags=ff)
1116
1117 class TestPostgresWsgiServer(BaseTestCases, WsgiSetup):
1118 """Class to run all test in BaseTestCases with the cache_tracker
1119 feature flag enabled when starting the wsgi server
1120 """
1121
1122 backend = 'postgresql'
1123
1124 @classmethod
1125 def setup_class(cls):
1126 '''All tests in this class use the same roundup instance.
1127 This instance persists across all tests.
1128 Create the tracker dir here so that it is ready for the
1129 create_app() method to be called.
1130
1131 cribbed from WsgiSetup::setup_class
1132 '''
1133
1134 # tests in this class.
1135 # set up and open a tracker
1136 cls.instance = db_test_base.setupTracker(cls.dirname, cls.backend)
1137
1138 # open the database
1139 cls.db = cls.instance.open('admin')
1140
1141 # add a user without edit access for status.
1142 cls.db.user.create(username="fred", roles='User',
1143 password=password.Password('sekrit'), address='fred@example.com')
1144
1145 # set the url the test instance will run at.
1146 cls.db.config['TRACKER_WEB'] = "http://localhost:9001/"
1147 # set up mailhost so errors get reported to debuging capture file
1148 cls.db.config.MAILHOST = "localhost"
1149 cls.db.config.MAIL_HOST = "localhost"
1150 cls.db.config.MAIL_DEBUG = "../_test_tracker_mail.log"
1151
1152 # added to enable csrf forgeries/CORS to be tested
1153 cls.db.config.WEB_CSRF_ENFORCE_HEADER_ORIGIN = "required"
1154 cls.db.config.WEB_ALLOWED_API_ORIGINS = "https://client.com"
1155 cls.db.config['WEB_CSRF_ENFORCE_HEADER_X-REQUESTED-WITH'] = "required"
1156
1157 cls.db.config.INDEXER = "native-fts"
1158
1159 # disable web login rate limiting. The fast rate of tests
1160 # causes them to trip the rate limit and fail.
1161 cls.db.config.WEB_LOGIN_ATTEMPTS_MIN = 0
1162
1163 # enable static precompressed files
1164 cls.db.config.WEB_USE_PRECOMPRESSED_FILES = 1
1165
1166 cls.db.config.save()
1167
1168 cls.db.commit()
1169 cls.db.close()
1170
1171 # re-open the database to get the updated INDEXER
1172 cls.db = cls.instance.open('admin')
1173
1174 result = cls.db.issue.create(title="foo bar RESULT")
1175
1176 cls.db.commit()
1177 cls.db.close()
1178
1179 # Force locale config to find locales in checkout not in
1180 # installed directories
1181 cls.backup_domain = i18n.DOMAIN
1182 cls.backup_locale_dirs = i18n.LOCALE_DIRS
1183 i18n.LOCALE_DIRS = ['locale']
1184 i18n.DOMAIN = ''
1185
1186 def test_native_fts(self):
1187 self.assertIn("postgresql_fts", str(self.db.indexer))
1188
1189 # use a ts: search as well so it only works on postgres_fts indexer
1190 f = requests.get(self.url_base() + "?@search_text=ts:RESULT")
1191 self.assertIn("foo bar RESULT", f.text)

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