Add EnumE.get_name()
This commit is contained in:
parent
aee917a3ef
commit
d8c9078708
|
@ -112,6 +112,14 @@ class EnumE(enum.Enum):
|
||||||
def has_value(cls, value: int) -> bool:
|
def has_value(cls, value: int) -> bool:
|
||||||
return value in set(item.value for item in cls)
|
return value in set(item.value for item in cls)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_name(cls, value: int):
|
||||||
|
for item in cls:
|
||||||
|
if item.value == value:
|
||||||
|
return item.name
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class PlanEnum(EnumE):
|
class PlanEnum(EnumE):
|
||||||
monthly = 2
|
monthly = 2
|
||||||
|
|
|
@ -12,6 +12,7 @@ from app.models import (
|
||||||
Mailbox,
|
Mailbox,
|
||||||
AliasMailbox,
|
AliasMailbox,
|
||||||
SenderFormatEnum,
|
SenderFormatEnum,
|
||||||
|
EnumE,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -197,3 +198,16 @@ def test_mailbox_delete(flask_client):
|
||||||
Mailbox.delete(m1.id)
|
Mailbox.delete(m1.id)
|
||||||
alias = Alias.get(alias.id)
|
alias = Alias.get(alias.id)
|
||||||
assert len(alias.mailboxes) == 2
|
assert len(alias.mailboxes) == 2
|
||||||
|
|
||||||
|
|
||||||
|
def test_EnumE():
|
||||||
|
class E(EnumE):
|
||||||
|
A = 100
|
||||||
|
B = 200
|
||||||
|
|
||||||
|
assert E.has_value(100)
|
||||||
|
assert not E.has_value(101)
|
||||||
|
|
||||||
|
assert E.get_name(100) == "A"
|
||||||
|
assert E.get_name(200) == "B"
|
||||||
|
assert E.get_name(101) is None
|
||||||
|
|
Loading…
Reference in a new issue