summaryrefslogtreecommitdiff
path: root/test/units/galaxy/test_role_install.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/units/galaxy/test_role_install.py')
-rw-r--r--test/units/galaxy/test_role_install.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/test/units/galaxy/test_role_install.py b/test/units/galaxy/test_role_install.py
index 687fcac1..819ed186 100644
--- a/test/units/galaxy/test_role_install.py
+++ b/test/units/galaxy/test_role_install.py
@@ -7,6 +7,7 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
+import json
import os
import functools
import pytest
@@ -16,7 +17,7 @@ from io import StringIO
from ansible import context
from ansible.cli.galaxy import GalaxyCLI
from ansible.galaxy import api, role, Galaxy
-from ansible.module_utils._text import to_text
+from ansible.module_utils.common.text.converters import to_text
from ansible.utils import context_objects as co
@@ -24,7 +25,7 @@ def call_galaxy_cli(args):
orig = co.GlobalCLIArgs._Singleton__instance
co.GlobalCLIArgs._Singleton__instance = None
try:
- GalaxyCLI(args=['ansible-galaxy', 'role'] + args).run()
+ return GalaxyCLI(args=['ansible-galaxy', 'role'] + args).run()
finally:
co.GlobalCLIArgs._Singleton__instance = orig
@@ -120,6 +121,22 @@ def test_role_download_github_no_download_url_for_version(init_mock_temp_file, m
assert mock_role_download_api.mock_calls[0][1][0] == 'https://github.com/test_owner/test_role/archive/0.0.1.tar.gz'
+@pytest.mark.parametrize(
+ 'state,rc',
+ [('SUCCESS', 0), ('FAILED', 1),]
+)
+def test_role_import(state, rc, mocker, galaxy_server, monkeypatch):
+ responses = [
+ {"available_versions": {"v1": "v1/"}},
+ {"results": [{'id': 12345, 'github_user': 'user', 'github_repo': 'role', 'github_reference': None, 'summary_fields': {'role': {'name': 'role'}}}]},
+ {"results": [{'state': 'WAITING', 'id': 12345, 'summary_fields': {'task_messages': []}}]},
+ {"results": [{'state': state, 'id': 12345, 'summary_fields': {'task_messages': []}}]},
+ ]
+ mock_api = mocker.MagicMock(side_effect=[StringIO(json.dumps(rsp)) for rsp in responses])
+ monkeypatch.setattr(api, 'open_url', mock_api)
+ assert call_galaxy_cli(['import', 'user', 'role']) == rc
+
+
def test_role_download_url(init_mock_temp_file, mocker, galaxy_server, mock_role_download_api, monkeypatch):
mock_api = mocker.MagicMock()
mock_api.side_effect = [