Skip to content

Commit

Permalink
Format code using black
Browse files Browse the repository at this point in the history
System tests code has a problem - different formatting is applied in different
files, classes, or even functions.
I'm tired of "adjusting" for each class, ignoring IDE warnings, manually
removing autocorrect from the IDE's built-in formatter, etc.

I suggest formatting the code once using black formatter:
https://pypi.org/project/black/
And further accept only formatted code.

I used this command to format the code:
python -m black neofs-testcases -t py310

Signed-off-by: Oleg Kulachenko <[email protected]>
  • Loading branch information
vvarg229 committed Oct 2, 2023
1 parent 8226f71 commit ef04906
Show file tree
Hide file tree
Showing 29 changed files with 458 additions and 297 deletions.
2 changes: 1 addition & 1 deletion pytest_tests/helpers/aws_cli_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AwsCliClient:

def __init__(self, s3gate_endpoint) -> None:
self.s3gate_endpoint = s3gate_endpoint
os.environ['AWS_EC2_METADATA_DISABLED'] = 'true'
os.environ["AWS_EC2_METADATA_DISABLED"] = "true"

def create_bucket(
self,
Expand Down
4 changes: 3 additions & 1 deletion pytest_tests/helpers/file_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ def concat_files(file_paths: list, resulting_file_path: Optional[str] = None) ->
Path to the resulting file.
"""
if not resulting_file_path:
resulting_file_path = os.path.join(os.getcwd(), ASSETS_DIR, TEST_FILES_DIR, str(uuid.uuid4()))
resulting_file_path = os.path.join(
os.getcwd(), ASSETS_DIR, TEST_FILES_DIR, str(uuid.uuid4())
)
with open(resulting_file_path, "wb") as f:
for file in file_paths:
with open(file, "rb") as part_file:
Expand Down
5 changes: 4 additions & 1 deletion pytest_tests/helpers/grpc_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
EACL_TIMED_OUT = "eACL setting: await timeout expired"
EACL_TABLE_IS_NOT_SET = "extended ACL table is not set for this container"
EACL_NOT_FOUND = "code = 3073.*message = eACL not found"
EACL_PROHIBITED_TO_MODIFY_SYSTEM_ACCESS = "table validation: it is prohibited to modify system access"
EACL_PROHIBITED_TO_MODIFY_SYSTEM_ACCESS = (
"table validation: it is prohibited to modify system access"
)


def error_matches_status(error: Exception, status_pattern: str) -> bool:
"""
Expand Down
4 changes: 2 additions & 2 deletions pytest_tests/steps/session_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def create_session_token(
wallet_password: str,
rpc_endpoint: str,
lifetime: Optional[int] = None,
expire_at: Optional[int] = None
expire_at: Optional[int] = None,
) -> str:
"""
Create session token for an object.
Expand All @@ -259,7 +259,7 @@ def create_session_token(
wallet_password=wallet_password,
out=session_token,
lifetime=lifetime,
expire_at=expire_at
expire_at=expire_at,
)
return session_token

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ class TestStorageGroup(ClusterTestBase):
@pytest.fixture(autouse=True)
def prepare_two_wallets(self, default_wallet):
self.main_wallet = default_wallet
self.other_wallet = os.path.join(os.getcwd(), ASSETS_DIR, TEST_FILES_DIR, f"{str(uuid.uuid4())}.json")
self.other_wallet = os.path.join(
os.getcwd(), ASSETS_DIR, TEST_FILES_DIR, f"{str(uuid.uuid4())}.json"
)
init_wallet(self.other_wallet, WALLET_PASS)
if not FREE_STORAGE:
main_chain = self.cluster.main_chain_nodes[0]
Expand Down
24 changes: 18 additions & 6 deletions pytest_tests/testsuites/acl/test_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@

from testsuites.acl.conftest import Wallets
from cluster_test_base import ClusterTestBase
from object_access import can_put_object, can_get_object, can_get_head_object, can_search_object, \
can_get_range_of_object, can_get_range_hash_of_object, can_delete_object
from object_access import (
can_put_object,
can_get_object,
can_get_head_object,
can_search_object,
can_get_range_of_object,
can_get_range_hash_of_object,
can_delete_object,
)
from python_keywords.acl import EACLRole
from python_keywords.container import create_container
from python_keywords.container_access import (
Expand Down Expand Up @@ -184,7 +191,9 @@ def test_basic_acl_readonly(self, wallets, client_shell, read_only_container, fi
)

@allure.title("Test basic ACL IR and STORAGE rules compliance")
def test_basic_acl_ir_storage_rules_compliance(self, wallets: Wallets, public_container: str, file_path: str):
def test_basic_acl_ir_storage_rules_compliance(
self, wallets: Wallets, public_container: str, file_path: str
):
"""
Test basic ACL IR and STORAGE rules compliance.
Expand Down Expand Up @@ -311,7 +320,9 @@ def test_basic_acl_ir_storage_rules_compliance(self, wallets: Wallets, public_co
endpoint=endpoint,
wallet_config=ir_wallet.config_path,
)
with allure.step("STORAGE node should NOT be able to GET range of object from container"):
with allure.step(
"STORAGE node should NOT be able to GET range of object from container"
):
assert not can_get_range_of_object(
wallet=storage_wallet.wallet_path,
cid=cid,
Expand All @@ -330,7 +341,9 @@ def test_basic_acl_ir_storage_rules_compliance(self, wallets: Wallets, public_co
endpoint=endpoint,
wallet_config=ir_wallet.config_path,
)
with allure.step("STORAGE node should be able to GET range hash of object from container"):
with allure.step(
"STORAGE node should be able to GET range hash of object from container"
):
assert can_get_range_hash_of_object(
wallet=storage_wallet.wallet_path,
cid=cid,
Expand Down Expand Up @@ -358,4 +371,3 @@ def test_basic_acl_ir_storage_rules_compliance(self, wallets: Wallets, public_co
endpoint=endpoint,
wallet_config=storage_wallet.config_path,
)

13 changes: 9 additions & 4 deletions pytest_tests/testsuites/acl/test_eacl.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
EACLRule,
create_eacl,
set_eacl,
wait_for_cache_expired, get_eacl,
wait_for_cache_expired,
get_eacl,
)
from python_keywords.container import create_container
from python_keywords.container_access import (
Expand Down Expand Up @@ -302,8 +303,12 @@ def test_deprecated_change_system_eacl(self, wallets, eacl_container_with_object

@pytest.mark.trusted_party_proved
@pytest.mark.system_eacl
@allure.title("Test case for verifying the impossible to change system extended ACL if eACL already set")
def test_deprecated_change_system_eacl_if_eacl_already_set(self, wallets, eacl_container_with_objects):
@allure.title(
"Test case for verifying the impossible to change system extended ACL if eACL already set"
)
def test_deprecated_change_system_eacl_if_eacl_already_set(
self, wallets, eacl_container_with_objects
):
user_wallet = wallets.get_wallet()
cid, object_oids, file_path = eacl_container_with_objects
endpoint = self.cluster.default_rpc_endpoint
Expand Down Expand Up @@ -489,7 +494,7 @@ def test_only_owner_can_set_eacl(
self,
wallets: Wallets,
eacl_full_placement_container_with_object: tuple[str, str, str],
not_owner_wallet: str
not_owner_wallet: str,
):
cid, oid, file_path = eacl_full_placement_container_with_object

Expand Down
32 changes: 19 additions & 13 deletions pytest_tests/testsuites/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def pytest_runtest_makereport(item, call):
# be "setup", "call", "teardown"
item.stash.setdefault(phase_report_key, {})[rep.when] = rep


def pytest_collection_modifyitems(items):
# Make network tests last based on @pytest.mark.node_mgmt
def priority(item: pytest.Item) -> int:
Expand Down Expand Up @@ -167,7 +168,7 @@ def temp_directory() -> str:


@pytest.fixture(scope="module", autouse=True)
@allure.title(f'Prepare test files directories')
@allure.title(f"Prepare test files directories")
def artifacts_directory(temp_directory: str) -> None:
dirs = [TEST_FILES_DIR, TEST_OBJECTS_DIR]
for dir_name in dirs:
Expand All @@ -185,7 +186,7 @@ def artifacts_directory(temp_directory: str) -> None:
@pytest.fixture(scope="session", autouse=True)
@allure.title("Collect full logs")
def collect_full_tests_logs(temp_directory, hosting: Hosting):
test_name = 'full_logs'
test_name = "full_logs"
start_time = datetime.utcnow()
yield
end_time = datetime.utcnow()
Expand All @@ -199,15 +200,15 @@ def collect_full_tests_logs(temp_directory, hosting: Hosting):
def collect_test_logs(request, temp_directory, hosting: Hosting):
test_name = request.node.nodeid.translate(str.maketrans(":[]/", "____"))
hash_suffix = hashlib.md5(test_name.encode()).hexdigest()
file_name = (test_name[:200] + '_' + hash_suffix) # limit total length to 255
file_name = test_name[:200] + "_" + hash_suffix # limit total length to 255
logs_dir = os.path.join(temp_directory, "logs")
with allure.step(f'Start collecting logs for {file_name}'):
with allure.step(f"Start collecting logs for {file_name}"):
start_time = datetime.utcnow()
yield
# https://docs.pytest.org/en/latest/example/simple.html#making-test-result-information-available-in-fixtures
report = request.node.stash[phase_report_key]
if report["setup"].failed or ("call" in report and report["call"].failed):
with allure.step(f'Stop collecting logs for {file_name}, logs path: {logs_dir} '):
with allure.step(f"Stop collecting logs for {file_name}, logs path: {logs_dir} "):
end_time = datetime.utcnow()
store_logs(hosting, logs_dir, file_name, start_time, end_time)

Expand All @@ -219,13 +220,13 @@ def netinfo(request, cluster: Cluster, client_shell: Shell, default_wallet: str)
report = request.node.stash[phase_report_key]
if report["setup"].failed or ("call" in report and report["call"].failed):
for node in cluster.storage_nodes:
with allure.step(f'Checking netinfo for node {node}'):
with allure.step(f"Checking netinfo for node {node}"):
net_info = get_netmap_netinfo(
wallet=default_wallet,
endpoint=node.get_rpc_endpoint(),
shell=client_shell,
)
logger.info(f'Netinfo from {node}:\n{net_info}')
logger.info(f"Netinfo from {node}:\n{net_info}")


@pytest.fixture(scope="session", autouse=True)
Expand Down Expand Up @@ -309,7 +310,7 @@ def background_grpc_load(client_shell: Shell, hosting: Hosting):
@pytest.fixture(scope="function")
@allure.title("Prepare not owner wallet and deposit")
def not_owner_wallet(client_shell: Shell, temp_directory: str, cluster: Cluster) -> str:
wallet_path = create_wallet(client_shell, temp_directory, cluster, 'not_owner_wallet')
wallet_path = create_wallet(client_shell, temp_directory, cluster, "not_owner_wallet")
yield wallet_path
os.remove(wallet_path)

Expand All @@ -319,6 +320,7 @@ def not_owner_wallet(client_shell: Shell, temp_directory: str, cluster: Cluster)
def default_wallet(client_shell: Shell, temp_directory: str, cluster: Cluster):
return create_wallet(client_shell, temp_directory, cluster)


@allure.title("Check logs for OOM and PANIC entries in {logs_dir}")
def check_logs(logs_dir: str):
problem_pattern = r"\Wpanic\W|\Woom\W|\Wtoo many open files\W"
Expand All @@ -341,7 +343,9 @@ def check_logs(logs_dir: str):
raise pytest.fail(f"System logs {', '.join(logs_with_problem)} contain critical errors")


def store_logs(hosting: Hosting, logs_dir: str, file_name: str, start_time: datetime, end_time: datetime) -> None:
def store_logs(
hosting: Hosting, logs_dir: str, file_name: str, start_time: datetime, end_time: datetime
) -> None:
os.makedirs(logs_dir, exist_ok=True)
dump_logs(hosting, logs_dir, start_time, end_time)
attach_logs(logs_dir, os.path.join(os.getcwd(), ASSETS_DIR, file_name))
Expand All @@ -363,7 +367,7 @@ def attach_logs(logs_dir: str, test_name: str) -> None:
# Zip all files and attach to Allure because it is more convenient to download a single
# zip with all logs rather than mess with individual logs files per service or node
logs_zip_file_path = shutil.make_archive(test_name, "zip", logs_dir)
allure.attach.file(logs_zip_file_path, name=f'{test_name}.zip', extension="zip")
allure.attach.file(logs_zip_file_path, name=f"{test_name}.zip", extension="zip")


def create_dir(dir_path: str) -> None:
Expand All @@ -378,11 +382,13 @@ def remove_dir(dir_path: str) -> None:


@allure.title("Prepare wallet and deposit")
def create_wallet(client_shell: Shell, temp_directory: str, cluster: Cluster, name: Optional[str] = None) -> str:
def create_wallet(
client_shell: Shell, temp_directory: str, cluster: Cluster, name: Optional[str] = None
) -> str:
if name is None:
wallet_name = f'{str(uuid.uuid4())}.json'
wallet_name = f"{str(uuid.uuid4())}.json"
else:
wallet_name = f'{name}.json'
wallet_name = f"{name}.json"

wallet_path = os.path.join(os.getcwd(), ASSETS_DIR, wallet_name)
init_wallet(wallet_path, WALLET_PASS)
Expand Down
4 changes: 1 addition & 3 deletions pytest_tests/testsuites/container/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ def test_container_creation(self, default_wallet, name):
@pytest.mark.trusted_party_proved
@allure.title("Not owner and not trusted party can NOT delete container")
def test_only_owner_can_delete_container(
self,
not_owner_wallet: WalletFile,
default_wallet: str
self, not_owner_wallet: WalletFile, default_wallet: str
):
cid = create_container(
wallet=default_wallet,
Expand Down
Loading

0 comments on commit ef04906

Please sign in to comment.