Use more unit test utils from community.internal_test_tools (#9918)

* Make conftest's patch_ansible_module use the context manager from .utils.

* Fix test dependencies.

* Use module mock utils from community.internal_test_tools.

* Use DataDictLoader from community.internal_test_tools.

* Use trust util from community.internal_test_tools.
This commit is contained in:
Felix Fontein 2025-03-22 13:12:31 +01:00 committed by GitHub
parent 9286b60182
commit 8ab8010b6d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
94 changed files with 217 additions and 267 deletions

View file

@ -40,6 +40,8 @@ jobs:
coverage: ${{ github.event_name == 'schedule' && 'always' || 'never' }} coverage: ${{ github.event_name == 'schedule' && 'always' || 'never' }}
pull-request-change-detection: 'true' pull-request-change-detection: 'true'
testing-type: sanity testing-type: sanity
pre-test-cmd: >-
git clone --depth=1 --single-branch https://github.com/ansible-collections/community.internal_test_tools.git ../../community/internal_test_tools
units: units:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -156,6 +158,8 @@ jobs:
; ;
git clone --depth=1 --single-branch https://github.com/ansible-collections/community.crypto.git ../../community/crypto git clone --depth=1 --single-branch https://github.com/ansible-collections/community.crypto.git ../../community/crypto
; ;
git clone --depth=1 --single-branch https://github.com/ansible-collections/community.docker.git ../../community/docker
;
git clone --depth=1 --single-branch https://github.com/ansible-collections/community.internal_test_tools.git ../../community/internal_test_tools git clone --depth=1 --single-branch https://github.com/ansible-collections/community.internal_test_tools.git ../../community/internal_test_tools
pull-request-change-detection: 'true' pull-request-change-detection: 'true'
target: ${{ matrix.target }} target: ${{ matrix.target }}

View file

@ -1,103 +0,0 @@
# Copyright (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com>
#
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import os
from ansible.errors import AnsibleParserError
from ansible.parsing.dataloader import DataLoader
from ansible.module_utils.common.text.converters import to_bytes, to_text
class DictDataLoader(DataLoader):
def __init__(self, file_mapping=None):
file_mapping = {} if file_mapping is None else file_mapping
assert isinstance(file_mapping, dict)
super(DictDataLoader, self).__init__()
self._file_mapping = file_mapping
self._build_known_directories()
self._vault_secrets = None
def load_from_file(self, path, cache=True, unsafe=False):
path = to_text(path)
if path in self._file_mapping:
return self.load(self._file_mapping[path], path)
return None
# TODO: the real _get_file_contents returns a bytestring, so we actually convert the
# unicode/text it's created with to utf-8
def _get_file_contents(self, file_name):
path = to_text(file_name)
if path in self._file_mapping:
return (to_bytes(self._file_mapping[path]), False)
else:
raise AnsibleParserError("file not found: %s" % path)
def path_exists(self, path):
path = to_text(path)
return path in self._file_mapping or path in self._known_directories
def is_file(self, path):
path = to_text(path)
return path in self._file_mapping
def is_directory(self, path):
path = to_text(path)
return path in self._known_directories
def list_directory(self, path):
ret = []
path = to_text(path)
for x in (list(self._file_mapping.keys()) + self._known_directories):
if x.startswith(path):
if os.path.dirname(x) == path:
ret.append(os.path.basename(x))
return ret
def is_executable(self, path):
# FIXME: figure out a way to make paths return true for this
return False
def _add_known_directory(self, directory):
if directory not in self._known_directories:
self._known_directories.append(directory)
def _build_known_directories(self):
self._known_directories = []
for path in self._file_mapping:
dirname = os.path.dirname(path)
while dirname not in ('/', ''):
self._add_known_directory(dirname)
dirname = os.path.dirname(dirname)
def push(self, path, content):
rebuild_dirs = False
if path not in self._file_mapping:
rebuild_dirs = True
self._file_mapping[path] = content
if rebuild_dirs:
self._build_known_directories()
def pop(self, path):
if path in self._file_mapping:
del self._file_mapping[path]
self._build_known_directories()
def clear(self):
self._file_mapping = dict()
self._known_directories = []
def get_basedir(self):
return os.getcwd()
def set_vault_secrets(self, vault_secrets):
self._vault_secrets = vault_secrets

View file

@ -13,6 +13,7 @@ import yaml
from ansible.inventory.data import InventoryData from ansible.inventory.data import InventoryData
from ansible.template import Templar from ansible.template import Templar
from ansible_collections.community.general.plugins.inventory.iocage import InventoryModule from ansible_collections.community.general.plugins.inventory.iocage import InventoryModule
from ansible_collections.community.internal_test_tools.tests.unit.utils.trust import make_trusted
@pytest.fixture @pytest.fixture
@ -49,7 +50,7 @@ def load_yml_data(path):
def get_option(option): def get_option(option):
groups = {} groups = {}
groups['test'] = "inventory_hostname.startswith('test')" groups['test'] = make_trusted("inventory_hostname.startswith('test')")
if option == 'groups': if option == 'groups':
return groups return groups

View file

@ -19,9 +19,9 @@ from ansible import constants as C
from ansible.inventory.data import InventoryData from ansible.inventory.data import InventoryData
from ansible.inventory.manager import InventoryManager from ansible.inventory.manager import InventoryManager
from ansible.module_utils.common.text.converters import to_native from ansible.module_utils.common.text.converters import to_native
from ansible_collections.community.internal_test_tools.tests.unit.mock.loader import DictDataLoader
from ansible_collections.community.general.plugins.inventory.opennebula import InventoryModule from ansible_collections.community.general.plugins.inventory.opennebula import InventoryModule
from ansible_collections.community.general.tests.unit.mock.loader import DictDataLoader
from ansible_collections.community.general.tests.unit.mock.path import mock_unfrackpath_noop from ansible_collections.community.general.tests.unit.mock.path import mock_unfrackpath_noop

View file

@ -13,6 +13,7 @@ from ansible_collections.community.internal_test_tools.tests.unit.compat.unittes
from ansible_collections.community.internal_test_tools.tests.unit.compat.mock import ( from ansible_collections.community.internal_test_tools.tests.unit.compat.mock import (
MagicMock, MagicMock,
) )
from ansible_collections.community.internal_test_tools.tests.unit.utils.trust import make_trusted
from ansible.plugins.loader import lookup_loader from ansible.plugins.loader import lookup_loader
@ -30,9 +31,9 @@ class TestLookupModule(TestCase):
self.assertListEqual( self.assertListEqual(
self.lookup.run( self.lookup.run(
[ [
{'a': '[1, 2]'}, {'a': make_trusted('[1, 2]')},
{'b': '[item.a + 3, item.a + 6]'}, {'b': make_trusted('[item.a + 3, item.a + 6]')},
{'c': '[item.a + item.b * 10]'}, {'c': make_trusted('[item.a + item.b * 10]')},
], ],
{}, {},
), ),

View file

@ -8,7 +8,7 @@ __metaclass__ = type
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.mock.loader import DictDataLoader from ansible_collections.community.internal_test_tools.tests.unit.mock.loader import DictDataLoader
from ansible.plugins import AnsiblePlugin from ansible.plugins import AnsiblePlugin
from ansible.template import Templar from ansible.template import Templar

View file

@ -5,44 +5,43 @@
from __future__ import (absolute_import, division, print_function) from __future__ import (absolute_import, division, print_function)
__metaclass__ = type __metaclass__ = type
import contextlib as _contextlib
import json import json
import pytest import pytest
from ansible.module_utils.six import string_types from ansible.module_utils.six import string_types
from ansible.module_utils.common.text.converters import to_bytes
from ansible.module_utils.common._collections_compat import MutableMapping from ansible.module_utils.common._collections_compat import MutableMapping
from ansible_collections.community.general.plugins.module_utils import deps from ansible_collections.community.general.plugins.module_utils import deps
from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import set_module_args as _set_module_args
def fix_ansible_args(args): def _fix_ansible_args(args):
if isinstance(args, string_types): if isinstance(args, string_types):
return args # This should be deprecated!
return json.loads(args)
if isinstance(args, MutableMapping): if isinstance(args, MutableMapping):
if 'ANSIBLE_MODULE_ARGS' not in args:
args = {'ANSIBLE_MODULE_ARGS': args}
if '_ansible_remote_tmp' not in args['ANSIBLE_MODULE_ARGS']:
args['ANSIBLE_MODULE_ARGS']['_ansible_remote_tmp'] = '/tmp'
if '_ansible_keep_remote_files' not in args['ANSIBLE_MODULE_ARGS']:
args['ANSIBLE_MODULE_ARGS']['_ansible_keep_remote_files'] = False
args = json.dumps(args)
return args return args
else:
raise Exception('Malformed data to the patch_ansible_module pytest fixture') raise Exception('Malformed data to the patch_ansible_module pytest fixture')
@pytest.fixture @pytest.fixture
def patch_ansible_module(request, mocker): def patch_ansible_module(request):
if hasattr(request, "param"): args = _fix_ansible_args(request.param)
args = fix_ansible_args(request.param) with _set_module_args(args):
mocker.patch('ansible.module_utils.basic._ANSIBLE_ARGS', to_bytes(args)) yield
else:
@pytest.fixture
def patch_ansible_module_uthelper(request):
@_contextlib.contextmanager
def _patch(args): def _patch(args):
args = fix_ansible_args(args) args = _fix_ansible_args(args)
mocker.patch('ansible.module_utils.basic._ANSIBLE_ARGS', to_bytes(args)) with _set_module_args(args):
yield
return _patch return _patch

View file

@ -9,7 +9,7 @@ import json
import pytest import pytest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules import alerta_customer from ansible_collections.community.general.plugins.modules import alerta_customer
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
class MockedReponse(object): class MockedReponse(object):

View file

@ -10,7 +10,7 @@ import pytest
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.general.tests.unit.compat.mock import Mock, patch from ansible_collections.community.general.tests.unit.compat.mock import Mock, patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import ModuleTestCase, set_module_args
from ansible_collections.community.general.plugins.modules.archive import get_archive, common_path from ansible_collections.community.general.plugins.modules.archive import get_archive, common_path

View file

@ -9,7 +9,7 @@ from ansible_collections.community.general.plugins.module_utils.source_control.b
from ansible_collections.community.general.plugins.modules import bitbucket_access_key from ansible_collections.community.general.plugins.modules import bitbucket_access_key
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleFailJson, AnsibleExitJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleFailJson, AnsibleExitJson, ModuleTestCase, set_module_args
class TestBucketAccessKeyModule(ModuleTestCase): class TestBucketAccessKeyModule(ModuleTestCase):

View file

@ -9,7 +9,7 @@ from ansible_collections.community.general.plugins.module_utils.source_control.b
from ansible_collections.community.general.plugins.modules import bitbucket_pipeline_key_pair from ansible_collections.community.general.plugins.modules import bitbucket_pipeline_key_pair
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleFailJson, AnsibleExitJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleFailJson, AnsibleExitJson, ModuleTestCase, set_module_args
class TestBucketPipelineKeyPairModule(ModuleTestCase): class TestBucketPipelineKeyPairModule(ModuleTestCase):

View file

@ -12,7 +12,7 @@ from ansible_collections.community.general.plugins.modules import bitbucket_pipe
from ansible_collections.community.general.plugins.modules.bitbucket_pipeline_known_host import HAS_PARAMIKO from ansible_collections.community.general.plugins.modules.bitbucket_pipeline_known_host import HAS_PARAMIKO
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args
class TestBucketPipelineKnownHostModule(ModuleTestCase): class TestBucketPipelineKnownHostModule(ModuleTestCase):

View file

@ -9,7 +9,7 @@ from ansible_collections.community.general.plugins.module_utils.source_control.b
from ansible_collections.community.general.plugins.modules import bitbucket_pipeline_variable from ansible_collections.community.general.plugins.modules import bitbucket_pipeline_variable
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleFailJson, AnsibleExitJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleFailJson, AnsibleExitJson, ModuleTestCase, set_module_args
class TestBucketPipelineVariableModule(ModuleTestCase): class TestBucketPipelineVariableModule(ModuleTestCase):

View file

@ -7,7 +7,7 @@ __metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules import bootc_manage from ansible_collections.community.general.plugins.modules import bootc_manage
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
class TestBootcManageModule(ModuleTestCase): class TestBootcManageModule(ModuleTestCase):

View file

@ -8,7 +8,7 @@ __metaclass__ = type
import pytest import pytest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules import campfire from ansible_collections.community.general.plugins.modules import campfire
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
class TestCampfireModule(ModuleTestCase): class TestCampfireModule(ModuleTestCase):

View file

@ -15,7 +15,7 @@ from urllib3.response import HTTPResponse
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible.module_utils.common.text.converters import to_bytes from ansible.module_utils.common.text.converters import to_bytes
from ansible_collections.community.general.plugins.modules import circonus_annotation from ansible_collections.community.general.plugins.modules import circonus_annotation
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
class TestCirconusAnnotation(ModuleTestCase): class TestCirconusAnnotation(ModuleTestCase):

View file

@ -9,7 +9,7 @@ __metaclass__ = type
from ansible_collections.community.general.plugins.modules import datadog_downtime from ansible_collections.community.general.plugins.modules import datadog_downtime
from ansible_collections.community.general.tests.unit.compat.mock import MagicMock, patch from ansible_collections.community.general.tests.unit.compat.mock import MagicMock, patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import ( from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
) )

View file

@ -9,7 +9,7 @@ import json
import pytest import pytest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules import discord from ansible_collections.community.general.plugins.modules import discord
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
class TestDiscordModule(ModuleTestCase): class TestDiscordModule(ModuleTestCase):

View file

@ -9,7 +9,7 @@ __metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch, call from ansible_collections.community.general.tests.unit.compat.mock import patch, call
from ansible_collections.community.general.plugins.modules import dnf_config_manager as dnf_config_manager_module from ansible_collections.community.general.plugins.modules import dnf_config_manager as dnf_config_manager_module
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, \ from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, \
ModuleTestCase, set_module_args ModuleTestCase, set_module_args
# Return value on all-default arguments # Return value on all-default arguments

View file

@ -9,7 +9,7 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
from ansible_collections.community.general.plugins.modules import dnsimple as dnsimple_module from ansible_collections.community.general.plugins.modules import dnsimple as dnsimple_module
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleFailJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleFailJson, ModuleTestCase, set_module_args
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
import pytest import pytest
import sys import sys

View file

@ -9,7 +9,7 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
from ansible_collections.community.general.plugins.modules import dnsimple_info from ansible_collections.community.general.plugins.modules import dnsimple_info
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleFailJson, ModuleTestCase, set_module_args, AnsibleExitJson from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleFailJson, ModuleTestCase, set_module_args, AnsibleExitJson
from httmock import response from httmock import response
from httmock import with_httmock from httmock import with_httmock
from httmock import urlmatch from httmock import urlmatch

View file

@ -9,7 +9,7 @@ import copy
import pytest import pytest
from ansible_collections.community.general.plugins.modules import gem from ansible_collections.community.general.plugins.modules import gem
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
def get_command(run_command): def get_command(run_command):

View file

@ -10,7 +10,7 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type __metaclass__ = type
from ansible_collections.community.general.plugins.modules import icinga2_feature from ansible_collections.community.general.plugins.modules import icinga2_feature
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible.module_utils import basic from ansible.module_utils import basic

View file

@ -8,7 +8,7 @@ __metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import call, patch from ansible_collections.community.general.tests.unit.compat.mock import call, patch
from ansible_collections.community.general.plugins.modules import ipa_getkeytab from ansible_collections.community.general.plugins.modules import ipa_getkeytab
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args
class IPAKeytabModuleTestCase(ModuleTestCase): class IPAKeytabModuleTestCase(ModuleTestCase):

View file

@ -11,7 +11,7 @@ from contextlib import contextmanager
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.tests.unit.compat.mock import call, patch from ansible_collections.community.general.tests.unit.compat.mock import call, patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
from ansible_collections.community.general.plugins.modules import ipa_otpconfig from ansible_collections.community.general.plugins.modules import ipa_otpconfig

View file

@ -11,7 +11,7 @@ from contextlib import contextmanager
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.tests.unit.compat.mock import call, patch from ansible_collections.community.general.tests.unit.compat.mock import call, patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
from ansible_collections.community.general.plugins.modules import ipa_otptoken from ansible_collections.community.general.plugins.modules import ipa_otptoken

View file

@ -11,7 +11,7 @@ from contextlib import contextmanager
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.tests.unit.compat.mock import call, patch from ansible_collections.community.general.tests.unit.compat.mock import call, patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
from ansible_collections.community.general.plugins.modules import ipa_pwpolicy from ansible_collections.community.general.plugins.modules import ipa_pwpolicy

View file

@ -11,7 +11,7 @@ __metaclass__ = type
import os import os
from ansible_collections.community.general.tests.unit.plugins.modules.utils import ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import ModuleTestCase, set_module_args
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.compat.mock import Mock from ansible_collections.community.general.tests.unit.compat.mock import Mock
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule

View file

@ -9,7 +9,13 @@ from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible.module_utils import basic from ansible.module_utils import basic
from ansible_collections.community.general.plugins.modules import jenkins_build from ansible_collections.community.general.plugins.modules import jenkins_build
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, set_module_args, exit_json, fail_json from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
AnsibleExitJson,
AnsibleFailJson,
set_module_args,
exit_json,
fail_json,
)
class jenkins: class jenkins:

View file

@ -9,7 +9,13 @@ from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible.module_utils import basic from ansible.module_utils import basic
from ansible_collections.community.general.plugins.modules import jenkins_build_info from ansible_collections.community.general.plugins.modules import jenkins_build_info
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, set_module_args, exit_json, fail_json from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
AnsibleExitJson,
AnsibleFailJson,
set_module_args,
exit_json,
fail_json,
)
class jenkins: class jenkins:

