feat: implement like & not like in compare util

This commit is contained in:
Gursheen Anand 2023-08-11 15:34:07 +05:30
parent 518b31bde0
commit b019a1163c
2 changed files with 30 additions and 0 deletions

View file

@ -173,6 +173,34 @@ class TestFilters(FrappeTestCase):
)
)
def test_like_not_like(self):
doc = {"doctype": "User", "username": "test_abc"}
self.assertTrue(
evaluate_filters(
doc,
[["username", "like", "test"]],
)
)
self.assertFalse(
evaluate_filters(
doc,
[["username", "like", "user1"]],
)
)
self.assertFalse(
evaluate_filters(
doc,
[["username", "not like", "test"]],
)
)
self.assertTrue(
evaluate_filters(
doc,
[["username", "not like", "user1"]],
)
)
class TestMoney(FrappeTestCase):
def test_money_in_words(self):

View file

@ -1707,6 +1707,8 @@ operator_map = {
"<=": operator.le,
"not None": lambda a, b: a is not None,
"None": lambda a, b: a is None,
"like": lambda a, b: operator.contains(a.strip("%"), b.strip("%")),
"not like": lambda a, b: not operator.contains(a.strip("%"), b.strip("%")),
}