Skip to content
Merged
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
6 changes: 5 additions & 1 deletion src/agent_toolkit/tests/resources/actions/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,11 @@ def test_dispatch_should_return_error_if_no_action_name_specified(self):
self.assertEqual(response.status, 500)
self.assertEqual(
content["errors"][0],
{"name": "RequestActionException", "detail": "🌳🌳🌳'action_name' is missing in the request", "status": 500},
{
"name": "RequestActionException",
"detail": "🌳🌳🌳'action_name' is missing in the request",
"status": 500,
},
)

def test_should_return_the_return_value_of_hook_when_method_name_is_hook(self):
Expand Down
18 changes: 15 additions & 3 deletions src/agent_toolkit/tests/resources/collections/test_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,11 @@ def test_edit_errors(
self.permission_service.can.reset_mock()
assert response.status == 500
response_content = json.loads(response.body)
assert response_content["errors"][0] == {"detail": "🌳🌳🌳", "name": "CollectionResourceException", "status": 500}
assert response_content["errors"][0] == {
"detail": "🌳🌳🌳",
"name": "CollectionResourceException",
"status": 500,
}

# JsonApiException
mocked_json_serializer_get.return_value.load = Mock(side_effect=JsonApiException)
Expand Down Expand Up @@ -964,7 +968,11 @@ def test_delete_error(self):

assert response.status == 500
response_content = json.loads(response.body)
assert response_content["errors"][0] == {"detail": "🌳🌳🌳", "name": "CollectionResourceException", "status": 500}
assert response_content["errors"][0] == {
"detail": "🌳🌳🌳",
"name": "CollectionResourceException",
"status": 500,
}

@patch(
"forestadmin.agent_toolkit.resources.collections.crud.ConditionTreeFactory.match_ids",
Expand Down Expand Up @@ -1095,7 +1103,11 @@ def test_csv_errors(self):

assert response.status == 500
response_content = json.loads(response.body)
assert response_content["errors"][0] == {"detail": "🌳🌳🌳cannot make csv", "name": "CsvException", "status": 500}
assert response_content["errors"][0] == {
"detail": "🌳🌳🌳cannot make csv",
"name": "CsvException",
"status": 500,
}

def test_csv_should_not_apply_pagination(self):
mock_orders = [{"id": 10, "cost": 200}, {"id": 11, "cost": 201}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,8 @@ def test_call_to_retrieve_should_raise_if_forest_backend_not_available(self):
side_effect=Exception("backend not available"),
):
self.assertRaisesRegex(
ForestException, r"🌳🌳🌳backend not available", self.loop.run_until_complete, self.ip_whitelist.retrieve()
ForestException,
r"🌳🌳🌳backend not available",
self.loop.run_until_complete,
self.ip_whitelist.retrieve(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,11 @@
GeneratedField = None


def serialize_enum_value(value):
try:
json.dumps(value)
except TypeError:
value = str(value)
return value


class FieldFactory:
@staticmethod
def _build_enum_values(field: Field) -> Optional[List[str]]:
if field.choices:
return [serialize_enum_value(c[0]) for c in field.choices] # type: ignore
return [str(c[0]) for c in field.choices] # type: ignore
return None

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_build_should_handle_enums(self):
field = models.IntegerField(choices=choices)
field_schema = FieldFactory.build(field)

self.assertEqual(field_schema["enum_values"], [1, 2, 3])
self.assertEqual(field_schema["enum_values"], ["1", "2", "3"])
self.assertEqual(field_schema["column_type"], PrimitiveType.ENUM)

def test_build_should_use_str_on_enum_values_when_value_is_not_json_serializable(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ def test_field_factory_should_raise_if_unknown_type(self):
value="1",
default_value="10",
)
self.assertRaisesRegex(FieldFactoryException, r"🌳🌳🌳Unknown field type: 'bla'", FieldFactory.build, plain_field)
self.assertRaisesRegex(
FieldFactoryException,
r"🌳🌳🌳Unknown field type: 'bla'",
FieldFactory.build,
plain_field,
)

def test_field_factory_should_raise_if_bad_param(self):
plain_field = PlainStringDynamicField(
Expand Down