View file

@ -13,7 +13,13 @@ import pytest
from ansible_collections.community.general.tests.unit.compat.mock import patch, call from ansible_collections.community.general.tests.unit.compat.mock import patch, call
from ansible_collections.community.general.plugins.modules import jenkins_node from ansible_collections.community.general.plugins.modules import jenkins_node
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, set_module_args, exit_json, fail_json from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
AnsibleExitJson,
AnsibleFailJson,
set_module_args,
exit_json,
fail_json,
)
from pytest import fixture, raises, mark, param from pytest import fixture, raises, mark, param

View file

@ -11,7 +11,7 @@ from contextlib import contextmanager
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args
from ansible_collections.community.general.plugins.modules import keycloak_authentication from ansible_collections.community.general.plugins.modules import keycloak_authentication

View file

@ -11,7 +11,7 @@ from contextlib import contextmanager
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args
from ansible_collections.community.general.plugins.modules import keycloak_authentication_required_actions from ansible_collections.community.general.plugins.modules import keycloak_authentication_required_actions

View file

@ -12,7 +12,7 @@ from contextlib import contextmanager
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args
from ansible_collections.community.general.plugins.modules import keycloak_client from ansible_collections.community.general.plugins.modules import keycloak_client

View file

@ -11,7 +11,7 @@ from contextlib import contextmanager
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args
from ansible_collections.community.general.plugins.modules import keycloak_client_rolemapping from ansible_collections.community.general.plugins.modules import keycloak_client_rolemapping

