Skip to content

Commit

Permalink
test_objects
Browse files Browse the repository at this point in the history
Signed-off-by: MaxGelbakhiani <[email protected]>
  • Loading branch information
MaxGelbakhiani committed Mar 26, 2024
1 parent 1f6f121 commit 2931e50
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 53 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,20 @@ jobs:
source venv/bin/activate && pytest test_downloads.py --base_url="$OUTPUT_CONTAINER_URL" --report_dir="$REPORT_DIR" --data_dir_prefix=../$REPORT_DIR
working-directory: ./tests

- name: Run obj count test
env:
NEOFS_WALLET: "../wallet.json"
NEOFS_WALLET_PASSWORD: ${{ secrets.NEOFS_WALLET_PASSWORD }}
NEOFS_NETWORK_DOMAIN: ${{ vars.NEOFS_NETWORK_DOMAIN }}
NEOFS_HTTP_GATE: ${{ vars.NEOFS_HTTP_GATE }}
STORE_OBJECTS_CID: ${{ vars.STORE_OBJECTS_CID }}
LIFETIME: ${{ vars.LIFETIME }}
PATH_TO_FILES_DIR: ${{ env.REWRITE_CONT_DIR }}
REPORT_DIR: ${{ env.REWRITE_CONT_DIR }}
run: |
source venv/bin/activate && pytest test_objects.py
working-directory: ./tests

- name: tmate session
if: always()
uses: mxschmitt/action-tmate@v3
45 changes: 45 additions & 0 deletions helpers/neofs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import subprocess
import json


def neofs_cli_execute(cmd: str, json_output: bool = False, timeout: int = None):
"""
Executes a given command and returns its output.
:param cmd: Command to execute.
:param json_output: Specifies if the command output is JSON.
:param timeout: Optional timeout for command execution.
:return: Command output as a string or a JSON object.
"""

try:
compl_proc = subprocess.run(
cmd,
check=True,
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
timeout=timeout,
shell=True,
)

print(f"RC: {compl_proc.returncode}")
print(f"Output: {compl_proc.stdout}")

if json_output:
try:
return json.loads(compl_proc.stdout)
except json.JSONDecodeError:
output_list = compl_proc.stdout.splitlines()
return json.dumps(output_list)
else:
return compl_proc.stdout.splitlines()

except subprocess.CalledProcessError as e:
raise Exception(
f"Command failed: {e.cmd}\n"
f"Error code: {e.returncode}\n"
f"Output: {e.output}\n"
f"Stdout: {e.stdout}\n"
f"Stderr: {e.stderr}\n"
)
41 changes: 1 addition & 40 deletions push-to-neofs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import subprocess
import argparse
import magic
import json
import distutils.util
from helpers.neofs import neofs_cli_execute

FILE_PATH = "FilePath" # the key for the attribute, is the path for the static page and allure report zip files
CONTENT_TYPE = "ContentType"
Expand Down Expand Up @@ -113,45 +113,6 @@ def get_rpc_endpoint(neofs_domain: str) -> str:
return f"{neofs_domain}:{PORT_8080}"


def neofs_cli_execute(cmd: str, json_output: bool = False, timeout: int = None):
"""
Executes a given command and returns its output.
:param cmd: Command to execute.
:param json_output: Specifies if the command output is JSON.
:param timeout: Optional timeout for command execution.
:return: Command output as a string or a JSON object.
"""

try:
compl_proc = subprocess.run(
cmd,
check=True,
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
timeout=timeout,
shell=True,
)

print(f"RC: {compl_proc.returncode}")
print(f"Output: {compl_proc.stdout}")

if json_output:
return json.loads(compl_proc.stdout)
else:
return compl_proc.stdout.splitlines()

except subprocess.CalledProcessError as e:
raise Exception(
f"Command failed: {e.cmd}\n"
f"Error code: {e.returncode}\n"
f"Output: {e.output}\n"
f"Stdout: {e.stdout}\n"
f"Stderr: {e.stderr}\n"
)


def search_objects_in_container(endpoint: str,
wallet: str,
password: str,
Expand Down
46 changes: 43 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import pytest


Expand All @@ -17,18 +18,57 @@ def pytest_addoption(parser):
default=None,
help="Prefix dir to add to modified test data",
)
parser.addoption("--wallet", action="store", help="NeoFS wallet")
parser.addoption("--wallet-password", action="store", help="NeoFS wallet password")
parser.addoption("--network-domain", action="store", help="NeoFS network domain")
parser.addoption("--http-gate", action="store", help="NeoFS HTTP gate")
parser.addoption("--cid", action="store", help="CID of objects to store")


@pytest.fixture
def base_url(request):
return request.config.getoption("--base_url")
return os.environ.get('BASE_URL') or request.config.getoption("--base_url")


@pytest.fixture
def report_dir(request):
return request.config.getoption("--report_dir")
return os.environ.get('REPORT_DIR') or request.config.getoption("--report_dir")


@pytest.fixture
def data_dir_prefix(request):
return request.config.getoption("--data_dir_prefix")
return os.environ.get('DATA_DIR_PREFIX') or request.config.getoption("--data_dir_prefix")


DATA_PATH_LIST = [
"data/1.txt",
"data/2.txt",
"data/dir/3.txt",
"data/dir/subdir/4.txt",
"data/dir/subdir/subdir_2/5.txt",
]


@pytest.fixture
def wallet(request):
return os.environ.get('NEOFS_WALLET') or request.config.getoption("--wallet")


@pytest.fixture
def wallet_password(request):
return os.environ.get('NEOFS_WALLET_PASSWORD') or request.config.getoption("--wallet-password")


@pytest.fixture
def network_domain(request):
return os.environ.get('NEOFS_NETWORK_DOMAIN') or request.config.getoption("--network-domain")


@pytest.fixture
def http_gate(request):
return os.environ.get('NEOFS_HTTP_GATE') or request.config.getoption("--http-gate")


@pytest.fixture
def cid(request):
return os.environ.get('STORE_OBJECTS_CID') or request.config.getoption("--cid")
12 changes: 2 additions & 10 deletions tests/test_downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import requests
import pytest
from urllib.parse import urljoin
from conftest import DATA_PATH_LIST


def download_file(url: str) -> str:
Expand All @@ -10,16 +11,7 @@ def download_file(url: str) -> str:
return response.text


@pytest.mark.parametrize(
"path",
[
"data/1.txt",
"data/2.txt",
"data/dir/3.txt",
"data/dir/subdir/4.txt",
"data/dir/subdir/subdir_2/5.txt",
],
)
@pytest.mark.parametrize("path", DATA_PATH_LIST)
def test_file_content(base_url, report_dir, data_dir_prefix, path):
if base_url is None:
pytest.fail("base_url is not provided. Provide it using --base_url option.")
Expand Down
20 changes: 20 additions & 0 deletions tests/test_objects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import sys
import pytest
from conftest import DATA_PATH_LIST

sys.path.insert(0, '..')
from helpers.neofs import neofs_cli_execute


def test_objects_number(wallet, wallet_password, network_domain, cid):
cmd = (
f"NEOFS_CLI_PASSWORD={wallet_password} neofs-cli --rpc-endpoint {network_domain}:8080 "
f"--wallet {wallet} container list-objects --cid {cid}"
)
objects_list = neofs_cli_execute(cmd, json_output=True)
print(objects_list)
obj_number = len(objects_list)
files_num = len(DATA_PATH_LIST)
assert (
obj_number == files_num
), f"Objects number of {obj_number} in the container and the number {files_num} of uploaded files doesn't match"

0 comments on commit 2931e50

Please sign in to comment.