Skip to content

Commit

Permalink
chore: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarreau committed Aug 6, 2024
1 parent 6b1498a commit a80f995
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/agent_toolkit/tests/resources/collections/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ def setUpClass(cls) -> None:
column_type=PrimitiveType.NUMBER,
is_primary_key=True,
type=FieldType.COLUMN,
filter_operators=set([Operator.IN, Operator.EQUAL]),
filter_operators=set([Operator.IN, Operator.EQUAL, Operator.NOT_IN]),
),
"title": Column(
column_type=PrimitiveType.STRING,
filter_operators=[Operator.IN, Operator.EQUAL],
filter_operators=[Operator.IN, Operator.EQUAL, Operator.NOT_IN],
type=FieldType.COLUMN,
),
"author": ManyToOne(
Expand Down Expand Up @@ -83,6 +83,21 @@ def test_parse_condition_tree_should_parse_array_when_IN_operator_str(self):
)
condition_tree = parse_condition_tree(request)
self.assertEqual(condition_tree.value, ["Foundation", "Harry Potter"])
self.assertEqual(condition_tree.operator, Operator.IN)

def test_parse_condition_tree_should_parse_array_when_NOT_IN_operator_str(self):
request = RequestCollection(
method=RequestMethod.GET,
body=None,
query={
"filters": '{"field":"title","operator":"not_in","value":"Foundation,Harry Potter"}',
"collection_name": "Book",
},
collection=self.collection_book,
)
condition_tree = parse_condition_tree(request)
self.assertEqual(condition_tree.value, ["Foundation", "Harry Potter"])
self.assertEqual(condition_tree.operator, Operator.NOT_IN)

def test_parse_condition_tree_should_parse_array_when_IN_operator_int(self):
request = RequestCollection(
Expand All @@ -96,6 +111,21 @@ def test_parse_condition_tree_should_parse_array_when_IN_operator_int(self):
)
condition_tree = parse_condition_tree(request)
self.assertEqual(condition_tree.value, [1, 2])
self.assertEqual(condition_tree.operator, Operator.IN)

def test_parse_condition_tree_should_parse_array_when_NOT_IN_operator_int(self):
request = RequestCollection(
method=RequestMethod.GET,
body=None,
query={
"filters": '{"field":"id","operator":"not_in","value": [1,2]}',
"collection_name": "Book",
},
collection=self.collection_book,
)
condition_tree = parse_condition_tree(request)
self.assertEqual(condition_tree.value, [1, 2])
self.assertEqual(condition_tree.operator, Operator.NOT_IN)

def test_parse_condition_tree_should_parse_complex_condition_tree(self):
request = RequestCollection(
Expand Down

0 comments on commit a80f995

Please sign in to comment.