Add readable enums #68

Merged
abereziny merged 1 commit from abereziny/frostfs-testlib:feature-add-more-representations into master 2023-08-03 09:26:06 +00:00
5 changed files with 22 additions and 10 deletions

View file

@ -1,9 +1,8 @@
from abc import abstractmethod
from datetime import datetime
from enum import Enum
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):
@ -15,7 +14,7 @@ def _make_objs_dict(key_names):
return objs_dict
class VersioningStatus(Enum):
class VersioningStatus(HumanReadableEnum):
ENABLED = "Enabled"
SUSPENDED = "Suspended"

View file

@ -14,6 +14,7 @@ from frostfs_testlib.resources.common import ASSETS_DIR, DEFAULT_WALLET_CONFIG
from frostfs_testlib.shell import Shell
from frostfs_testlib.storage.dataclasses.storage_object_info import StorageObjectInfo
from frostfs_testlib.storage.dataclasses.wallet import WalletInfo
from frostfs_testlib.testing.readable import HumanReadableEnum
from frostfs_testlib.utils import json_utils, wallet_utils
reporter = get_reporter()
@ -26,7 +27,7 @@ WRONG_VERB = "wrong verb of the session"
INVALID_SIGNATURE = "invalid signature of the session data"
class ObjectVerb(Enum):
class ObjectVerb(HumanReadableEnum):
PUT = "PUT"
DELETE = "DELETE"
GET = "GET"
@ -36,7 +37,7 @@ class ObjectVerb(Enum):
SEARCH = "SEARCH"
class ContainerVerb(Enum):
class ContainerVerb(HumanReadableEnum):
CREATE = "PUT"
DELETE = "DELETE"
SETEACL = "SETEACL"

View file

@ -3,6 +3,7 @@ from dataclasses import dataclass
from enum import Enum
from typing import Any, Dict, List, Optional, Union
from frostfs_testlib.testing.readable import HumanReadableEnum
from frostfs_testlib.utils import wallet_utils
logger = logging.getLogger("NeoLogger")
@ -10,7 +11,7 @@ EACL_LIFETIME = 100500
FROSTFS_CONTRACT_CACHE_TIMEOUT = 30
class EACLOperation(Enum):
class EACLOperation(HumanReadableEnum):
PUT = "put"
GET = "get"
HEAD = "head"
@ -20,24 +21,24 @@ class EACLOperation(Enum):
DELETE = "delete"
class EACLAccess(Enum):
class EACLAccess(HumanReadableEnum):
ALLOW = "allow"
DENY = "deny"
class EACLRole(Enum):
class EACLRole(HumanReadableEnum):
OTHERS = "others"
USER = "user"
SYSTEM = "system"
class EACLHeaderType(Enum):
class EACLHeaderType(HumanReadableEnum):
REQUEST = "req" # Filter request headers
OBJECT = "obj" # Filter object headers
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_NOT_EQUAL = "!=" # Return true if strings are different

View file

@ -1,4 +1,13 @@
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):

View file

@ -3,6 +3,7 @@ from typing import Any
import pytest
from frostfs_testlib.s3 import AwsCliClient, Boto3ClientWrapper
from frostfs_testlib.storage.dataclasses.acl import EACLRole
from frostfs_testlib.storage.dataclasses.frostfs_services import (
HTTPGate,
InnerRing,
@ -30,6 +31,7 @@ class TestDataclassesStr:
(S3Gate, "S3Gate"),
(HTTPGate, "HTTPGate"),
(InnerRing, "InnerRing"),
(EACLRole.OTHERS, "OTHERS"),
],
)
def test_classes_string_representation(self, obj: Any, expected: str):