diff --git a/tests/functional/event_handler/test_api_gateway.py b/tests/functional/event_handler/test_api_gateway.py index 5d44f68f2af..1272125da8b 100644 --- a/tests/functional/event_handler/test_api_gateway.py +++ b/tests/functional/event_handler/test_api_gateway.py @@ -733,10 +733,7 @@ def get_account(account_id: str): def test_custom_serializer(): - class Color(Enum): - RED = 1 - BLUE = 2 - + # GIVEN a custom serializer to handle enums and sets class CustomEncoder(JSONEncoder): def default(self, data): if isinstance(data, Enum): @@ -746,7 +743,7 @@ def default(self, data): except TypeError: pass else: - return list(iterable) + return sorted(iterable) return JSONEncoder.default(self, data) def custom_serializer(data) -> str: @@ -754,6 +751,10 @@ def custom_serializer(data) -> str: app = ApiGatewayResolver(serializer=custom_serializer) + class Color(Enum): + RED = 1 + BLUE = 2 + @app.get("/colors") def get_color() -> Dict: return { @@ -761,8 +762,10 @@ def get_color() -> Dict: "variations": {"light", "dark"}, } + # WHEN calling handler response = app({"httpMethod": "GET", "path": "/colors"}, None) + # THEN then use the custom serializer body = response["body"] - expected = '{"color": 1, "variations": ["light", "dark"]}' + expected = '{"color": 1, "variations": ["dark", "light"]}' assert expected == body