def test_add_searchable_database(): db = SQLiteBackend("foo") ds = { ("foo", "bar"): { "database": "foo", "code": "bar", "name": "lollipop" } } db.write(ds) with Searcher(db.filename) as s: assert s.search("lollipop", proxy=False)
def test_copy_save_propogates_to_search_index(): db = SQLiteBackend("foo") ds = { ("foo", "bar"): { "database": "foo", "code": "bar", "name": "lollipop" } } db.write(ds) assert db.search("lollipop") cp = db.get("bar").copy(code="baz") cp["name"] = "candy" cp.save() assert db.search("candy")
def test_case_sensitivity_convert_lowercase(): db = SQLiteBackend("foo") ds = { ("foo", "bar"): { "database": "foo", "code": "bar", "name": "LOLLIpop" } } db.write(ds) assert db.search("LOLLIpop".lower()) assert db.search("lollipop") assert db.search("LOLLipop") assert db.search("LOLL*") assert db.search("Lollipop") assert not db.search("nope")
def test_case_sensitivity_mask(): db = SQLiteBackend("foo") ds = { ("foo", "bar"): { "database": "foo", "code": "bar", "name": "lollipop", "location": "CH", }, ("foo", "baz"): { "database": "foo", "code": "baz", "name": "ice lollipop", "location": "FR", "reference product": "ZEBRA", }, } db.write(ds) assert len(db.search("lollipop")) == 2 assert len(db.search("lollipop", mask={"product": "ZEbra"})) == 1
def test_case_sensitivity_filter(): db = SQLiteBackend("foo") ds = { ("foo", "bar"): { "database": "foo", "code": "bar", "name": "lollipop", "location": "CH", }, ("foo", "baz"): { "database": "foo", "code": "baz", "name": "ice lollipop", "location": "FR", }, } db.write(ds) assert len(db.search("lollipop")) == 2 assert len(db.search("lollipop", filter={"location": "fr"})) == 1 assert len(db.search("lollipop", filter={"location": "FR"})) == 1
def test_delete_database(): db = SQLiteBackend("foo") ds = { ("foo", "bar"): { "database": "foo", "code": "bar", "name": "lollipop" } } db.write(ds) with Searcher(db.filename) as s: assert s.search("lollipop", proxy=False) db.make_unsearchable() with Searcher(db.filename) as s: assert not s.search("lollipop", proxy=False) db.make_searchable() with Searcher(db.filename) as s: assert s.search("lollipop", proxy=False) del databases["foo"] with Searcher(db.filename) as s: assert not s.search("lollipop", proxy=False)
def test_modify_database(): db = SQLiteBackend("foo") ds = { ("foo", "bar"): { "database": "foo", "code": "bar", "name": "lollipop" } } db.write(ds) with Searcher(db.filename) as s: assert not s.search("cream", proxy=False) assert s.search("lollipop", proxy=False) ds2 = { ("foo", "bar"): { "database": "foo", "code": "bar", "name": "ice cream" } } db.write(ds2) with Searcher(db.filename) as s: assert s.search("cream", proxy=False)