diff options
Diffstat (limited to 'test/units/galaxy')
-rw-r--r-- | test/units/galaxy/test_api.py | 17 | ||||
-rw-r--r-- | test/units/galaxy/test_collection.py | 38 | ||||
-rw-r--r-- | test/units/galaxy/test_collection_install.py | 21 | ||||
-rw-r--r-- | test/units/galaxy/test_role_install.py | 4 | ||||
-rw-r--r-- | test/units/galaxy/test_role_requirements.py | 4 | ||||
-rw-r--r-- | test/units/galaxy/test_token.py | 4 | ||||
-rw-r--r-- | test/units/galaxy/test_user_agent.py | 3 |
7 files changed, 48 insertions, 43 deletions
diff --git a/test/units/galaxy/test_api.py b/test/units/galaxy/test_api.py index b019f1a..c7ee165 100644 --- a/test/units/galaxy/test_api.py +++ b/test/units/galaxy/test_api.py @@ -2,9 +2,7 @@ # Copyright: (c) 2019, Ansible Project # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -# Make coding more python3-ish -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import json import os @@ -24,8 +22,9 @@ from ansible.errors import AnsibleError from ansible.galaxy import api as galaxy_api from ansible.galaxy.api import CollectionVersionMetadata, GalaxyAPI, GalaxyError from ansible.galaxy.token import BasicAuthToken, GalaxyToken, KeycloakToken +from ansible.module_utils.common.file import S_IRWU_RG_RO from ansible.module_utils.common.text.converters import to_native, to_text -from ansible.module_utils.six.moves.urllib import error as urllib_error +import urllib.error from ansible.utils import context_objects as co from ansible.utils.display import Display @@ -49,7 +48,7 @@ def collection_artifact(tmp_path_factory): b_io = BytesIO(b"\x00\x01\x02\x03") tar_info = tarfile.TarInfo('test') tar_info.size = 4 - tar_info.mode = 0o0644 + tar_info.mode = S_IRWU_RG_RO tfile.addfile(tarinfo=tar_info, fileobj=b_io) yield tar_path @@ -326,8 +325,8 @@ def test_initialise_automation_hub(monkeypatch): def test_initialise_unknown(monkeypatch): mock_open = MagicMock() mock_open.side_effect = [ - urllib_error.HTTPError('https://galaxy.ansible.com/api/', 500, 'msg', {}, StringIO(u'{"msg":"raw error"}')), - urllib_error.HTTPError('https://galaxy.ansible.com/api/api/', 500, 'msg', {}, StringIO(u'{"msg":"raw error"}')), + urllib.error.HTTPError('https://galaxy.ansible.com/api/', 500, 'msg', {}, StringIO(u'{"msg":"raw error"}')), + urllib.error.HTTPError('https://galaxy.ansible.com/api/api/', 500, 'msg', {}, StringIO(u'{"msg":"raw error"}')), ] monkeypatch.setattr(galaxy_api, 'open_url', mock_open) @@ -444,7 +443,7 @@ def test_publish_failure(api_version, collection_url, response, expected, collec expected_url = '%s/api/%s/%s' % (api.api_server, api_version, collection_url) mock_open = MagicMock() - mock_open.side_effect = urllib_error.HTTPError(expected_url, 500, 'msg', {}, + mock_open.side_effect = urllib.error.HTTPError(expected_url, 500, 'msg', {}, StringIO(to_text(json.dumps(response)))) monkeypatch.setattr(galaxy_api, 'open_url', mock_open) @@ -1236,7 +1235,7 @@ def test_cache_flaky_pagination(cache_dir, monkeypatch): side_effect=[ StringIO(to_text(json.dumps(responses[0]))), StringIO(to_text(json.dumps(responses[1]))), - urllib_error.HTTPError(responses[1]['next'], 500, 'Error', {}, StringIO()), + urllib.error.HTTPError(responses[1]['next'], 500, 'Error', {}, StringIO()), StringIO(to_text(json.dumps(responses[3]))), ] ) diff --git a/test/units/galaxy/test_collection.py b/test/units/galaxy/test_collection.py index 991184a..10bc0e5 100644 --- a/test/units/galaxy/test_collection.py +++ b/test/units/galaxy/test_collection.py @@ -2,9 +2,7 @@ # Copyright: (c) 2019, Ansible Project # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -# Make coding more python3-ish -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import json import os @@ -25,7 +23,8 @@ from ansible.cli.galaxy import GalaxyCLI from ansible.errors import AnsibleError from ansible.galaxy import api, collection, token from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text -from ansible.module_utils.six.moves import builtins +from ansible.module_utils.common.file import S_IRWU_RG_RO +import builtins from ansible.utils import context_objects as co from ansible.utils.display import Display from ansible.utils.hashing import secure_hash_s @@ -39,10 +38,17 @@ def reset_cli_args(): co.GlobalCLIArgs._Singleton__instance = None -@pytest.fixture() -def collection_input(tmp_path_factory): - ''' Creates a collection skeleton directory for build tests ''' - test_dir = to_text(tmp_path_factory.mktemp('test-ÅÑŚÌβŁÈ Collections Input')) +@pytest.fixture +def collection_path_suffix(request): + """Return test collection path suffix or the default.""" + return getattr(request, 'param', 'test-ÅÑŚÌβŁÈ Collections Input') + + +@pytest.fixture +def collection_input(tmp_path_factory, collection_path_suffix): + """Create a collection skeleton directory for build tests.""" + test_dir = to_text(tmp_path_factory.mktemp(collection_path_suffix)) + namespace = 'ansible_namespace' collection = 'collection' skeleton = os.path.join(os.path.dirname(os.path.split(__file__)[0]), 'cli', 'test_data', 'collection_skeleton') @@ -73,7 +79,7 @@ def collection_artifact(monkeypatch, tmp_path_factory): b_io = BytesIO(b"\x00\x01\x02\x03") tar_info = tarfile.TarInfo('test') tar_info.size = 4 - tar_info.mode = 0o0644 + tar_info.mode = S_IRWU_RG_RO tfile.addfile(tarinfo=tar_info, fileobj=b_io) return input_file, mock_open @@ -101,14 +107,14 @@ def tmp_tarfile(tmp_path_factory, manifest_info): b_io = BytesIO(data) tar_info = tarfile.TarInfo(filename) tar_info.size = len(data) - tar_info.mode = 0o0644 + tar_info.mode = S_IRWU_RG_RO tfile.addfile(tarinfo=tar_info, fileobj=b_io) b_data = to_bytes(json.dumps(manifest_info, indent=True), errors='surrogate_or_strict') b_io = BytesIO(b_data) tar_info = tarfile.TarInfo('MANIFEST.json') tar_info.size = len(b_data) - tar_info.mode = 0o0644 + tar_info.mode = S_IRWU_RG_RO tfile.addfile(tarinfo=tar_info, fileobj=b_io) sha256_hash = sha256() @@ -467,6 +473,14 @@ def test_build_existing_output_without_force(collection_input): collection.build_collection(to_text(input_dir, errors='surrogate_or_strict'), to_text(output_dir, errors='surrogate_or_strict'), False) +@pytest.mark.parametrize( + 'collection_path_suffix', + ( + 'test-ÅÑŚÌβŁÈ Collections Input 1 with_slash/', + 'test-ÅÑŚÌβŁÈ Collections Input 2 no slash', + ), + indirect=('collection_path_suffix', ), +) def test_build_existing_output_with_force(collection_input): input_dir, output_dir = collection_input @@ -949,7 +963,7 @@ def test_extract_tar_file_outside_dir(tmp_path_factory): b_io = BytesIO(data) tar_info = tarfile.TarInfo(tar_filename) tar_info.size = len(data) - tar_info.mode = 0o0644 + tar_info.mode = S_IRWU_RG_RO tfile.addfile(tarinfo=tar_info, fileobj=b_io) expected = re.escape("Cannot extract tar entry '%s' as it will be placed outside the collection directory" diff --git a/test/units/galaxy/test_collection_install.py b/test/units/galaxy/test_collection_install.py index a61ae40..9398c00 100644 --- a/test/units/galaxy/test_collection_install.py +++ b/test/units/galaxy/test_collection_install.py @@ -2,9 +2,7 @@ # Copyright: (c) 2019, Ansible Project # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -# Make coding more python3-ish -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import copy import json @@ -19,13 +17,14 @@ import yaml from io import BytesIO, StringIO from unittest.mock import MagicMock, patch -import ansible.module_utils.six.moves.urllib.error as urllib_error +import urllib.error from ansible import context from ansible.cli.galaxy import GalaxyCLI from ansible.errors import AnsibleError from ansible.galaxy import collection, api, dependency_resolution from ansible.galaxy.dependency_resolution.dataclasses import Candidate, Requirement +from ansible.module_utils.common.file import S_IRWU_RG_RO, S_IRWXU_RXG_RXO from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text from ansible.module_utils.common.process import get_bin_path from ansible.utils import context_objects as co @@ -347,7 +346,7 @@ def test_build_requirement_from_tar_no_manifest(tmp_path_factory): b_io = BytesIO(json_data) tar_info = tarfile.TarInfo('FILES.json') tar_info.size = len(json_data) - tar_info.mode = 0o0644 + tar_info.mode = S_IRWU_RG_RO tfile.addfile(tarinfo=tar_info, fileobj=b_io) concrete_artifact_cm = collection.concrete_artifact_manager.ConcreteArtifactsManager(test_dir, validate_certs=False) @@ -371,7 +370,7 @@ def test_build_requirement_from_tar_no_files(tmp_path_factory): b_io = BytesIO(json_data) tar_info = tarfile.TarInfo('MANIFEST.json') tar_info.size = len(json_data) - tar_info.mode = 0o0644 + tar_info.mode = S_IRWU_RG_RO tfile.addfile(tarinfo=tar_info, fileobj=b_io) concrete_artifact_cm = collection.concrete_artifact_manager.ConcreteArtifactsManager(test_dir, validate_certs=False) @@ -389,7 +388,7 @@ def test_build_requirement_from_tar_invalid_manifest(tmp_path_factory): b_io = BytesIO(json_data) tar_info = tarfile.TarInfo('MANIFEST.json') tar_info.size = len(json_data) - tar_info.mode = 0o0644 + tar_info.mode = S_IRWU_RG_RO tfile.addfile(tarinfo=tar_info, fileobj=b_io) concrete_artifact_cm = collection.concrete_artifact_manager.ConcreteArtifactsManager(test_dir, validate_certs=False) @@ -551,7 +550,7 @@ def test_build_requirement_from_name_missing(galaxy_server, monkeypatch, tmp_pat def test_build_requirement_from_name_401_unauthorized(galaxy_server, monkeypatch, tmp_path_factory): mock_open = MagicMock() - mock_open.side_effect = api.GalaxyError(urllib_error.HTTPError('https://galaxy.server.com', 401, 'msg', {}, + mock_open.side_effect = api.GalaxyError(urllib.error.HTTPError('https://galaxy.server.com', 401, 'msg', {}, StringIO()), "error") monkeypatch.setattr(galaxy_server, 'get_collection_versions', mock_open) @@ -786,9 +785,9 @@ def test_install_collection(collection_artifact, monkeypatch): assert actual_files == [b'FILES.json', b'MANIFEST.json', b'README.md', b'docs', b'playbooks', b'plugins', b'roles', b'runme.sh'] - assert stat.S_IMODE(os.stat(os.path.join(collection_path, b'plugins')).st_mode) == 0o0755 - assert stat.S_IMODE(os.stat(os.path.join(collection_path, b'README.md')).st_mode) == 0o0644 - assert stat.S_IMODE(os.stat(os.path.join(collection_path, b'runme.sh')).st_mode) == 0o0755 + assert stat.S_IMODE(os.stat(os.path.join(collection_path, b'plugins')).st_mode) == S_IRWXU_RXG_RXO + assert stat.S_IMODE(os.stat(os.path.join(collection_path, b'README.md')).st_mode) == S_IRWU_RG_RO + assert stat.S_IMODE(os.stat(os.path.join(collection_path, b'runme.sh')).st_mode) == S_IRWXU_RXG_RXO assert mock_display.call_count == 2 assert mock_display.mock_calls[0][1][0] == "Installing 'ansible_namespace.collection:0.1.0' to '%s'" \ diff --git a/test/units/galaxy/test_role_install.py b/test/units/galaxy/test_role_install.py index 819ed18..25dff80 100644 --- a/test/units/galaxy/test_role_install.py +++ b/test/units/galaxy/test_role_install.py @@ -2,9 +2,7 @@ # Copyright: (c) 2019, Ansible Project # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -# Make coding more python3-ish -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import json diff --git a/test/units/galaxy/test_role_requirements.py b/test/units/galaxy/test_role_requirements.py index a84bbb5..6b7011a 100644 --- a/test/units/galaxy/test_role_requirements.py +++ b/test/units/galaxy/test_role_requirements.py @@ -2,9 +2,7 @@ # Copyright: (c) 2020, Ansible Project # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -# Make coding more python3-ish -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import pytest diff --git a/test/units/galaxy/test_token.py b/test/units/galaxy/test_token.py index 9fc12d4..a02076e 100644 --- a/test/units/galaxy/test_token.py +++ b/test/units/galaxy/test_token.py @@ -2,9 +2,7 @@ # Copyright: (c) 2019, Ansible Project # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -# Make coding more python3-ish -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import os import pytest diff --git a/test/units/galaxy/test_user_agent.py b/test/units/galaxy/test_user_agent.py index da0103f..f771324 100644 --- a/test/units/galaxy/test_user_agent.py +++ b/test/units/galaxy/test_user_agent.py @@ -2,8 +2,7 @@ # Copyright: (c) 2019, Ansible Project # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import platform |