From 19e21e921904761ec9e959d774a69ac769952593 Mon Sep 17 00:00:00 2001 From: Karanbir Singh Date: Wed, 12 Oct 2022 18:11:25 -0700 Subject: [PATCH 1/2] Support for contains_in operator --- business_rules/operators.py | 4 ++++ tests/test_operators.py | 3 +++ 2 files changed, 7 insertions(+) diff --git a/business_rules/operators.py b/business_rules/operators.py index d43e5b1f..5f9540c3 100644 --- a/business_rules/operators.py +++ b/business_rules/operators.py @@ -95,6 +95,10 @@ def matches_regex(self, regex): def non_empty(self): return bool(self.value) + @type_operator(FIELD_TEXT) + def contains_in(self, other_string): + return self.value in other_string + @export_type class NumericType(BaseType): diff --git a/tests/test_operators.py b/tests/test_operators.py index 824d4a69..20e677c8 100644 --- a/tests/test_operators.py +++ b/tests/test_operators.py @@ -46,6 +46,9 @@ def test_non_empty(self): self.assertFalse(StringType("").non_empty()) self.assertFalse(StringType(None).non_empty()) + def test_string_contains_in(self): + self.assertTrue(StringType("hello").contains_in("hello world")) + self.assertFalse(StringType("word").contains_in("hello world")) class NumericOperatorTests(TestCase): From 21a420545861ae0c0597b3daf6b768c87ed89c7f Mon Sep 17 00:00:00 2001 From: Karanbir Singh Date: Thu, 13 Oct 2022 00:45:55 -0700 Subject: [PATCH 2/2] Changing name of the operator to is_in --- business_rules/operators.py | 2 +- tests/test_operators.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/business_rules/operators.py b/business_rules/operators.py index 5f9540c3..55d982a9 100644 --- a/business_rules/operators.py +++ b/business_rules/operators.py @@ -96,7 +96,7 @@ def non_empty(self): return bool(self.value) @type_operator(FIELD_TEXT) - def contains_in(self, other_string): + def is_in(self, other_string): return self.value in other_string diff --git a/tests/test_operators.py b/tests/test_operators.py index 20e677c8..0d51896c 100644 --- a/tests/test_operators.py +++ b/tests/test_operators.py @@ -46,9 +46,9 @@ def test_non_empty(self): self.assertFalse(StringType("").non_empty()) self.assertFalse(StringType(None).non_empty()) - def test_string_contains_in(self): - self.assertTrue(StringType("hello").contains_in("hello world")) - self.assertFalse(StringType("word").contains_in("hello world")) + def test_string_is_in(self): + self.assertTrue(StringType("hello").is_in("hello world")) + self.assertFalse(StringType("word").is_in("hello world")) class NumericOperatorTests(TestCase):