rework the test for better behaviour along other tests
gitea/wcs/pipeline/head There was a failure building this commit
Details
gitea/wcs/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
180f07752e
commit
5d8ceee958
|
@ -1188,15 +1188,19 @@ def test_sql_criteria_fts(pub):
|
|||
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()
|
||||
|
||||
cur.execute('SELECT count(*) FROM wcs_search_tokens;')
|
||||
start = cur.fetchone()[0]
|
||||
# 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'))
|
||||
|
||||
cur.execute("SELECT * FROM wcs_search_tokens;")
|
||||
print(cur.fetchall())
|
||||
# define a new table
|
||||
test_formdef = FormDef()
|
||||
test_formdef.name = 'tableSelectFTStokens'
|
||||
|
@ -1204,42 +1208,26 @@ def test_search_tokens_purge(pub):
|
|||
test_formdef.store()
|
||||
data_class = test_formdef.data_class(mode='sql')
|
||||
|
||||
cur.execute('SELECT count(*) FROM wcs_search_tokens;')
|
||||
assert cur.fetchone()[0] == start + 1
|
||||
|
||||
cur.execute("SELECT * FROM wcs_search_tokens;")
|
||||
print(cur.fetchall())
|
||||
assert token_exists('tableselectftstoken')
|
||||
|
||||
t = data_class()
|
||||
t.data = {'3': 'foofortokensofcourse'}
|
||||
t.just_created()
|
||||
t.store()
|
||||
|
||||
cur.execute("SELECT * FROM wcs_search_tokens;")
|
||||
print(cur.fetchall())
|
||||
|
||||
# 3 elements are indexed here, ids and field
|
||||
cur.execute('SELECT count(*) FROM wcs_search_tokens;')
|
||||
assert cur.fetchone()[0] == start + 4
|
||||
assert token_exists('foofortokensofcours')
|
||||
|
||||
t.data = {'3': 'chaussettefortokensofcourse'}
|
||||
t.store()
|
||||
|
||||
# one additional element
|
||||
cur.execute("SELECT * FROM wcs_search_tokens;")
|
||||
print(cur.fetchall())
|
||||
|
||||
cur.execute('SELECT count(*) FROM wcs_search_tokens;')
|
||||
assert cur.fetchone()[0] == start + 5
|
||||
assert token_exists('foofortokensofcours')
|
||||
assert token_exists('chaussettefortokensofcours')
|
||||
|
||||
sql.purge_obsolete_search_tokens()
|
||||
|
||||
cur.execute("SELECT * FROM wcs_search_tokens;")
|
||||
print(cur.fetchall())
|
||||
|
||||
# should be back to the previous step
|
||||
cur.execute('SELECT count(*) FROM wcs_search_tokens;')
|
||||
assert cur.fetchone()[0] == start + 4
|
||||
assert not(token_exists('foofortokensofcours'))
|
||||
assert token_exists('chaussettefortokensofcours')
|
||||
|
||||
|
||||
def table_exists(cur, table_name):
|
||||
|
|
Loading…
Reference in New Issue