View file

@ -12,7 +12,7 @@ from contextlib import contextmanager
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args
from ansible_collections.community.general.plugins.modules import keycloak_clientscope from ansible_collections.community.general.plugins.modules import keycloak_clientscope

View file

@ -15,7 +15,7 @@ from ansible.module_utils.six import StringIO
from ansible_collections.community.general.plugins.modules import keycloak_realm_key from ansible_collections.community.general.plugins.modules import keycloak_realm_key
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args
from ansible_collections.community.general.plugins.modules import keycloak_component from ansible_collections.community.general.plugins.modules import keycloak_component

View file

@ -11,7 +11,7 @@ from contextlib import contextmanager
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args
from ansible_collections.community.general.plugins.modules import keycloak_identity_provider from ansible_collections.community.general.plugins.modules import keycloak_identity_provider

View file

@ -11,7 +11,7 @@ from contextlib import contextmanager
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args
from ansible_collections.community.general.plugins.modules import keycloak_realm from ansible_collections.community.general.plugins.modules import keycloak_realm

View file

@ -11,7 +11,7 @@ from contextlib import contextmanager
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args
from ansible_collections.community.general.plugins.modules import keycloak_realm_info from ansible_collections.community.general.plugins.modules import keycloak_realm_info

View file

@ -11,7 +11,7 @@ from contextlib import contextmanager
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args
from ansible_collections.community.general.plugins.modules import keycloak_realm_key from ansible_collections.community.general.plugins.modules import keycloak_realm_key

