annotate test/test_memorydb.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 2ce855803633
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4349
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1 import unittest, os, shutil, time
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
3 from roundup import hyperdb
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
4
5388
d26921b851c3 Python 3 preparation: make relative imports explicit.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5319
diff changeset
5 from .db_test_base import DBTest, ROTest, SchemaTest, config, setupSchema
6360
a77a7d04ed23 Move memorydb from test to roundup/test
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5388
diff changeset
6 from roundup.test import memorydb
4349
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
7
6802
044dcf3608a2 update session db tests
John Rouillard <rouilj@ieee.org>
parents: 6365
diff changeset
8 from roundup.anypy import strings
044dcf3608a2 update session db tests
John Rouillard <rouilj@ieee.org>
parents: 6365
diff changeset
9
4349
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
10 class memorydbOpener:
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
11 module = memorydb
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
12
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
13 def nuke_database(self):
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
14 # really kill it
6365
7f00fc5958ca Make memorydb persistent across re-open
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6360
diff changeset
15 memorydb.db_nuke('')
4349
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
16 self.db = None
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
17
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
18 db = None
6365
7f00fc5958ca Make memorydb persistent across re-open
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6360
diff changeset
19 def open_database(self, user='admin'):
7f00fc5958ca Make memorydb persistent across re-open
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6360
diff changeset
20 if self.db:
7f00fc5958ca Make memorydb persistent across re-open
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6360
diff changeset
21 self.db.close()
7f00fc5958ca Make memorydb persistent across re-open
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6360
diff changeset
22 self.db = self.module.Database(config, user)
4349
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
23 return self.db
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
24
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
25 def setUp(self):
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
26 self.open_database()
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
27 setupSchema(self.db, 1, self.module)
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
28
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
29 def tearDown(self):
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
30 if self.db is not None:
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
31 self.db.close()
6365
7f00fc5958ca Make memorydb persistent across re-open
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6360
diff changeset
32 self.db = None
7f00fc5958ca Make memorydb persistent across re-open
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6360
diff changeset
33 self.nuke_database()
4349
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
34
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
35 # nuke and re-create db for restore
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
36 def nukeAndCreate(self):
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
37 self.db.close()
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
38 self.nuke_database()
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
39 self.db = self.module.Database(config, 'admin')
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
40 setupSchema(self.db, 0, self.module)
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
41
5033
63c79c0992ae Update tests to work with py.test
John Kristensen <john@jerrykan.com>
parents: 4570
diff changeset
42
63c79c0992ae Update tests to work with py.test
John Kristensen <john@jerrykan.com>
parents: 4570
diff changeset
43 class memorydbDBTest(memorydbOpener, DBTest, unittest.TestCase):
4349
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
44 pass
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
45
5033
63c79c0992ae Update tests to work with py.test
John Kristensen <john@jerrykan.com>
parents: 4570
diff changeset
46
63c79c0992ae Update tests to work with py.test
John Kristensen <john@jerrykan.com>
parents: 4570
diff changeset
47 class memorydbROTest(memorydbOpener, ROTest, unittest.TestCase):
4349
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
48 def setUp(self):
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
49 self.db = self.module.Database(config)
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
50 setupSchema(self.db, 0, self.module)
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
51
5033
63c79c0992ae Update tests to work with py.test
John Kristensen <john@jerrykan.com>
parents: 4570
diff changeset
52
63c79c0992ae Update tests to work with py.test
John Kristensen <john@jerrykan.com>
parents: 4570
diff changeset
53 class memorydbSchemaTest(memorydbOpener, SchemaTest, unittest.TestCase):
4349
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
54 pass
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
55
5033
63c79c0992ae Update tests to work with py.test
John Kristensen <john@jerrykan.com>
parents: 4570
diff changeset
56
5388
d26921b851c3 Python 3 preparation: make relative imports explicit.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5319
diff changeset
57 from .session_common import SessionTest
5319
62de601bdf6f Fix commits although a Reject exception is raised
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5037
diff changeset
58 class memorydbSessionTest(memorydbOpener, SessionTest, unittest.TestCase):
6802
044dcf3608a2 update session db tests
John Rouillard <rouilj@ieee.org>
parents: 6365
diff changeset
59 s2b = lambda x,y: strings.s2b(y)
044dcf3608a2 update session db tests
John Rouillard <rouilj@ieee.org>
parents: 6365
diff changeset
60
4349
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
61 def setUp(self):
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
62 self.db = self.module.Database(config, 'admin')
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
63 setupSchema(self.db, 1, self.module)
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
64 self.sessions = self.db.sessions
6828
2ce855803633 Implement UpdateTimestamp for memorydb and test.
John Rouillard <rouilj@ieee.org>
parents: 6827
diff changeset
65 self.db.Session = self.sessions
6822
5053ee6c846b memorydb fixes for otks tests.
John Rouillard <rouilj@ieee.org>
parents: 6810
diff changeset
66 self.otks = self.db.otks
6828
2ce855803633 Implement UpdateTimestamp for memorydb and test.
John Rouillard <rouilj@ieee.org>
parents: 6827
diff changeset
67 self.db.Otk = self.otks
4349
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
68
6828
2ce855803633 Implement UpdateTimestamp for memorydb and test.
John Rouillard <rouilj@ieee.org>
parents: 6827
diff changeset
69 def get_ts(self):
2ce855803633 Implement UpdateTimestamp for memorydb and test.
John Rouillard <rouilj@ieee.org>
parents: 6827
diff changeset
70 return (self.sessions.get('random_session', '__timestamp'),)
2ce855803633 Implement UpdateTimestamp for memorydb and test.
John Rouillard <rouilj@ieee.org>
parents: 6827
diff changeset
71
2ce855803633 Implement UpdateTimestamp for memorydb and test.
John Rouillard <rouilj@ieee.org>
parents: 6827
diff changeset
72 def testDbType(self):
2ce855803633 Implement UpdateTimestamp for memorydb and test.
John Rouillard <rouilj@ieee.org>
parents: 6827
diff changeset
73 self.assertIn("memorydb", repr(self.db))
2ce855803633 Implement UpdateTimestamp for memorydb and test.
John Rouillard <rouilj@ieee.org>
parents: 6827
diff changeset
74 self.assertIn("{}", repr(self.db.Session))
6806
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
75
4349
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
76 # vim: set filetype=python ts=4 sw=4 et si
f0faef4dd023 Make memorydb pass all tests;
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
77

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