[#312] Add new tagging tests for s3
Signed-off-by: Yulia Kovshova <y.kovshova@yadro.com>
This commit is contained in:
parent
1d09fc73b6
commit
bb62299945
5 changed files with 185 additions and 34 deletions
|
@ -2,8 +2,8 @@ import os
|
|||
from typing import Optional
|
||||
|
||||
import allure
|
||||
|
||||
from steps import s3_gate_bucket, s3_gate_object
|
||||
import s3_gate_bucket
|
||||
import s3_gate_object
|
||||
|
||||
|
||||
@allure.step("Expected all objects are presented in the bucket")
|
||||
|
@ -48,3 +48,45 @@ def set_bucket_versioning(s3_client, bucket: str, status: s3_gate_bucket.Version
|
|||
|
||||
def object_key_from_file_path(full_path: str) -> str:
|
||||
return os.path.basename(full_path)
|
||||
|
||||
|
||||
def assert_tags(
|
||||
actual_tags: list, expected_tags: Optional[list] = None, unexpected_tags: Optional[list] = None
|
||||
) -> None:
|
||||
expected_tags = (
|
||||
[{"Key": key, "Value": value} for key, value in expected_tags] if expected_tags else []
|
||||
)
|
||||
unexpected_tags = (
|
||||
[{"Key": key, "Value": value} for key, value in unexpected_tags] if unexpected_tags else []
|
||||
)
|
||||
if expected_tags == []:
|
||||
assert not actual_tags, f"Expected there is no tags, got {actual_tags}"
|
||||
assert len(expected_tags) == len(actual_tags)
|
||||
for tag in expected_tags:
|
||||
assert tag in actual_tags, f"Tag {tag} must be in {actual_tags}"
|
||||
for tag in unexpected_tags:
|
||||
assert tag not in actual_tags, f"Tag {tag} should not be in {actual_tags}"
|
||||
|
||||
|
||||
@allure.step("Expected all tags are presented in object")
|
||||
def check_tags_by_object(
|
||||
s3_client,
|
||||
bucket: str,
|
||||
key_name: str,
|
||||
expected_tags: list,
|
||||
unexpected_tags: Optional[list] = None,
|
||||
) -> None:
|
||||
actual_tags = s3_gate_object.get_object_tagging(s3_client, bucket, key_name)
|
||||
assert_tags(
|
||||
expected_tags=expected_tags, unexpected_tags=unexpected_tags, actual_tags=actual_tags
|
||||
)
|
||||
|
||||
|
||||
@allure.step("Expected all tags are presented in bucket")
|
||||
def check_tags_by_bucket(
|
||||
s3_client, bucket: str, expected_tags: list, unexpected_tags: Optional[list] = None
|
||||
) -> None:
|
||||
actual_tags = s3_gate_bucket.get_bucket_tagging(s3_client, bucket)
|
||||
assert_tags(
|
||||
expected_tags=expected_tags, unexpected_tags=unexpected_tags, actual_tags=actual_tags
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue