Skip to content

Commit

Permalink
update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abikouo committed Oct 18, 2022
1 parent f2fc643 commit 0ae6e58
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
2 changes: 1 addition & 1 deletion plugins/module_utils/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
__metaclass__ = type

from ansible.module_utils.basic import to_text
from ansible.module_utils.six.moves.urllib.parse import urlparse
from urllib.parse import urlparse

from .botocore import boto3_conn

Expand Down
19 changes: 7 additions & 12 deletions tests/unit/module_utils/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def generate_random_string(size, include_digits=True):
return ''.join(random.choice(buffer) for i in range(size))


@pytest.mark.parametrize("parts", range(10))
@pytest.mark.parametrize("parts", range(0, 10, 3))
@pytest.mark.parametrize("version", [True, False])
def test_s3_head_objects(parts, version):

Expand Down Expand Up @@ -68,7 +68,7 @@ def raise_botoclient_exception():


@pytest.mark.parametrize("use_file", [False, True])
@pytest.mark.parametrize("parts", range(10))
@pytest.mark.parametrize("parts", range(0, 10, 3))
@patch("ansible_collections.amazon.aws.plugins.module_utils.s3.md5")
@patch("ansible_collections.amazon.aws.plugins.module_utils.s3.s3_head_objects")
def test_calculate_checksum(m_s3_head_objects, m_s3_md5, use_file, parts, tmp_path):
Expand Down Expand Up @@ -370,14 +370,7 @@ def test_parse_default_endpoint(m_config, mode, encryption_mode, dualstack, sig_
assert result == expected


@pytest.mark.parametrize(
"ceph,isfakes3",
[
(True, False),
(False, True),
(False, False),
]
)
@pytest.mark.parametrize("scenario", ["ceph", "fakes3", "default"])
@patch('ansible_collections.amazon.aws.plugins.module_utils.s3.parse_default_endpoint')
@patch('ansible_collections.amazon.aws.plugins.module_utils.s3.parse_fakes3_endpoint')
@patch('ansible_collections.amazon.aws.plugins.module_utils.s3.is_fakes3')
Expand All @@ -386,8 +379,7 @@ def test_s3_conn_params(m_parse_ceph_endpoint,
m_is_fakes3,
m_parse_fakes3_endpoint,
m_parse_default_endpoint,
ceph,
isfakes3):
scenario):

url = "https://my-bucket.s3.us-west-2.amazonaws.com"
region = "us-east-1"
Expand All @@ -399,6 +391,9 @@ def test_s3_conn_params(m_parse_ceph_endpoint,

endpoint = {"endpoint": url, "config": {"s3": True, "signature": "s123"}}

ceph = bool(scenario == "ceph")
isfakes3 = bool(scenario == "fakes3")

m_is_fakes3.return_value = isfakes3
if ceph:
m_parse_ceph_endpoint.return_value = endpoint
Expand Down

0 comments on commit 0ae6e58

Please sign in to comment.