1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-16 08:53:15 +00:00

Reformat everything.

This commit is contained in:
Felix Fontein 2025-11-01 12:08:41 +01:00
parent 3f2213791a
commit 340ff8586d
1008 changed files with 61301 additions and 58309 deletions

View file

@ -9,37 +9,22 @@ import unittest
from .oneview_module_loader import FcoeNetworkModule
from .hpe_test_utils import OneViewBaseTestCase
FAKE_MSG_ERROR = 'Fake message error'
FAKE_MSG_ERROR = "Fake message error"
DEFAULT_FCOE_NETWORK_TEMPLATE = dict(
name='New FCoE Network 2',
vlanId="201",
connectionTemplateUri=None
)
DEFAULT_FCOE_NETWORK_TEMPLATE = dict(name="New FCoE Network 2", vlanId="201", connectionTemplateUri=None)
PARAMS_FOR_PRESENT = dict(
config='config.json',
state='present',
data=dict(name=DEFAULT_FCOE_NETWORK_TEMPLATE['name'])
)
PARAMS_FOR_PRESENT = dict(config="config.json", state="present", data=dict(name=DEFAULT_FCOE_NETWORK_TEMPLATE["name"]))
PARAMS_WITH_CHANGES = dict(
config='config.json',
state='present',
data=dict(name=DEFAULT_FCOE_NETWORK_TEMPLATE['name'],
fabricType='DirectAttach',
newName='New Name')
config="config.json",
state="present",
data=dict(name=DEFAULT_FCOE_NETWORK_TEMPLATE["name"], fabricType="DirectAttach", newName="New Name"),
)
PARAMS_FOR_ABSENT = dict(
config='config.json',
state='absent',
data=dict(name=DEFAULT_FCOE_NETWORK_TEMPLATE['name'])
)
PARAMS_FOR_ABSENT = dict(config="config.json", state="absent", data=dict(name=DEFAULT_FCOE_NETWORK_TEMPLATE["name"]))
class FcoeNetworkSpec(unittest.TestCase,
OneViewBaseTestCase):
class FcoeNetworkSpec(unittest.TestCase, OneViewBaseTestCase):
"""
OneViewBaseTestCase provides the mocks used in this test case
"""
@ -59,7 +44,7 @@ class FcoeNetworkSpec(unittest.TestCase,
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
msg=FcoeNetworkModule.MSG_CREATED,
ansible_facts=dict(fcoe_network=DEFAULT_FCOE_NETWORK_TEMPLATE)
ansible_facts=dict(fcoe_network=DEFAULT_FCOE_NETWORK_TEMPLATE),
)
def test_should_not_update_when_data_is_equals(self):
@ -71,12 +56,12 @@ class FcoeNetworkSpec(unittest.TestCase,
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=False,
msg=FcoeNetworkModule.MSG_ALREADY_PRESENT,
ansible_facts=dict(fcoe_network=DEFAULT_FCOE_NETWORK_TEMPLATE)
ansible_facts=dict(fcoe_network=DEFAULT_FCOE_NETWORK_TEMPLATE),
)
def test_update_when_data_has_modified_attributes(self):
data_merged = DEFAULT_FCOE_NETWORK_TEMPLATE.copy()
data_merged['fabricType'] = 'DirectAttach'
data_merged["fabricType"] = "DirectAttach"
self.resource.get_by.return_value = [DEFAULT_FCOE_NETWORK_TEMPLATE]
self.resource.update.return_value = data_merged
@ -86,9 +71,7 @@ class FcoeNetworkSpec(unittest.TestCase,
FcoeNetworkModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
msg=FcoeNetworkModule.MSG_UPDATED,
ansible_facts=dict(fcoe_network=data_merged)
changed=True, msg=FcoeNetworkModule.MSG_UPDATED, ansible_facts=dict(fcoe_network=data_merged)
)
def test_should_remove_fcoe_network(self):
@ -98,10 +81,7 @@ class FcoeNetworkSpec(unittest.TestCase,
FcoeNetworkModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
msg=FcoeNetworkModule.MSG_DELETED
)
self.mock_ansible_module.exit_json.assert_called_once_with(changed=True, msg=FcoeNetworkModule.MSG_DELETED)
def test_should_do_nothing_when_fcoe_network_not_exist(self):
self.resource.get_by.return_value = []
@ -111,44 +91,40 @@ class FcoeNetworkSpec(unittest.TestCase,
FcoeNetworkModule().run()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=False,
msg=FcoeNetworkModule.MSG_ALREADY_ABSENT
changed=False, msg=FcoeNetworkModule.MSG_ALREADY_ABSENT
)
def test_update_scopes_when_different(self):
params_to_scope = PARAMS_FOR_PRESENT.copy()
params_to_scope['data']['scopeUris'] = ['test']
params_to_scope["data"]["scopeUris"] = ["test"]
self.mock_ansible_module.params = params_to_scope
resource_data = DEFAULT_FCOE_NETWORK_TEMPLATE.copy()
resource_data['scopeUris'] = ['fake']
resource_data['uri'] = 'rest/fcoe/fake'
resource_data["scopeUris"] = ["fake"]
resource_data["uri"] = "rest/fcoe/fake"
self.resource.get_by.return_value = [resource_data]
patch_return = resource_data.copy()
patch_return['scopeUris'] = ['test']
patch_return["scopeUris"] = ["test"]
self.resource.patch.return_value = patch_return
FcoeNetworkModule().run()
self.resource.patch.assert_called_once_with('rest/fcoe/fake',
operation='replace',
path='/scopeUris',
value=['test'])
self.resource.patch.assert_called_once_with(
"rest/fcoe/fake", operation="replace", path="/scopeUris", value=["test"]
)
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=True,
ansible_facts=dict(fcoe_network=patch_return),
msg=FcoeNetworkModule.MSG_UPDATED
changed=True, ansible_facts=dict(fcoe_network=patch_return), msg=FcoeNetworkModule.MSG_UPDATED
)
def test_should_do_nothing_when_scopes_are_the_same(self):
params_to_scope = PARAMS_FOR_PRESENT.copy()
params_to_scope['data']['scopeUris'] = ['test']
params_to_scope["data"]["scopeUris"] = ["test"]
self.mock_ansible_module.params = params_to_scope
resource_data = DEFAULT_FCOE_NETWORK_TEMPLATE.copy()
resource_data['scopeUris'] = ['test']
resource_data["scopeUris"] = ["test"]
self.resource.get_by.return_value = [resource_data]
FcoeNetworkModule().run()
@ -156,11 +132,9 @@ class FcoeNetworkSpec(unittest.TestCase,
self.resource.patch.not_been_called()
self.mock_ansible_module.exit_json.assert_called_once_with(
changed=False,
ansible_facts=dict(fcoe_network=resource_data),
msg=FcoeNetworkModule.MSG_ALREADY_PRESENT
changed=False, ansible_facts=dict(fcoe_network=resource_data), msg=FcoeNetworkModule.MSG_ALREADY_PRESENT
)
if __name__ == '__main__':
if __name__ == "__main__":
unittest.main()