Add readable enums
Signed-off-by: Andrey Berezin <a.berezin@yadro.com>
This commit is contained in:
parent
807235af95
commit
e4878f4d1e
5 changed files with 22 additions and 10 deletions
|
@ -1,9 +1,8 @@
|
||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from enum import Enum
|
|
||||||
from typing import Literal, Optional, Union
|
from typing import Literal, Optional, Union
|
||||||
|
|
||||||
from frostfs_testlib.testing.readable import HumanReadableABC
|
from frostfs_testlib.testing.readable import HumanReadableABC, HumanReadableEnum
|
||||||
|
|
||||||
|
|
||||||
def _make_objs_dict(key_names):
|
def _make_objs_dict(key_names):
|
||||||
|
@ -15,7 +14,7 @@ def _make_objs_dict(key_names):
|
||||||
return objs_dict
|
return objs_dict
|
||||||
|
|
||||||
|
|
||||||
class VersioningStatus(Enum):
|
class VersioningStatus(HumanReadableEnum):
|
||||||
ENABLED = "Enabled"
|
ENABLED = "Enabled"
|
||||||
SUSPENDED = "Suspended"
|
SUSPENDED = "Suspended"
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ from frostfs_testlib.resources.common import ASSETS_DIR, DEFAULT_WALLET_CONFIG
|
||||||
from frostfs_testlib.shell import Shell
|
from frostfs_testlib.shell import Shell
|
||||||
from frostfs_testlib.storage.dataclasses.storage_object_info import StorageObjectInfo
|
from frostfs_testlib.storage.dataclasses.storage_object_info import StorageObjectInfo
|
||||||
from frostfs_testlib.storage.dataclasses.wallet import WalletInfo
|
from frostfs_testlib.storage.dataclasses.wallet import WalletInfo
|
||||||
|
from frostfs_testlib.testing.readable import HumanReadableEnum
|
||||||
from frostfs_testlib.utils import json_utils, wallet_utils
|
from frostfs_testlib.utils import json_utils, wallet_utils
|
||||||
|
|
||||||
reporter = get_reporter()
|
reporter = get_reporter()
|
||||||
|
@ -26,7 +27,7 @@ WRONG_VERB = "wrong verb of the session"
|
||||||
INVALID_SIGNATURE = "invalid signature of the session data"
|
INVALID_SIGNATURE = "invalid signature of the session data"
|
||||||
|
|
||||||
|
|
||||||
class ObjectVerb(Enum):
|
class ObjectVerb(HumanReadableEnum):
|
||||||
PUT = "PUT"
|
PUT = "PUT"
|
||||||
DELETE = "DELETE"
|
DELETE = "DELETE"
|
||||||
GET = "GET"
|
GET = "GET"
|
||||||
|
@ -36,7 +37,7 @@ class ObjectVerb(Enum):
|
||||||
SEARCH = "SEARCH"
|
SEARCH = "SEARCH"
|
||||||
|
|
||||||
|
|
||||||
class ContainerVerb(Enum):
|
class ContainerVerb(HumanReadableEnum):
|
||||||
CREATE = "PUT"
|
CREATE = "PUT"
|
||||||
DELETE = "DELETE"
|
DELETE = "DELETE"
|
||||||
SETEACL = "SETEACL"
|
SETEACL = "SETEACL"
|
||||||
|
|
|
@ -3,6 +3,7 @@ from dataclasses import dataclass
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any, Dict, List, Optional, Union
|
from typing import Any, Dict, List, Optional, Union
|
||||||
|
|
||||||
|
from frostfs_testlib.testing.readable import HumanReadableEnum
|
||||||
from frostfs_testlib.utils import wallet_utils
|
from frostfs_testlib.utils import wallet_utils
|
||||||
|
|
||||||
logger = logging.getLogger("NeoLogger")
|
logger = logging.getLogger("NeoLogger")
|
||||||
|
@ -10,7 +11,7 @@ EACL_LIFETIME = 100500
|
||||||
FROSTFS_CONTRACT_CACHE_TIMEOUT = 30
|
FROSTFS_CONTRACT_CACHE_TIMEOUT = 30
|
||||||
|
|
||||||
|
|
||||||
class EACLOperation(Enum):
|
class EACLOperation(HumanReadableEnum):
|
||||||
PUT = "put"
|
PUT = "put"
|
||||||
GET = "get"
|
GET = "get"
|
||||||
HEAD = "head"
|
HEAD = "head"
|
||||||
|
@ -20,24 +21,24 @@ class EACLOperation(Enum):
|
||||||
DELETE = "delete"
|
DELETE = "delete"
|
||||||
|
|
||||||
|
|
||||||
class EACLAccess(Enum):
|
class EACLAccess(HumanReadableEnum):
|
||||||
ALLOW = "allow"
|
ALLOW = "allow"
|
||||||
DENY = "deny"
|
DENY = "deny"
|
||||||
|
|
||||||
|
|
||||||
class EACLRole(Enum):
|
class EACLRole(HumanReadableEnum):
|
||||||
OTHERS = "others"
|
OTHERS = "others"
|
||||||
USER = "user"
|
USER = "user"
|
||||||
SYSTEM = "system"
|
SYSTEM = "system"
|
||||||
|
|
||||||
|
|
||||||
class EACLHeaderType(Enum):
|
class EACLHeaderType(HumanReadableEnum):
|
||||||
REQUEST = "req" # Filter request headers
|
REQUEST = "req" # Filter request headers
|
||||||
OBJECT = "obj" # Filter object headers
|
OBJECT = "obj" # Filter object headers
|
||||||
SERVICE = "SERVICE" # Filter service headers. These are not processed by FrostFS nodes and exist for service use only
|
SERVICE = "SERVICE" # Filter service headers. These are not processed by FrostFS nodes and exist for service use only
|
||||||
|
|
||||||
|
|
||||||
class EACLMatchType(Enum):
|
class EACLMatchType(HumanReadableEnum):
|
||||||
STRING_EQUAL = "=" # Return true if strings are equal
|
STRING_EQUAL = "=" # Return true if strings are equal
|
||||||
STRING_NOT_EQUAL = "!=" # Return true if strings are different
|
STRING_NOT_EQUAL = "!=" # Return true if strings are different
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,13 @@
|
||||||
from abc import ABCMeta
|
from abc import ABCMeta
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
|
||||||
|
class HumanReadableEnum(Enum):
|
||||||
|
def __str__(self):
|
||||||
|
return self._name_
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return self._name_
|
||||||
|
|
||||||
|
|
||||||
class HumanReadableABCMeta(ABCMeta):
|
class HumanReadableABCMeta(ABCMeta):
|
||||||
|
|
|
@ -3,6 +3,7 @@ from typing import Any
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from frostfs_testlib.s3 import AwsCliClient, Boto3ClientWrapper
|
from frostfs_testlib.s3 import AwsCliClient, Boto3ClientWrapper
|
||||||
|
from frostfs_testlib.storage.dataclasses.acl import EACLRole
|
||||||
from frostfs_testlib.storage.dataclasses.frostfs_services import (
|
from frostfs_testlib.storage.dataclasses.frostfs_services import (
|
||||||
HTTPGate,
|
HTTPGate,
|
||||||
InnerRing,
|
InnerRing,
|
||||||
|
@ -30,6 +31,7 @@ class TestDataclassesStr:
|
||||||
(S3Gate, "S3Gate"),
|
(S3Gate, "S3Gate"),
|
||||||
(HTTPGate, "HTTPGate"),
|
(HTTPGate, "HTTPGate"),
|
||||||
(InnerRing, "InnerRing"),
|
(InnerRing, "InnerRing"),
|
||||||
|
(EACLRole.OTHERS, "OTHERS"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_classes_string_representation(self, obj: Any, expected: str):
|
def test_classes_string_representation(self, obj: Any, expected: str):
|
||||||
|
|
Loading…
Reference in a new issue