View file

@ -16,7 +16,7 @@ from ansible_collections.community.general.plugins.modules import \
keycloak_realm_keys_metadata_info keycloak_realm_keys_metadata_info
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import ( from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
AnsibleExitJson, ModuleTestCase, set_module_args) AnsibleExitJson, ModuleTestCase, set_module_args)

View file

@ -11,7 +11,7 @@ from contextlib import contextmanager
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args
from ansible_collections.community.general.plugins.modules import keycloak_role from ansible_collections.community.general.plugins.modules import keycloak_role

View file

@ -12,7 +12,7 @@ from contextlib import contextmanager
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args
from ansible_collections.community.general.plugins.modules import keycloak_user from ansible_collections.community.general.plugins.modules import keycloak_user

View file

@ -11,7 +11,7 @@ from contextlib import contextmanager
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args
from ansible_collections.community.general.plugins.modules import keycloak_user_federation from ansible_collections.community.general.plugins.modules import keycloak_user_federation

View file

@ -11,7 +11,7 @@ from contextlib import contextmanager
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args
from ansible_collections.community.general.plugins.modules import keycloak_userprofile from ansible_collections.community.general.plugins.modules import keycloak_userprofile

View file

@ -8,7 +8,7 @@ __metaclass__ = type
import pytest import pytest
from ansible_collections.community.general.plugins.modules import linode from ansible_collections.community.general.plugins.modules import linode
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import set_module_args
from .linode_conftest import api_key, auth # noqa: F401, pylint: disable=unused-import from .linode_conftest import api_key, auth # noqa: F401, pylint: disable=unused-import

View file

@ -22,7 +22,7 @@ from linode_api4 import LinodeClient
from ansible_collections.community.general.plugins.modules import linode_v4 from ansible_collections.community.general.plugins.modules import linode_v4
from ansible_collections.community.general.plugins.module_utils.linode import get_user_agent from ansible_collections.community.general.plugins.module_utils.linode import get_user_agent
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import set_module_args
from ansible_collections.community.general.tests.unit.compat import mock from ansible_collections.community.general.tests.unit.compat import mock
from .linode_conftest import access_token, no_access_token_in_env, default_args, mock_linode # noqa: F401, pylint: disable=unused-import from .linode_conftest import access_token, no_access_token_in_env, default_args, mock_linode # noqa: F401, pylint: disable=unused-import

View file

@ -8,7 +8,7 @@ __metaclass__ = type
from ansible_collections.community.general.plugins.modules import lvg_rename from ansible_collections.community.general.plugins.modules import lvg_rename
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import ( from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
AnsibleFailJson, AnsibleExitJson, ModuleTestCase, set_module_args) AnsibleFailJson, AnsibleExitJson, ModuleTestCase, set_module_args)

View file

@ -7,7 +7,7 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type __metaclass__ = type
import sys import sys
from ansible_collections.community.general.tests.unit.plugins.modules.utils import ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import ModuleTestCase, set_module_args
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.compat.mock import Mock from ansible_collections.community.general.tests.unit.compat.mock import Mock
from ansible_collections.community.general.tests.unit.compat.mock import mock_open from ansible_collections.community.general.tests.unit.compat.mock import mock_open

View file

@ -10,7 +10,7 @@ import pytest
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.plugins.modules import monit from ansible_collections.community.general.plugins.modules import monit
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson
TEST_OUTPUT = """ TEST_OUTPUT = """

View file

@ -11,7 +11,7 @@ __metaclass__ = type
import nomad import nomad
from ansible_collections.community.general.plugins.modules import nomad_token from ansible_collections.community.general.plugins.modules import nomad_token
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
def mock_acl_get_tokens(empty_list=False): def mock_acl_get_tokens(empty_list=False):

View file

@ -8,7 +8,7 @@ __metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import call, patch from ansible_collections.community.general.tests.unit.compat.mock import call, patch
from ansible_collections.community.general.plugins.modules import npm from ansible_collections.community.general.plugins.modules import npm
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, set_module_args
class NPMModuleTestCase(ModuleTestCase): class NPMModuleTestCase(ModuleTestCase):

View file

@ -14,8 +14,8 @@ from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible.module_utils import basic from ansible.module_utils import basic
import ansible_collections.community.general.plugins.modules.ocapi_command as module import ansible_collections.community.general.plugins.modules.ocapi_command as module
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args, exit_json, fail_json from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import set_module_args, exit_json, fail_json
from ansible.module_utils.six.moves.urllib.parse import urljoin from ansible.module_utils.six.moves.urllib.parse import urljoin

View file

@ -10,8 +10,8 @@ from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible.module_utils import basic from ansible.module_utils import basic
import ansible_collections.community.general.plugins.modules.ocapi_info as module import ansible_collections.community.general.plugins.modules.ocapi_info as module
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args, exit_json, fail_json from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import set_module_args, exit_json, fail_json
MOCK_BASE_URI = "mockBaseUri" MOCK_BASE_URI = "mockBaseUri"
MOCK_JOB_NAME_IN_PROGRESS = "MockJobInProgress" MOCK_JOB_NAME_IN_PROGRESS = "MockJobInProgress"

View file

