mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-14 07:55:05 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -9,39 +9,32 @@ from unittest import mock
|
|||
from .hpe_test_utils import OneViewBaseTestCase
|
||||
from .oneview_module_loader import NetworkSetModule
|
||||
|
||||
FAKE_MSG_ERROR = 'Fake message error'
|
||||
FAKE_MSG_ERROR = "Fake message error"
|
||||
|
||||
NETWORK_SET = dict(
|
||||
name='OneViewSDK Test Network Set',
|
||||
networkUris=['/rest/ethernet-networks/aaa-bbb-ccc']
|
||||
)
|
||||
NETWORK_SET = dict(name="OneViewSDK Test Network Set", networkUris=["/rest/ethernet-networks/aaa-bbb-ccc"])
|
||||
|
||||
NETWORK_SET_WITH_NEW_NAME = dict(name='OneViewSDK Test Network Set - Renamed')
|
||||
NETWORK_SET_WITH_NEW_NAME = dict(name="OneViewSDK Test Network Set - Renamed")
|
||||
|
||||
PARAMS_FOR_PRESENT = dict(
|
||||
config='config.json',
|
||||
state='present',
|
||||
data=dict(name=NETWORK_SET['name'],
|
||||
networkUris=['/rest/ethernet-networks/aaa-bbb-ccc'])
|
||||
config="config.json",
|
||||
state="present",
|
||||
data=dict(name=NETWORK_SET["name"], networkUris=["/rest/ethernet-networks/aaa-bbb-ccc"]),
|
||||
)
|
||||
|
||||
PARAMS_WITH_CHANGES = dict(
|
||||
config='config.json',
|
||||
state='present',
|
||||
data=dict(name=NETWORK_SET['name'],
|
||||
newName=f"{NETWORK_SET['name']} - Renamed",
|
||||
networkUris=['/rest/ethernet-networks/aaa-bbb-ccc', 'Name of a Network'])
|
||||
config="config.json",
|
||||
state="present",
|
||||
data=dict(
|
||||
name=NETWORK_SET["name"],
|
||||
newName=f"{NETWORK_SET['name']} - Renamed",
|
||||
networkUris=["/rest/ethernet-networks/aaa-bbb-ccc", "Name of a Network"],
|
||||
),
|
||||
)
|
||||
|
||||
PARAMS_FOR_ABSENT = dict(
|
||||
config='config.json',
|
||||
state='absent',
|
||||
data=dict(name=NETWORK_SET['name'])
|
||||
)
|
||||
PARAMS_FOR_ABSENT = dict(config="config.json", state="absent", data=dict(name=NETWORK_SET["name"]))
|
||||
|
||||
|
||||
class NetworkSetModuleSpec(unittest.TestCase,
|
||||
OneViewBaseTestCase):
|
||||
class NetworkSetModuleSpec(unittest.TestCase, OneViewBaseTestCase):
|
||||
"""
|
||||
OneViewBaseTestCase has common tests for class constructor and main function,
|
||||
also provides the mocks used in this test case.
|
||||
|
|
@ -61,9 +54,7 @@ class NetworkSetModuleSpec(unittest.TestCase,
|
|||
NetworkSetModule().run()
|
||||
|
||||
self.mock_ansible_module.exit_json.assert_called_once_with(
|
||||
changed=True,
|
||||
msg=NetworkSetModule.MSG_CREATED,
|
||||
ansible_facts=dict(network_set=NETWORK_SET)
|
||||
changed=True, msg=NetworkSetModule.MSG_CREATED, ansible_facts=dict(network_set=NETWORK_SET)
|
||||
)
|
||||
|
||||
def test_should_not_update_when_data_is_equals(self):
|
||||
|
|
@ -74,29 +65,25 @@ class NetworkSetModuleSpec(unittest.TestCase,
|
|||
NetworkSetModule().run()
|
||||
|
||||
self.mock_ansible_module.exit_json.assert_called_once_with(
|
||||
changed=False,
|
||||
msg=NetworkSetModule.MSG_ALREADY_PRESENT,
|
||||
ansible_facts=dict(network_set=NETWORK_SET)
|
||||
changed=False, msg=NetworkSetModule.MSG_ALREADY_PRESENT, ansible_facts=dict(network_set=NETWORK_SET)
|
||||
)
|
||||
|
||||
def test_update_when_data_has_modified_attributes(self):
|
||||
data_merged = dict(name=f"{NETWORK_SET['name']} - Renamed",
|
||||
networkUris=['/rest/ethernet-networks/aaa-bbb-ccc',
|
||||
'/rest/ethernet-networks/ddd-eee-fff']
|
||||
)
|
||||
data_merged = dict(
|
||||
name=f"{NETWORK_SET['name']} - Renamed",
|
||||
networkUris=["/rest/ethernet-networks/aaa-bbb-ccc", "/rest/ethernet-networks/ddd-eee-fff"],
|
||||
)
|
||||
|
||||
self.resource.get_by.side_effect = [NETWORK_SET], []
|
||||
self.resource.update.return_value = data_merged
|
||||
self.ethernet_network_client.get_by.return_value = [{'uri': '/rest/ethernet-networks/ddd-eee-fff'}]
|
||||
self.ethernet_network_client.get_by.return_value = [{"uri": "/rest/ethernet-networks/ddd-eee-fff"}]
|
||||
|
||||
self.mock_ansible_module.params = PARAMS_WITH_CHANGES
|
||||
|
||||
NetworkSetModule().run()
|
||||
|
||||
self.mock_ansible_module.exit_json.assert_called_once_with(
|
||||
changed=True,
|
||||
msg=NetworkSetModule.MSG_UPDATED,
|
||||
ansible_facts=dict(network_set=data_merged)
|
||||
changed=True, msg=NetworkSetModule.MSG_UPDATED, ansible_facts=dict(network_set=data_merged)
|
||||
)
|
||||
|
||||
def test_should_raise_exception_when_ethernet_network_not_found(self):
|
||||
|
|
@ -108,8 +95,7 @@ class NetworkSetModuleSpec(unittest.TestCase,
|
|||
NetworkSetModule().run()
|
||||
|
||||
self.mock_ansible_module.fail_json.assert_called_once_with(
|
||||
exception=mock.ANY,
|
||||
msg=f"{NetworkSetModule.MSG_ETHERNET_NETWORK_NOT_FOUND}Name of a Network"
|
||||
exception=mock.ANY, msg=f"{NetworkSetModule.MSG_ETHERNET_NETWORK_NOT_FOUND}Name of a Network"
|
||||
)
|
||||
|
||||
def test_should_remove_network(self):
|
||||
|
|
@ -119,10 +105,7 @@ class NetworkSetModuleSpec(unittest.TestCase,
|
|||
|
||||
NetworkSetModule().run()
|
||||
|
||||
self.mock_ansible_module.exit_json.assert_called_once_with(
|
||||
changed=True,
|
||||
msg=NetworkSetModule.MSG_DELETED
|
||||
)
|
||||
self.mock_ansible_module.exit_json.assert_called_once_with(changed=True, msg=NetworkSetModule.MSG_DELETED)
|
||||
|
||||
def test_should_do_nothing_when_network_set_not_exist(self):
|
||||
self.resource.get_by.return_value = []
|
||||
|
|
@ -132,44 +115,40 @@ class NetworkSetModuleSpec(unittest.TestCase,
|
|||
NetworkSetModule().run()
|
||||
|
||||
self.mock_ansible_module.exit_json.assert_called_once_with(
|
||||
changed=False,
|
||||
msg=NetworkSetModule.MSG_ALREADY_ABSENT
|
||||
changed=False, msg=NetworkSetModule.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 = NETWORK_SET.copy()
|
||||
resource_data['scopeUris'] = ['fake']
|
||||
resource_data['uri'] = 'rest/network-sets/fake'
|
||||
resource_data["scopeUris"] = ["fake"]
|
||||
resource_data["uri"] = "rest/network-sets/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
|
||||
|
||||
NetworkSetModule().run()
|
||||
|
||||
self.resource.patch.assert_called_once_with('rest/network-sets/fake',
|
||||
operation='replace',
|
||||
path='/scopeUris',
|
||||
value=['test'])
|
||||
self.resource.patch.assert_called_once_with(
|
||||
"rest/network-sets/fake", operation="replace", path="/scopeUris", value=["test"]
|
||||
)
|
||||
|
||||
self.mock_ansible_module.exit_json.assert_called_once_with(
|
||||
changed=True,
|
||||
ansible_facts=dict(network_set=patch_return),
|
||||
msg=NetworkSetModule.MSG_UPDATED
|
||||
changed=True, ansible_facts=dict(network_set=patch_return), msg=NetworkSetModule.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 = NETWORK_SET.copy()
|
||||
resource_data['scopeUris'] = ['test']
|
||||
resource_data["scopeUris"] = ["test"]
|
||||
self.resource.get_by.return_value = [resource_data]
|
||||
|
||||
NetworkSetModule().run()
|
||||
|
|
@ -177,11 +156,9 @@ class NetworkSetModuleSpec(unittest.TestCase,
|
|||
self.resource.patch.not_been_called()
|
||||
|
||||
self.mock_ansible_module.exit_json.assert_called_once_with(
|
||||
changed=False,
|
||||
ansible_facts=dict(network_set=resource_data),
|
||||
msg=NetworkSetModule.MSG_ALREADY_PRESENT
|
||||
changed=False, ansible_facts=dict(network_set=resource_data), msg=NetworkSetModule.MSG_ALREADY_PRESENT
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue