Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for is_in operator #86

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions business_rules/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ def matches_regex(self, regex):
def non_empty(self):
return bool(self.value)

@type_operator(FIELD_TEXT)
def is_in(self, other_string):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You really need a substring option? Or are you intending this to be about membership in a list of things?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

substring option

return self.value in other_string


@export_type
class NumericType(BaseType):
Expand Down
3 changes: 3 additions & 0 deletions tests/test_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def test_non_empty(self):
self.assertFalse(StringType("").non_empty())
self.assertFalse(StringType(None).non_empty())

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):

Expand Down