@ -9,7 +9,7 @@ __metaclass__ = type
from ansible.module_utils import basic from ansible.module_utils import basic
from ansible_collections.community.general.tests.unit.compat import mock from ansible_collections.community.general.tests.unit.compat import mock
from ansible_collections.community.general.tests.unit.plugins.modules.utils import ( from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
AnsibleExitJson, AnsibleExitJson,
AnsibleFailJson, AnsibleFailJson,
set_module_args, set_module_args,

View file

@ -10,7 +10,7 @@ from ansible_collections.community.general.plugins.modules import pagerduty_aler
import json import json
import pytest import pytest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
class PagerDutyAlertsTest(unittest.TestCase): class PagerDutyAlertsTest(unittest.TestCase):

View file

@ -9,7 +9,7 @@ import json
import pytest import pytest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules import pagerduty_change from ansible_collections.community.general.plugins.modules import pagerduty_change
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
class TestPagerDutyChangeModule(ModuleTestCase): class TestPagerDutyChangeModule(ModuleTestCase):

View file

@ -9,7 +9,7 @@ from ansible_collections.community.general.tests.unit.compat.mock import patch,
from ansible_collections.community.general.plugins.modules import parted as parted_module from ansible_collections.community.general.plugins.modules import parted as parted_module
from ansible_collections.community.general.plugins.modules.parted import parse_parted_version from ansible_collections.community.general.plugins.modules.parted import parse_parted_version
from ansible_collections.community.general.plugins.modules.parted import parse_partition_info from ansible_collections.community.general.plugins.modules.parted import parse_partition_info
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
# Example of output : parted -s -m /dev/sdb -- unit 'MB' print # Example of output : parted -s -m /dev/sdb -- unit 'MB' print
parted_output1 = """ parted_output1 = """

View file

@ -11,7 +11,7 @@ import json
pytest.importorskip('xmltodict') pytest.importorskip('xmltodict')
from ansible_collections.community.general.tests.unit.plugins.modules.utils import ModuleTestCase, set_module_args, AnsibleFailJson, AnsibleExitJson from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import ModuleTestCase, set_module_args, AnsibleFailJson, AnsibleExitJson
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules import pmem as pmem_module from ansible_collections.community.general.plugins.modules import pmem as pmem_module

View file

@ -19,7 +19,7 @@ from ansible_collections.community.general.tests.unit.plugins.module_utils.net_t
PritunlListOrganizationAfterPostMock, PritunlListOrganizationAfterPostMock,
PritunlPostOrganizationMock, PritunlPostOrganizationMock,
) )
from ansible_collections.community.general.tests.unit.plugins.modules.utils import ( from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
AnsibleExitJson, AnsibleExitJson,
AnsibleFailJson, AnsibleFailJson,
ModuleTestCase, ModuleTestCase,

View file

@ -15,7 +15,7 @@ from ansible_collections.community.general.tests.unit.plugins.module_utils.net_t
PritunlListOrganizationMock, PritunlListOrganizationMock,
PritunlEmptyOrganizationMock, PritunlEmptyOrganizationMock,
) )
from ansible_collections.community.general.tests.unit.plugins.modules.utils import ( from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
AnsibleExitJson, AnsibleExitJson,
AnsibleFailJson, AnsibleFailJson,
ModuleTestCase, ModuleTestCase,

View file

@ -20,7 +20,7 @@ from ansible_collections.community.general.tests.unit.plugins.module_utils.net_t
PritunlPostUserMock, PritunlPostUserMock,
PritunlPutUserMock, PritunlPutUserMock,
) )
from ansible_collections.community.general.tests.unit.plugins.modules.utils import ( from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
AnsibleExitJson, AnsibleExitJson,
AnsibleFailJson, AnsibleFailJson,
ModuleTestCase, ModuleTestCase,

View file

@ -15,7 +15,7 @@ from ansible_collections.community.general.tests.unit.plugins.module_utils.net_t
PritunlListOrganizationMock, PritunlListOrganizationMock,
PritunlListUserMock, PritunlListUserMock,
) )
from ansible_collections.community.general.tests.unit.plugins.modules.utils import ( from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
AnsibleExitJson, AnsibleExitJson,
AnsibleFailJson, AnsibleFailJson,
ModuleTestCase, ModuleTestCase,

View file

@ -7,7 +7,7 @@ from __future__ import (absolute_import, division, print_function)
import \ import \
ansible_collections.community.general.plugins.module_utils.proxmox as proxmox_utils ansible_collections.community.general.plugins.module_utils.proxmox as proxmox_utils
from ansible_collections.community.general.plugins.modules import proxmox_backup from ansible_collections.community.general.plugins.modules import proxmox_backup
from ansible_collections.community.general.tests.unit.plugins.modules.utils import ( from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
AnsibleExitJson, AnsibleFailJson, set_module_args, ModuleTestCase) AnsibleExitJson, AnsibleFailJson, set_module_args, ModuleTestCase)
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch

View file

