def test_update_scopes_when_different(self): params_to_scope = PARAMS_FOR_PRESENT.copy() params_to_scope['data']['scopeUris'] = ['test'] self.mock_ansible_module.params = params_to_scope resource_data = SWITCH.copy() resource_data['scopeUris'] = ['fake'] resource_data['uri'] = 'rest/switches/fake' self.resource.get_by.return_value = [resource_data] patch_return = resource_data.copy() patch_return['scopeUris'] = ['test'] self.resource.patch.return_value = patch_return SwitchModule().run() self.resource.patch.assert_called_once_with('rest/switches/fake', operation='replace', path='/scopeUris', value=['test']) self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, ansible_facts=dict(switch=patch_return), msg=SwitchModule.MSG_UPDATED )
def test_should_fail_when_switch_not_found_on_update_ports(self): self.resource.get_by.return_value = [] self.mock_ansible_module.params = PARAMS_PORTS_UPDATED SwitchModule().run() self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=SwitchModule.MSG_NOT_FOUND)
def test_should_do_nothing_when_switch_not_exist(self): self.resource.get_by.return_value = [] self.mock_ansible_module.params = PARAMS_FOR_ABSENT SwitchModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=SwitchModule.MSG_ALREADY_ABSENT)
def test_should_remove_switch(self): self.resource.get_by.return_value = [SWITCH] self.mock_ansible_module.params = PARAMS_FOR_ABSENT SwitchModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=SwitchModule.MSG_DELETED)
def test_should_update_switch_ports(self): self.resource.get_by.return_value = [SWITCH] self.mock_ansible_module.params = PARAMS_PORTS_UPDATED SwitchModule().run() self.resource.update_ports.assert_called_once_with( id_or_uri=SWITCH["uri"], ports=PARAMS_PORTS_UPDATED["data"]['ports']) self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=SwitchModule.MSG_PORTS_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'] self.mock_ansible_module.params = params_to_scope resource_data = SWITCH.copy() resource_data['scopeUris'] = ['test'] self.resource.get_by.return_value = [resource_data] SwitchModule().run() self.resource.patch.not_been_called() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, ansible_facts=dict(switch=resource_data), msg=SwitchModule.MSG_ALREADY_PRESENT)