From 3816556782a9f3352cfe07a0f709cca201860904 Mon Sep 17 00:00:00 2001 From: Amjith Ramanujam Date: Sun, 1 Sep 2019 21:18:47 -0700 Subject: [PATCH] Add tests for the create-update-trigger option. --- tests/test_cli.py | 24 ++++++++++++++++++++++++ tests/test_enable_fts.py | 13 +++++++++++++ 2 files changed, 37 insertions(+) diff --git a/tests/test_cli.py b/tests/test_cli.py index ddb936b..62e129b 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -329,6 +329,30 @@ def test_enable_fts(db_path): assert "Gosh_fts" == Database(db_path)["Gosh"].detect_fts() +def test_enable_fts_with_triggers(db_path): + Database(db_path)["Gosh"].insert_all([{"c1": "baz"}]) + exit_code = ( + CliRunner() + .invoke( + cli.cli, + ["enable-fts", db_path, "Gosh", "c1", "--fts4", "--create-update-triggers"], + ) + .exit_code + ) + assert 0 == exit_code + + def search(q): + return ( + Database(db_path) + .conn.execute("select c1 from Gosh_fts where c1 match ?", [q]) + .fetchall() + ) + + assert [("baz",)] == search("baz") + Database(db_path)["Gosh"].insert_all([{"c1": "martha"}]) + assert [("martha",)] == search("martha") + + def test_populate_fts(db_path): Database(db_path)["Gosh"].insert_all([{"c1": "baz"}]) exit_code = ( diff --git a/tests/test_enable_fts.py b/tests/test_enable_fts.py index 6cefe54..cb1ff7f 100644 --- a/tests/test_enable_fts.py +++ b/tests/test_enable_fts.py @@ -48,3 +48,16 @@ def test_optimize_fts(fresh_db): "searchable_5_fts", ): fresh_db[table_name].optimize() + + +def test_enable_fts_w_triggers(fresh_db): + table = fresh_db["searchable"] + table.insert(search_records[0]) + table.enable_fts( + ["text", "country"], fts_version="FTS4", create_update_triggers=True + ) + assert [("tanuki are tricksters", "Japan", "foo")] == table.search("tanuki") + table.insert(search_records[1]) + # Triggers will auto-populate FTS virtual table, not need to call populate_fts() + assert [("racoons are trash pandas", "USA", "bar")] == table.search("usa") + assert [] == table.search("bar")