Skip to content

Commit

Permalink
fix enum comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
zworkb committed Apr 23, 2024
1 parent d5003b1 commit 2e07c3e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/edutap/wallet_google/models/primitives/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,18 @@ def __new__(cls: type["CamelCaseAliasEnum"], value: str) -> "CamelCaseAliasEnum"
cls._member_names_.append(camel)
return obj


def __eq__(self, other: Enum) -> bool:
"""Allow comparison with the camelcase value.
take into account that UPPER_CASE and camelCase are equal
"""
if self.value == other.value:
return True
else:
v1 = self.value.lower().replace("_", "")
v2 = other.value.lower().replace("_", "")
return v1 == v2


class Action(CamelCaseAliasEnum):
"""
see: https://developers.google.com/wallet/generic/rest/v1/smarttap#action
Expand Down
2 changes: 2 additions & 0 deletions tests/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def test_action_enum():

assert Action("ACTION_UNSPECIFIED") == Action.ACTION_UNSPECIFIED
assert Action("actionUnspecified") == Action.ACTION_UNSPECIFIED

assert Action("S2AP") != Action.ACTION_UNSPECIFIED

assert Action("S2AP") == Action.S2AP
assert Action("s2ap") == Action.S2AP
Expand Down

0 comments on commit 2e07c3e

Please sign in to comment.