def test_should_fail_if_spp_does_not_exist(self):
        msg = "Baseline SPP named 'SPP1' not found in OneView Appliance."
        self.resource.get_by_name.side_effect = [None, None, None]

        self.mock_ansible_module.params = PARAMS_FOR_PRESENT

        FirmwareDriverModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=msg)
    def test_should_do_nothing_when_firmware_driver_not_exist(self):
        self.resource.get_by_name.return_value = None
        self.mock_ansible_module.params = PARAMS_ABSENT

        FirmwareDriverModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=FirmwareDriverModule.MSG_ALREADY_ABSENT
        )
    def test_should_fail_if_hotfix_does_not_exist(self):
        msg = "Hotfix named 'hotfix1' not found in OneView Appliance."
        self.resource.data = {'uri': '/rest/fake'}
        self.resource.get_by_name.side_effect = [None, self.resource, None]

        self.mock_ansible_module.params = PARAMS_FOR_PRESENT

        FirmwareDriverModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=msg)
    def test_should_remove_firmware_driver(self):
        self.resource.data = FIRMWARE_DRIVER
        self.resource.get_by_name.return_value = self.resource
        self.mock_ansible_module.params = PARAMS_ABSENT

        FirmwareDriverModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=FirmwareDriverModule.MSG_DELETED
        )
    def test_should_not_update_when_data_is_equals(self):
        self.resource.data = FIRMWARE_DRIVER_TEMPLATE
        self.resource.get_by_name.return_value = self.resource
        self.mock_ansible_module.params = PARAMS_FOR_PRESENT

        FirmwareDriverModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=FirmwareDriverModule.MSG_ALREADY_PRESENT,
            ansible_facts=dict(firmware_driver=FIRMWARE_DRIVER_TEMPLATE)
        )
    def test_should_fail_when_missing_name_(self):
        fake_data = FIRMWARE_DRIVER_TEMPLATE.copy()
        fake_data.pop('customBaselineName')
        params_missing_name = PARAMS_FOR_PRESENT.copy()
        params_missing_name['data'] = fake_data
        msg = "A 'name' parameter or a 'customBaselineName' field inside the 'data' parameter "
        msg += "is required for this operation."
        self.mock_ansible_module.params = params_missing_name

        FirmwareDriverModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=msg)
    def test_should_create_new_firmware_driver(self):
        self.resource.data = {'uri': '/rest/fake'}
        self.resource.get_by_name.side_effect = [None, self.resource, self.resource, self.resource]
        self.resource.create.return_value = self.resource

        self.mock_ansible_module.params = PARAMS_FOR_PRESENT

        FirmwareDriverModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=FirmwareDriverModule.MSG_CREATED,
            ansible_facts=dict(firmware_driver={'uri': '/rest/fake'})
        )