def test_should_get_all(self):
        self.san_managers.get_all.return_value = self.PRESENT_SAN_MANAGERS
        self.mock_ansible_module.params = self.PARAMS_GET_ALL

        SanManagerFactsModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(san_managers=(self.PRESENT_SAN_MANAGERS)))
    def test_should_get_by_display_name(self):
        self.san_managers.get_by_provider_display_name.return_value = self.PRESENT_SAN_MANAGERS[
            0]
        self.mock_ansible_module.params = self.PARAMS_GET_BY_PROVIDER_DISPLAY_NAME

        SanManagerFactsModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(san_managers=(self.PRESENT_SAN_MANAGERS)))
    def test_should_load_config_from_file(self, mock_ansible_module,
                                          mock_ov_client_from_env_vars,
                                          mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_client_from_json_file.return_value = mock_ov_instance
        mock_ansible_instance = create_ansible_mock({'config': 'config.json'})
        mock_ansible_module.return_value = mock_ansible_instance

        SanManagerFactsModule()

        mock_ov_client_from_json_file.assert_called_once_with('config.json')
        mock_ov_client_from_env_vars.not_been_called()
    def test_should_fail_when_get_all_raises_exception(
            self, mock_ansible_module, mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.san_managers.get_all.side_effect = Exception(
            ERROR_MSG)

        mock_ov_client_from_json_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(PARAMS_GET_ALL)
        mock_ansible_module.return_value = mock_ansible_instance

        SanManagerFactsModule().run()

        mock_ansible_instance.fail_json.assert_called_once()
    def test_should_get_all(self, mock_ansible_module,
                            mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.san_managers.get_all.return_value = PRESENT_SAN_MANAGERS

        mock_ov_client_from_json_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(PARAMS_GET_ALL)
        mock_ansible_module.return_value = mock_ansible_instance

        SanManagerFactsModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(san_managers=(PRESENT_SAN_MANAGERS)))
    def test_should_fail_when_get_by_provider_display_name_raises_exception(
            self, mock_ansible_module, mock_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.san_managers.get_by_provider_display_name.side_effect = Exception(
            ERROR_MSG)

        mock_from_json_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(
            PARAMS_GET_BY_PROVIDER_DISPLAY_NAME)
        mock_ansible_module.return_value = mock_ansible_instance

        SanManagerFactsModule().run()

        mock_ansible_instance.fail_json.assert_called_once()
    def test_should_get_by_display_name(self, mock_ansible_module,
                                        mock_ov_client_from_json_file):
        mock_ov_instance = mock.Mock()
        mock_ov_instance.san_managers.get_by_provider_display_name.return_value = PRESENT_SAN_MANAGERS[
            0]

        mock_ov_client_from_json_file.return_value = mock_ov_instance

        mock_ansible_instance = create_ansible_mock(
            PARAMS_GET_BY_PROVIDER_DISPLAY_NAME)
        mock_ansible_module.return_value = mock_ansible_instance

        SanManagerFactsModule().run()

        mock_ansible_instance.exit_json.assert_called_once_with(
            changed=False,
            ansible_facts=dict(san_managers=(PRESENT_SAN_MANAGERS)))