This commit is contained in:
parent
f6e4bc03f8
commit
817875d6cb
|
@ -1185,6 +1185,51 @@ def test_sql_criteria_fts(pub):
|
|||
assert data_class.select([st.FtsMatch(formdata1.id_display)])[0].id_display == formdata1.id_display
|
||||
|
||||
|
||||
def test_search_tokens_purge(pub):
|
||||
_, cur = sql.get_connection_and_cursor()
|
||||
|
||||
def token_exists(token):
|
||||
cur.execute('SELECT count(*) FROM wcs_search_tokens WHERE token=%s;', (token,))
|
||||
return cur.fetchone()[0] == 1
|
||||
|
||||
# purge garbage from other tests
|
||||
FormDef.wipe()
|
||||
sql.purge_obsolete_search_tokens()
|
||||
|
||||
# make sure the existing situation is clean for the test
|
||||
assert not (token_exists('tableselectftstoken'))
|
||||
assert not (token_exists('foofortokensofcours'))
|
||||
assert not (token_exists('chaussettefortokensofcours'))
|
||||
|
||||
# define a new table
|
||||
test_formdef = FormDef()
|
||||
test_formdef.name = 'tableSelectFTStokens'
|
||||
test_formdef.fields = [fields.StringField(id='3', label='string')]
|
||||
test_formdef.store()
|
||||
data_class = test_formdef.data_class(mode='sql')
|
||||
|
||||
assert token_exists('tableselectftstoken')
|
||||
|
||||
t = data_class()
|
||||
t.data = {'3': 'foofortokensofcourse'}
|
||||
t.just_created()
|
||||
t.store()
|
||||
|
||||
assert token_exists('foofortokensofcours')
|
||||
|
||||
t.data = {'3': 'chaussettefortokensofcourse'}
|
||||
t.store()
|
||||
|
||||
# one additional element
|
||||
assert token_exists('foofortokensofcours')
|
||||
assert token_exists('chaussettefortokensofcours')
|
||||
|
||||
sql.purge_obsolete_search_tokens()
|
||||
|
||||
assert not (token_exists('foofortokensofcours'))
|
||||
assert token_exists('chaussettefortokensofcours')
|
||||
|
||||
|
||||
def table_exists(cur, table_name):
|
||||
cur.execute(
|
||||
'''SELECT COUNT(*) FROM information_schema.tables
|
||||
|
|
Loading…
Reference in New Issue