Skip to content

Commit f5f4123

Browse files
author
Michael Brewer
committed
test(event-handler): fix apigw test
1 parent b2c4915 commit f5f4123

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

tests/functional/event_handler/test_api_gateway.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -733,10 +733,7 @@ def get_account(account_id: str):
733733

734734

735735
def test_custom_serializer():
736-
class Color(Enum):
737-
RED = 1
738-
BLUE = 2
739-
736+
# GIVEN a custom serializer to handle enums and sets
740737
class CustomEncoder(JSONEncoder):
741738
def default(self, data):
742739
if isinstance(data, Enum):
@@ -746,23 +743,29 @@ def default(self, data):
746743
except TypeError:
747744
pass
748745
else:
749-
return list(iterable)
746+
return sorted(iterable)
750747
return JSONEncoder.default(self, data)
751748

752749
def custom_serializer(data) -> str:
753750
return json.dumps(data, cls=CustomEncoder)
754751

755752
app = ApiGatewayResolver(serializer=custom_serializer)
756753

754+
class Color(Enum):
755+
RED = 1
756+
BLUE = 2
757+
757758
@app.get("/colors")
758759
def get_color() -> Dict:
759760
return {
760761
"color": Color.RED,
761762
"variations": {"light", "dark"},
762763
}
763764

765+
# WHEN calling handler
764766
response = app({"httpMethod": "GET", "path": "/colors"}, None)
765767

768+
# THEN then use the custom serializer
766769
body = response["body"]
767-
expected = '{"color": 1, "variations": ["light", "dark"]}'
770+
expected = '{"color": 1, "variations": ["dark", "light"]}'
768771
assert expected == body

0 commit comments

Comments
 (0)