From 38b7c80217c4e72b1d8988eb1e60bb6e77334114 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 18 Apr 2024 07:52:22 +0200 Subject: Adding upstream version 9.4.0+dfsg. Signed-off-by: Daniel Baumann --- .../fusion/tests/unit/mocks/operation_mock.py | 14 ++++++- .../fusion/tests/unit/module_utils/test_parsing.py | 47 ++++++++++++++-------- .../fusion/tests/unit/modules/test_fusion_az.py | 10 +++-- 3 files changed, 51 insertions(+), 20 deletions(-) (limited to 'ansible_collections/purestorage/fusion/tests/unit') diff --git a/ansible_collections/purestorage/fusion/tests/unit/mocks/operation_mock.py b/ansible_collections/purestorage/fusion/tests/unit/mocks/operation_mock.py index 99487ddfa..a3a70c67d 100644 --- a/ansible_collections/purestorage/fusion/tests/unit/mocks/operation_mock.py +++ b/ansible_collections/purestorage/fusion/tests/unit/mocks/operation_mock.py @@ -8,6 +8,9 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type from enum import Enum +from ansible_collections.purestorage.fusion.tests.helpers import ( + OperationResultsDict, +) class OperationStatus(str, Enum): @@ -18,7 +21,16 @@ class OperationStatus(str, Enum): class OperationMock: - def __init__(self, id, status, retry_in=1): + def __init__( + self, + id, + status, + result=OperationResultsDict( + {"resource": OperationResultsDict({"id": "fake-id"})} + ), + retry_in=1, + ): self.id = id self.status = status self.retry_in = retry_in + self.result = result diff --git a/ansible_collections/purestorage/fusion/tests/unit/module_utils/test_parsing.py b/ansible_collections/purestorage/fusion/tests/unit/module_utils/test_parsing.py index 7e2a1cc78..230d0ff01 100644 --- a/ansible_collections/purestorage/fusion/tests/unit/module_utils/test_parsing.py +++ b/ansible_collections/purestorage/fusion/tests/unit/module_utils/test_parsing.py @@ -7,13 +7,12 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type +import pytest from ansible_collections.purestorage.fusion.plugins.module_utils.parsing import ( - parse_number_with_metric_suffix, parse_minutes, + parse_number_with_metric_suffix, ) -import pytest - class MockException(Exception): pass @@ -83,16 +82,36 @@ def test_parsing_invalid_number(): def test_parsing_valid_time_period(): module = MockModule() + assert parse_minutes(module, "0") == 0 + assert parse_minutes(module, "00") == 0 + assert parse_minutes(module, "00M") == 0 assert parse_minutes(module, "10") == 10 - assert parse_minutes(module, "2h") == 120 - assert parse_minutes(module, "2H") == 120 + assert parse_minutes(module, "015") == 15 + assert parse_minutes(module, "0023") == 23 + assert parse_minutes(module, "0H10M") == 10 + assert parse_minutes(module, "2h") == 2 * 60 + assert parse_minutes(module, "2H") == 2 * 60 + assert parse_minutes(module, "02h") == 2 * 60 + assert parse_minutes(module, "02H") == 2 * 60 + assert parse_minutes(module, "002h") == 2 * 60 + assert parse_minutes(module, "002H") == 2 * 60 + assert parse_minutes(module, "0D10H10M") == 10 * 60 + 10 assert parse_minutes(module, "14D") == 14 * 24 * 60 + assert parse_minutes(module, "014D") == 14 * 24 * 60 + assert parse_minutes(module, "0000014D") == 14 * 24 * 60 assert parse_minutes(module, "1W") == 7 * 24 * 60 + assert parse_minutes(module, "01W") == 7 * 24 * 60 + assert parse_minutes(module, "01Y0H10M") == 365 * 24 * 60 + 10 assert parse_minutes(module, "12Y") == 12 * 365 * 24 * 60 + assert parse_minutes(module, "012Y") == 12 * 365 * 24 * 60 assert ( parse_minutes(module, "10Y20W30D40H50M") == 10 * 365 * 24 * 60 + 20 * 7 * 24 * 60 + 30 * 24 * 60 + 40 * 60 + 50 ) + assert ( + parse_minutes(module, "010Y20W30D40H50M") + == 10 * 365 * 24 * 60 + 20 * 7 * 24 * 60 + 30 * 24 * 60 + 40 * 60 + 50 + ) assert ( parse_minutes(module, "10Y20W30D40H") == 10 * 365 * 24 * 60 + 20 * 7 * 24 * 60 + 30 * 24 * 60 + 40 * 60 @@ -110,6 +129,10 @@ def test_parsing_valid_time_period(): assert parse_minutes(module, "40H50M") == 40 * 60 + 50 assert parse_minutes(module, "30D50M") == 30 * 24 * 60 + 50 assert parse_minutes(module, "20W40H") == 20 * 7 * 24 * 60 + 40 * 60 + assert ( + parse_minutes(module, "01W000010D10H10M") + == 7 * 24 * 60 + 10 * 24 * 60 + 10 * 60 + 10 + ) def test_parsing_invalid_time_period(): @@ -123,16 +146,8 @@ def test_parsing_invalid_time_period(): with pytest.raises(MockException): assert parse_minutes(module, "1V") with pytest.raises(MockException): - assert parse_minutes(module, "0M") - with pytest.raises(MockException): - assert parse_minutes(module, "0H10M") - with pytest.raises(MockException): - assert parse_minutes(module, "0H10M") + assert parse_minutes(module, "1v") with pytest.raises(MockException): - assert parse_minutes(module, "0D10H10M") + assert parse_minutes(module, "10M2H") with pytest.raises(MockException): - assert parse_minutes(module, "01W10D10H10M") - with pytest.raises(MockException): - assert parse_minutes(module, "01Y0H10M") - with pytest.raises(MockException): - assert parse_minutes(module, "1V") + assert parse_minutes(module, "0H10M01Y") diff --git a/ansible_collections/purestorage/fusion/tests/unit/modules/test_fusion_az.py b/ansible_collections/purestorage/fusion/tests/unit/modules/test_fusion_az.py index a384506d8..ee300638e 100644 --- a/ansible_collections/purestorage/fusion/tests/unit/modules/test_fusion_az.py +++ b/ansible_collections/purestorage/fusion/tests/unit/modules/test_fusion_az.py @@ -81,7 +81,9 @@ class TestCreateAZ: azone, region_name=module_params["region"] ) await_operation_mock.assert_called_once_with(fusion_mock, op) - moduleMock.exit_json.assert_called_once_with(changed=True) + moduleMock.exit_json.assert_called_once_with( + changed=True, id=op.result.resource.id + ) @patch(f"{current_module}.fusion_az.purefusion.AvailabilityZonesApi.__new__") @patch(f"{current_module}.fusion_az.await_operation") @@ -113,7 +115,7 @@ class TestCreateAZ: # Assertions mock_az_api_obj.create_availability_zone.assert_not_called() await_operation_mock.assert_not_called() - moduleMock.exit_json.assert_called_once_with(changed=True) + moduleMock.exit_json.assert_called_once_with(changed=True, id=None) @patch(f"{current_module}.fusion_az.purefusion.AvailabilityZonesApi.__new__") @patch(f"{current_module}.fusion_az.await_operation") @@ -151,7 +153,9 @@ class TestCreateAZ: azone, region_name=module_params["region"] ) await_operation_mock.assert_called_once_with(fusion_mock, op) - moduleMock.exit_json.assert_called_once_with(changed=True) + moduleMock.exit_json.assert_called_once_with( + changed=True, id=op.result.resource.id + ) @patch(f"{current_module}.fusion_az.purefusion.AvailabilityZonesApi.__new__") @patch(f"{current_module}.fusion_az.await_operation") -- cgit v1.2.3