def test_should_fail_with_missing_required_attributes(self): self.mock_ansible_module.params = PARAMS_FOR_INVALID ApplianceDeviceSnmpV1TrapDestinationsModule().run() self.mock_ansible_module.fail_json.assert_called_once_with( exception=mock.ANY, msg=ApplianceDeviceSnmpV1TrapDestinationsModule.MSG_VALUE_ERROR)
def test_should_do_nothing_when_snmp_v1_trap_destination_not_exist(self): self.resource.get_all.return_value = [] self.mock_ansible_module.params = PARAMS_FOR_ABSENT ApplianceDeviceSnmpV1TrapDestinationsModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=ApplianceDeviceSnmpV1TrapDestinationsModule.MSG_ALREADY_ABSENT)
def test_should_remove_snmp_v1_trap_destination_by_uri(self): self.resource.get_by.return_value = [DEFAULT_SNMPv1_TRAP_TEMPLATE] self.mock_ansible_module.params = PARAMS_FOR_ABSENT_WITH_URI ApplianceDeviceSnmpV1TrapDestinationsModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=ApplianceDeviceSnmpV1TrapDestinationsModule.MSG_DELETED)
def test_should_get_the_same_resource_by_uri(self): self.resource.get_by.return_value = [DEFAULT_SNMPv1_TRAP_TEMPLATE] self.mock_ansible_module.params = PARAMS_FOR_PRESENT_WITH_URI ApplianceDeviceSnmpV1TrapDestinationsModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=ApplianceDeviceSnmpV1TrapDestinationsModule. MSG_ALREADY_PRESENT, ansible_facts=dict(appliance_device_snmp_v1_trap_destinations=( DEFAULT_SNMPv1_TRAP_TEMPLATE)))
def test_should_create_new_snmp_v1_trap_destination(self): self.resource.get_all.return_value = [] self.resource.create.return_value = DEFAULT_SNMPv1_TRAP_TEMPLATE self.mock_ansible_module.params = PARAMS_FOR_PRESENT ApplianceDeviceSnmpV1TrapDestinationsModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=ApplianceDeviceSnmpV1TrapDestinationsModule.MSG_CREATED, ansible_facts=dict(appliance_device_snmp_v1_trap_destinations= DEFAULT_SNMPv1_TRAP_TEMPLATE))
def test_should_not_update_when_data_is_equals(self): self.resource.data = DEFAULT_SNMPv1_TRAP_TEMPLATE self.resource.get_by_name.return_value = self.resource self.resource.get_by_uri.return_value = self.resource self.mock_ansible_module.params = PARAMS_FOR_PRESENT ApplianceDeviceSnmpV1TrapDestinationsModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=ApplianceDeviceSnmpV1TrapDestinationsModule.MSG_ALREADY_PRESENT, ansible_facts=dict(appliance_device_snmp_v1_trap_destinations=DEFAULT_SNMPv1_TRAP_TEMPLATE) )
def test_update_when_data_has_modified_attributes(self): self.resource.data = DEFAULT_SNMPv1_TRAP_TEMPLATE data_merged = DEFAULT_SNMPv1_TRAP_TEMPLATE.copy() self.resource.get_by_name.return_value = self.resource self.resource.update.return_value = self.resource self.mock_ansible_module.params = PARAMS_WITH_CHANGES ApplianceDeviceSnmpV1TrapDestinationsModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=ApplianceDeviceSnmpV1TrapDestinationsModule.MSG_UPDATED, ansible_facts=dict(appliance_device_snmp_v1_trap_destinations=data_merged) )