@ -15,7 +15,7 @@ proxmoxer = pytest.importorskip("proxmoxer")
from ansible_collections.community.general.plugins.modules import proxmox_backup_info from ansible_collections.community.general.plugins.modules import proxmox_backup_info
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import ( from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
AnsibleExitJson, AnsibleExitJson,
AnsibleFailJson, AnsibleFailJson,
ModuleTestCase, ModuleTestCase,

View file

@ -23,7 +23,7 @@ from ansible_collections.community.general.tests.unit.compat.mock import (
patch, patch,
DEFAULT, DEFAULT,
) )
from ansible_collections.community.general.tests.unit.plugins.modules.utils import ( from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
AnsibleExitJson, AnsibleExitJson,
AnsibleFailJson, AnsibleFailJson,
ModuleTestCase, ModuleTestCase,

View file

@ -20,7 +20,7 @@ mandatory_py_version = pytest.mark.skipif(
from ansible_collections.community.general.tests.unit.compat.mock import MagicMock, patch from ansible_collections.community.general.tests.unit.compat.mock import MagicMock, patch
from ansible_collections.community.general.plugins.modules import proxmox_snap from ansible_collections.community.general.plugins.modules import proxmox_snap
import ansible_collections.community.general.plugins.module_utils.proxmox as proxmox_utils import ansible_collections.community.general.plugins.module_utils.proxmox as proxmox_utils
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import set_module_args
def get_resources(type): def get_resources(type):

View file

@ -14,7 +14,7 @@ proxmoxer = pytest.importorskip("proxmoxer")
from ansible_collections.community.general.plugins.modules import proxmox_storage_contents_info from ansible_collections.community.general.plugins.modules import proxmox_storage_contents_info
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import ( from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
AnsibleExitJson, AnsibleExitJson,
AnsibleFailJson, AnsibleFailJson,
ModuleTestCase, ModuleTestCase,

View file

@ -24,7 +24,7 @@ mandatory_py_version = pytest.mark.skipif(
from ansible_collections.community.general.plugins.modules import proxmox_tasks_info from ansible_collections.community.general.plugins.modules import proxmox_tasks_info
import ansible_collections.community.general.plugins.module_utils.proxmox as proxmox_utils import ansible_collections.community.general.plugins.module_utils.proxmox as proxmox_utils
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import set_module_args
NODE = 'node01' NODE = 'node01'
TASK_UPID = 'UPID:iaclab-01-01:000029DD:1599528B:6108F068:srvreload:networking:root@pam:' TASK_UPID = 'UPID:iaclab-01-01:000029DD:1599528B:6108F068:srvreload:networking:root@pam:'

View file

@ -21,7 +21,7 @@ mandatory_py_version = pytest.mark.skipif(
from ansible_collections.community.general.plugins.modules import proxmox_template from ansible_collections.community.general.plugins.modules import proxmox_template
from ansible_collections.community.general.tests.unit.compat.mock import patch, Mock from ansible_collections.community.general.tests.unit.compat.mock import patch, Mock
from ansible_collections.community.general.tests.unit.plugins.modules.utils import ( from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
AnsibleFailJson, AnsibleFailJson,
ModuleTestCase, ModuleTestCase,
set_module_args, set_module_args,

View file

@ -20,7 +20,7 @@ mandatory_py_version = pytest.mark.skipif(
from ansible_collections.community.general.plugins.modules import proxmox_vm_info from ansible_collections.community.general.plugins.modules import proxmox_vm_info
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import ( from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
AnsibleExitJson, AnsibleExitJson,
AnsibleFailJson, AnsibleFailJson,
ModuleTestCase, ModuleTestCase,

View file

@ -13,7 +13,7 @@ import json
from redis import __version__ from redis import __version__
from ansible_collections.community.general.plugins.modules import redis_data from ansible_collections.community.general.plugins.modules import redis_data
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import set_module_args
HAS_REDIS_USERNAME_OPTION = True HAS_REDIS_USERNAME_OPTION = True
if tuple(map(int, __version__.split('.'))) < (3, 4, 0): if tuple(map(int, __version__.split('.'))) < (3, 4, 0):

View file

@ -14,7 +14,7 @@ import redis
from redis import __version__ from redis import __version__
from ansible_collections.community.general.plugins.modules import redis_data_incr from ansible_collections.community.general.plugins.modules import redis_data_incr
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import set_module_args
HAS_REDIS_USERNAME_OPTION = True HAS_REDIS_USERNAME_OPTION = True

View file

@ -14,7 +14,7 @@ from redis import __version__
from ansible_collections.community.general.plugins.modules import ( from ansible_collections.community.general.plugins.modules import (
redis_data_info) redis_data_info)
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import set_module_args
HAS_REDIS_USERNAME_OPTION = True HAS_REDIS_USERNAME_OPTION = True

View file

@ -9,7 +9,7 @@ __metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch, MagicMock from ansible_collections.community.general.tests.unit.compat.mock import patch, MagicMock
from ansible_collections.community.general.plugins.modules import redis_info from ansible_collections.community.general.plugins.modules import redis_info
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
class FakeRedisClient(MagicMock): class FakeRedisClient(MagicMock):

View file

@ -7,7 +7,7 @@ __metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import call, patch from ansible_collections.community.general.tests.unit.compat.mock import call, patch
from ansible_collections.community.general.plugins.modules import rhsm_release from ansible_collections.community.general.plugins.modules import rhsm_release
from ansible_collections.community.general.tests.unit.plugins.modules.utils import ( from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args) AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args)

View file

@ -8,7 +8,7 @@ __metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import call, patch from ansible_collections.community.general.tests.unit.compat.mock import call, patch
from ansible_collections.community.general.plugins.modules import rpm_ostree_pkg from ansible_collections.community.general.plugins.modules import rpm_ostree_pkg
from ansible_collections.community.general.tests.unit.plugins.modules.utils import ( from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args) AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args)

View file

@ -11,7 +11,7 @@ import pytest
from ansible_collections.community.general.plugins.modules import scaleway_compute_private_network from ansible_collections.community.general.plugins.modules import scaleway_compute_private_network
from ansible_collections.community.general.plugins.module_utils.scaleway import Scaleway, Response from ansible_collections.community.general.plugins.module_utils.scaleway import Scaleway, Response
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import set_module_args
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch

View file

@ -12,7 +12,7 @@ import pytest
from ansible_collections.community.general.plugins.modules import scaleway_private_network from ansible_collections.community.general.plugins.modules import scaleway_private_network
from ansible_collections.community.general.plugins.module_utils.scaleway import Scaleway, Response from ansible_collections.community.general.plugins.module_utils.scaleway import Scaleway, Response
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import set_module_args
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch

View file

@ -7,7 +7,7 @@ __metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleFailJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleFailJson, ModuleTestCase, set_module_args
from ansible_collections.community.general.plugins.modules.simpleinit_msb import SimpleinitMSB, build_module from ansible_collections.community.general.plugins.modules.simpleinit_msb import SimpleinitMSB, build_module

View file

@ -9,7 +9,7 @@ import json
import pytest import pytest
from ansible_collections.community.general.tests.unit.compat.mock import Mock, patch from ansible_collections.community.general.tests.unit.compat.mock import Mock, patch
from ansible_collections.community.general.plugins.modules import slack from ansible_collections.community.general.plugins.modules import slack
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
class TestSlackModule(ModuleTestCase): class TestSlackModule(ModuleTestCase):

View file

@ -13,7 +13,7 @@ from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.general.plugins.modules import ( from ansible_collections.community.general.plugins.modules import (
solaris_zone solaris_zone
) )
from ansible_collections.community.general.tests.unit.plugins.modules.utils import ( from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
set_module_args, set_module_args,
) )

View file

@ -7,7 +7,7 @@ __metaclass__ = type
from ansible_collections.community.general.plugins.modules import statsd from ansible_collections.community.general.plugins.modules import statsd
from ansible_collections.community.general.tests.unit.compat.mock import patch, MagicMock from ansible_collections.community.general.tests.unit.compat.mock import patch, MagicMock
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
class FakeStatsD(MagicMock): class FakeStatsD(MagicMock):

View file

@ -7,7 +7,7 @@ __metaclass__ = type
from ansible.module_utils import basic from ansible.module_utils import basic
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args, AnsibleExitJson, AnsibleFailJson, ModuleTestCase from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import set_module_args, AnsibleExitJson, AnsibleFailJson, ModuleTestCase
from ansible_collections.community.general.plugins.modules import sysupgrade from ansible_collections.community.general.plugins.modules import sysupgrade

View file

@ -9,7 +9,7 @@ import json
import pytest import pytest
from ansible_collections.community.general.plugins.modules import terraform from ansible_collections.community.general.plugins.modules import terraform
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import set_module_args
def test_terraform_without_argument(capfd): def test_terraform_without_argument(capfd):

View file

@ -8,7 +8,13 @@ from ansible_collections.community.general.tests.unit.compat import unittest
from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible.module_utils import basic from ansible.module_utils import basic
import ansible_collections.community.general.plugins.modules.ufw as module import ansible_collections.community.general.plugins.modules.ufw as module
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, set_module_args, exit_json, fail_json from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
AnsibleExitJson,
AnsibleFailJson,
set_module_args,
exit_json,
fail_json,
)
# mock ufw messages # mock ufw messages

View file

@ -9,7 +9,7 @@ from ansible_collections.community.general.tests.unit.compat import mock
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible.module_utils import basic from ansible.module_utils import basic
from ansible_collections.community.general.plugins.modules import usb_facts from ansible_collections.community.general.plugins.modules import usb_facts
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, set_module_args, exit_json, fail_json from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, set_module_args, exit_json, fail_json
def get_bin_path(self, arg, required=False): def get_bin_path(self, arg, required=False):

View file

@ -16,8 +16,8 @@ from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible.module_utils import basic from ansible.module_utils import basic
import ansible_collections.community.general.plugins.modules.wdc_redfish_command as module import ansible_collections.community.general.plugins.modules.wdc_redfish_command as module
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args, exit_json, fail_json from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import set_module_args, exit_json, fail_json
MOCK_SUCCESSFUL_HTTP_EMPTY_RESPONSE = { MOCK_SUCCESSFUL_HTTP_EMPTY_RESPONSE = {
"ret": True, "ret": True,

View file

@ -10,8 +10,8 @@ from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible.module_utils import basic from ansible.module_utils import basic
import ansible_collections.community.general.plugins.modules.wdc_redfish_info as module import ansible_collections.community.general.plugins.modules.wdc_redfish_info as module
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args, exit_json, fail_json from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import set_module_args, exit_json, fail_json
MOCK_SUCCESSFUL_RESPONSE_WITH_ACTIONS = { MOCK_SUCCESSFUL_RESPONSE_WITH_ACTIONS = {
"ret": True, "ret": True,

View file

@ -9,8 +9,8 @@ from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.compat import unittest from ansible_collections.community.general.tests.unit.compat import unittest
from ansible.module_utils import basic from ansible.module_utils import basic
import ansible_collections.community.general.plugins.modules.xcc_redfish_command as module import ansible_collections.community.general.plugins.modules.xcc_redfish_command as module
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args, exit_json, fail_json from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import set_module_args, exit_json, fail_json
def get_bin_path(self, arg, required=False): def get_bin_path(self, arg, required=False):

View file

@ -69,7 +69,7 @@ class UTHelper(object):
def set_test_func(self): def set_test_func(self):
@pytest.mark.parametrize('test_case', self.test_cases, ids=[tc.id for tc in self.test_cases]) @pytest.mark.parametrize('test_case', self.test_cases, ids=[tc.id for tc in self.test_cases])
@pytest.mark.usefixtures(*self.fixtures) @pytest.mark.usefixtures(*self.fixtures)
def _test_module(mocker, capfd, patch_ansible_module, test_case): def _test_module(mocker, capfd, patch_ansible_module_uthelper, test_case):
""" """
Run unit tests for each test case in self.test_cases Run unit tests for each test case in self.test_cases
""" """
@ -79,7 +79,7 @@ class UTHelper(object):
args["_ansible_check_mode"] = test_case.flags.get("check") args["_ansible_check_mode"] = test_case.flags.get("check")
if test_case.flags.get("diff"): if test_case.flags.get("diff"):
args["_ansible_diff"] = test_case.flags.get("diff") args["_ansible_diff"] = test_case.flags.get("diff")
patch_ansible_module(args) with patch_ansible_module_uthelper(args):
self.runner.run(mocker, capfd, test_case) self.runner.run(mocker, capfd, test_case)
self.add_func_to_test_module("test_module", _test_module) self.add_func_to_test_module("test_module", _test_module)

View file

@ -11,7 +11,12 @@ __metaclass__ = type
import pytest import pytest
from ansible.utils.unsafe_proxy import AnsibleUnsafe from ansible_collections.community.internal_test_tools.tests.unit.utils.trust import (
make_untrusted as _make_untrusted,
make_trusted as _make_trusted,
is_trusted as _is_trusted,
SUPPORTS_DATA_TAGGING,
)
from ansible_collections.community.general.plugins.plugin_utils.unsafe import ( from ansible_collections.community.general.plugins.plugin_utils.unsafe import (
make_unsafe, make_unsafe,
@ -20,28 +25,14 @@ from ansible_collections.community.general.plugins.plugin_utils.unsafe import (
TEST_MAKE_UNSAFE = [ TEST_MAKE_UNSAFE = [
( (
u'text', _make_trusted(u'text'),
[], [],
[ [
(), (),
], ],
), ),
( (
u'{{text}}', _make_trusted(u'{{text}}'),
[
(),
],
[],
),
(
b'text',
[],
[
(),
],
),
(
b'{{text}}',
[ [
(), (),
], ],
@ -49,14 +40,14 @@ TEST_MAKE_UNSAFE = [
), ),
( (
{ {
'skey': 'value', _make_trusted('skey'): _make_trusted('value'),
'ukey': '{{value}}', _make_trusted('ukey'): _make_trusted('{{value}}'),
1: [ 1: [
'value', _make_trusted('value'),
'{{value}}', _make_trusted('{{value}}'),
{ {
1.0: '{{value}}', 1.0: _make_trusted('{{value}}'),
2.0: 'value', 2.0: _make_trusted('value'),
}, },
], ],
}, },
@ -72,7 +63,7 @@ TEST_MAKE_UNSAFE = [
], ],
), ),
( (
['value', '{{value}}'], [_make_trusted('value'), _make_trusted('{{value}}')],
[ [
(1, ), (1, ),
], ],
@ -82,6 +73,24 @@ TEST_MAKE_UNSAFE = [
), ),
] ]
if not SUPPORTS_DATA_TAGGING:
TEST_MAKE_UNSAFE.extend([
(
_make_trusted(b"text"),
[],
[
(),
],
),
(
_make_trusted(b"{{text}}"),
[
(),
],
[],
),
])
@pytest.mark.parametrize("value, check_unsafe_paths, check_safe_paths", TEST_MAKE_UNSAFE) @pytest.mark.parametrize("value, check_unsafe_paths, check_safe_paths", TEST_MAKE_UNSAFE)
def test_make_unsafe(value, check_unsafe_paths, check_safe_paths): def test_make_unsafe(value, check_unsafe_paths, check_safe_paths):
@ -91,43 +100,59 @@ def test_make_unsafe(value, check_unsafe_paths, check_safe_paths):
obj = unsafe_value obj = unsafe_value
for elt in check_path: for elt in check_path:
obj = obj[elt] obj = obj[elt]
assert isinstance(obj, AnsibleUnsafe) assert not _is_trusted(obj)
for check_path in check_safe_paths: for check_path in check_safe_paths:
obj = unsafe_value obj = unsafe_value
for elt in check_path: for elt in check_path:
obj = obj[elt] obj = obj[elt]
assert not isinstance(obj, AnsibleUnsafe) assert _is_trusted(obj)
def test_make_unsafe_idempotence():
assert make_unsafe(None) is None
unsafe_str = _make_untrusted('{{test}}')
assert id(make_unsafe(unsafe_str)) == id(unsafe_str)
safe_str = _make_trusted('{{test}}')
assert id(make_unsafe(safe_str)) != id(safe_str)
def test_make_unsafe_dict_key(): def test_make_unsafe_dict_key():
value = { value = {
b'test': 1, _make_trusted(u'test'): 2,
u'test': 2,
} }
if not SUPPORTS_DATA_TAGGING:
value[_make_trusted(b"test")] = 1
unsafe_value = make_unsafe(value) unsafe_value = make_unsafe(value)
assert unsafe_value == value assert unsafe_value == value
for obj in unsafe_value: for obj in unsafe_value:
assert not isinstance(obj, AnsibleUnsafe) assert _is_trusted(obj)
value = { value = {
b'{{test}}': 1, _make_trusted(u'{{test}}'): 2,
u'{{test}}': 2,
} }
if not SUPPORTS_DATA_TAGGING:
value[_make_trusted(b"{{test}}")] = 1
unsafe_value = make_unsafe(value) unsafe_value = make_unsafe(value)
assert unsafe_value == value assert unsafe_value == value
for obj in unsafe_value: for obj in unsafe_value:
assert isinstance(obj, AnsibleUnsafe) assert not _is_trusted(obj)
def test_make_unsafe_set(): def test_make_unsafe_set():
value = set([b'test', u'test']) value = set([_make_trusted(u'test')])
if not SUPPORTS_DATA_TAGGING:
value.add(_make_trusted(b"test"))
unsafe_value = make_unsafe(value) unsafe_value = make_unsafe(value)
assert unsafe_value == value assert unsafe_value == value
for obj in unsafe_value: for obj in unsafe_value:
assert not isinstance(obj, AnsibleUnsafe) assert _is_trusted(obj)
value = set([b'{{test}}', u'{{test}}']) value = set([_make_trusted(u'{{test}}')])
if not SUPPORTS_DATA_TAGGING:
value.add(_make_trusted(b"{{test}}"))
unsafe_value = make_unsafe(value) unsafe_value = make_unsafe(value)
assert unsafe_value == value assert unsafe_value == value
for obj in unsafe_value: for obj in unsafe_value:
assert isinstance(obj, AnsibleUnsafe) assert not _is_trusted(obj)

View file

@ -72,24 +72,23 @@ if [ "${test}" == "sanity/extra" ]; then
fi fi
# START: HACK install dependencies # START: HACK install dependencies
if [ "${script}" != "sanity" ] || [ "${test}" == "sanity/extra" ]; then
# Nothing further should be added to this list. # Nothing further should be added to this list.
# This is to prevent modules or plugins in this collection having a runtime dependency on other collections. # This is to prevent modules or plugins in this collection having a runtime dependency on other collections.
retry git clone --depth=1 --single-branch https://github.com/ansible-collections/community.internal_test_tools.git "${ANSIBLE_COLLECTIONS_PATHS}/ansible_collections/community/internal_test_tools" retry git clone --depth=1 --single-branch https://github.com/ansible-collections/community.internal_test_tools.git "${ANSIBLE_COLLECTIONS_PATHS}/ansible_collections/community/internal_test_tools"
retry git clone --depth=1 --single-branch https://github.com/ansible-collections/community.docker.git "${ANSIBLE_COLLECTIONS_PATHS}/ansible_collections/community/docker"
# NOTE: we're installing with git to work around Galaxy being a huge PITA (https://github.com/ansible/galaxy/issues/2429) # NOTE: we're installing with git to work around Galaxy being a huge PITA (https://github.com/ansible/galaxy/issues/2429)
# retry ansible-galaxy -vvv collection install community.internal_test_tools # retry ansible-galaxy -vvv collection install community.internal_test_tools
fi
if [ "${script}" != "sanity" ] && [ "${script}" != "units" ] && [ "${test}" != "sanity/extra" ]; then if [ "${script}" != "sanity" ] && [ "${script}" != "units" ] && [ "${test}" != "sanity/extra" ]; then
# To prevent Python dependencies on other collections only install other collections for integration tests # To prevent Python dependencies on other collections only install other collections for integration tests
retry git clone --depth=1 --single-branch https://github.com/ansible-collections/ansible.posix.git "${ANSIBLE_COLLECTIONS_PATHS}/ansible_collections/ansible/posix" retry git clone --depth=1 --single-branch https://github.com/ansible-collections/ansible.posix.git "${ANSIBLE_COLLECTIONS_PATHS}/ansible_collections/ansible/posix"
retry git clone --depth=1 --single-branch https://github.com/ansible-collections/community.crypto.git "${ANSIBLE_COLLECTIONS_PATHS}/ansible_collections/community/crypto" retry git clone --depth=1 --single-branch https://github.com/ansible-collections/community.crypto.git "${ANSIBLE_COLLECTIONS_PATHS}/ansible_collections/community/crypto"
retry git clone --depth=1 --single-branch https://github.com/ansible-collections/community.docker.git "${ANSIBLE_COLLECTIONS_PATHS}/ansible_collections/community/docker"
# NOTE: we're installing with git to work around Galaxy being a huge PITA (https://github.com/ansible/galaxy/issues/2429) # NOTE: we're installing with git to work around Galaxy being a huge PITA (https://github.com/ansible/galaxy/issues/2429)
# retry ansible-galaxy -vvv collection install ansible.posix # retry ansible-galaxy -vvv collection install ansible.posix
# retry ansible-galaxy -vvv collection install community.crypto # retry ansible-galaxy -vvv collection install community.crypto
# retry ansible-galaxy -vvv collection install community.docker
fi fi
# END: HACK # END: HACK
export PYTHONIOENCODING='utf-8' export PYTHONIOENCODING='utf-8'