From e4878f4d1e4b1aaa1df2006674d5437c9ace90c2 Mon Sep 17 00:00:00 2001 From: Andrey Berezin Date: Wed, 2 Aug 2023 21:38:27 +0300 Subject: [PATCH] Add readable enums Signed-off-by: Andrey Berezin --- src/frostfs_testlib/s3/interfaces.py | 5 ++--- src/frostfs_testlib/steps/session_token.py | 5 +++-- src/frostfs_testlib/storage/dataclasses/acl.py | 11 ++++++----- src/frostfs_testlib/testing/readable.py | 9 +++++++++ tests/test_dataclasses.py | 2 ++ 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/frostfs_testlib/s3/interfaces.py b/src/frostfs_testlib/s3/interfaces.py index 166abff..8d82f71 100644 --- a/src/frostfs_testlib/s3/interfaces.py +++ b/src/frostfs_testlib/s3/interfaces.py @@ -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" diff --git a/src/frostfs_testlib/steps/session_token.py b/src/frostfs_testlib/steps/session_token.py index 14e25f1..b82d0e2 100644 --- a/src/frostfs_testlib/steps/session_token.py +++ b/src/frostfs_testlib/steps/session_token.py @@ -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" diff --git a/src/frostfs_testlib/storage/dataclasses/acl.py b/src/frostfs_testlib/storage/dataclasses/acl.py index cceb4d8..1330618 100644 --- a/src/frostfs_testlib/storage/dataclasses/acl.py +++ b/src/frostfs_testlib/storage/dataclasses/acl.py @@ -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 diff --git a/src/frostfs_testlib/testing/readable.py b/src/frostfs_testlib/testing/readable.py index 66384b7..80f1169 100644 --- a/src/frostfs_testlib/testing/readable.py +++ b/src/frostfs_testlib/testing/readable.py @@ -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): diff --git a/tests/test_dataclasses.py b/tests/test_dataclasses.py index 11cda7a..f1cc51e 100644 --- a/tests/test_dataclasses.py +++ b/tests/test_dataclasses.py @@ -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):