annotate test/test_misc.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 5986ddd0d2e7
children 3129d73e8535
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5155
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
1 # misc tests
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
2
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
3 import unittest
5481
9a09719b0d8e helper to allow comparing dicts and None values in Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5155
diff changeset
4 import roundup.anypy.cmp_
6654
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
5 import sys
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
6 from roundup.anypy.strings import StringIO # define StringIO
5155
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
7 from roundup.cgi.accept_language import parse
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
8
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
9 class AcceptLanguageTest(unittest.TestCase):
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
10 def testParse(self):
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
11 self.assertEqual(parse("da, en-gb;q=0.8, en;q=0.7"),
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
12 ['da', 'en_gb', 'en'])
6347
3b945aee0919 accept_language parse; fix priority order; preserve insertion order
John Rouillard <rouilj@ieee.org>
parents: 5481
diff changeset
13 self.assertEqual(parse("da, en-gb;q=0.7, en;q=0.8"),
3b945aee0919 accept_language parse; fix priority order; preserve insertion order
John Rouillard <rouilj@ieee.org>
parents: 5481
diff changeset
14 ['da', 'en', 'en_gb'])
5155
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
15 self.assertEqual(parse("en;q=0.2, fr;q=1"), ['fr', 'en'])
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
16 self.assertEqual(parse("zn; q = 0.2 ,pt-br;q =1"), ['pt_br', 'zn'])
6347
3b945aee0919 accept_language parse; fix priority order; preserve insertion order
John Rouillard <rouilj@ieee.org>
parents: 5481
diff changeset
17 self.assertEqual(parse("pt-br;q =1, zn; q = 0.2"), ['pt_br', 'zn'])
3b945aee0919 accept_language parse; fix priority order; preserve insertion order
John Rouillard <rouilj@ieee.org>
parents: 5481
diff changeset
18 self.assertEqual(parse("pt-br,zn;q= 0.1, en-US;q=0.5"),
3b945aee0919 accept_language parse; fix priority order; preserve insertion order
John Rouillard <rouilj@ieee.org>
parents: 5481
diff changeset
19 ['pt_br', 'en_US', 'zn'])
3b945aee0919 accept_language parse; fix priority order; preserve insertion order
John Rouillard <rouilj@ieee.org>
parents: 5481
diff changeset
20 # verify that items with q=1.0 are in same output order as input
3b945aee0919 accept_language parse; fix priority order; preserve insertion order
John Rouillard <rouilj@ieee.org>
parents: 5481
diff changeset
21 self.assertEqual(parse("pt-br,en-US; q=0.5, zn;q= 1.0" ),
3b945aee0919 accept_language parse; fix priority order; preserve insertion order
John Rouillard <rouilj@ieee.org>
parents: 5481
diff changeset
22 ['pt_br', 'zn', 'en_US'])
3b945aee0919 accept_language parse; fix priority order; preserve insertion order
John Rouillard <rouilj@ieee.org>
parents: 5481
diff changeset
23 self.assertEqual(parse("zn;q=1.0;q= 1.0,pt-br,en-US; q=0.5" ),
3b945aee0919 accept_language parse; fix priority order; preserve insertion order
John Rouillard <rouilj@ieee.org>
parents: 5481
diff changeset
24 ['zn', 'pt_br', 'en_US'])
5155
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
25 self.assertEqual(parse("es-AR"), ['es_AR'])
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
26 self.assertEqual(parse("es-es-cat"), ['es_es_cat'])
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
27 self.assertEqual(parse(""), [])
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
28 self.assertEqual(parse(None),[])
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
29 self.assertEqual(parse(" "), [])
e1e3531b4d9b add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
30 self.assertEqual(parse("en,"), ['en'])
5481
9a09719b0d8e helper to allow comparing dicts and None values in Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5155
diff changeset
31
9a09719b0d8e helper to allow comparing dicts and None values in Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5155
diff changeset
32 class CmpTest(unittest.TestCase):
9a09719b0d8e helper to allow comparing dicts and None values in Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5155
diff changeset
33 def testCmp(self):
9a09719b0d8e helper to allow comparing dicts and None values in Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents: 5155
diff changeset
34 roundup.anypy.cmp_._test()
6654
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
35
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
36 class VersionCheck(unittest.TestCase):
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
37 def test_Version_Check(self):
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
38
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
39 # test for valid versions
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
40 from roundup.version_check import VERSION_NEEDED
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
41 self.assertEqual((2, 7), VERSION_NEEDED)
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
42 del(sys.modules['roundup.version_check'])
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
43
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
44
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
45 # fake an invalid version
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
46 real_ver = sys.version_info
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
47 sys.version_info = (2, 1)
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
48
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
49 # exit is called on failure, but that breaks testing so
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
50 # just return and discard the exit code.
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
51 real_exit = sys.exit
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
52 sys.exit = lambda code: code
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
53
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
54 # error case uses print(), capture and check
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
55 capturedOutput = StringIO()
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
56 sys.stdout = capturedOutput
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
57 from roundup.version_check import VERSION_NEEDED
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
58 sys.stdout = sys.__stdout__
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
59 self.assertIn("Roundup requires Python 2.7", capturedOutput.getvalue())
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
60
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
61 # reset to valid values for future tests
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
62 sys.exit = real_exit
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
63 sys.version_info = real_ver
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
64
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
65

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