mirror of
https://github.com/ansible/awx.git
synced 2026-05-20 07:17:40 -02:30
Make tower_inventory_source org optional, add tests
This commit is contained in:
@@ -4,6 +4,7 @@ import datetime
|
||||
import importlib
|
||||
from contextlib import redirect_stdout
|
||||
from unittest import mock
|
||||
import logging
|
||||
|
||||
from requests.models import Response
|
||||
|
||||
@@ -13,6 +14,9 @@ from awx.main.tests.functional.conftest import _request
|
||||
from awx.main.models import Organization, Project, Inventory, Credential, CredentialType
|
||||
|
||||
|
||||
logger = logging.getLogger('awx.main.tests')
|
||||
|
||||
|
||||
def sanitize_dict(din):
|
||||
'''Sanitize Django response data to purge it of internal types
|
||||
so it may be used to cast a requests response object
|
||||
@@ -34,13 +38,22 @@ def sanitize_dict(din):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def run_module():
|
||||
def run_module(request):
|
||||
def rf(module_name, module_params, request_user):
|
||||
|
||||
def new_request(self, method, url, **kwargs):
|
||||
kwargs_copy = kwargs.copy()
|
||||
if 'data' in kwargs:
|
||||
kwargs_copy['data'] = json.loads(kwargs['data'])
|
||||
if 'params' in kwargs and method == 'GET':
|
||||
# query params for GET are handled a bit differently by
|
||||
# tower-cli and python requests as opposed to REST framework APIRequestFactory
|
||||
kwargs_copy.setdefault('data', {})
|
||||
if isinstance(kwargs['params'], dict):
|
||||
kwargs_copy['data'].update(kwargs['params'])
|
||||
elif isinstance(kwargs['params'], list):
|
||||
for k, v in kwargs['params']:
|
||||
kwargs_copy['data'][k] = v
|
||||
|
||||
# make request
|
||||
rf = _request(method.lower())
|
||||
@@ -53,6 +66,13 @@ def run_module():
|
||||
sanitize_dict(py_data)
|
||||
resp._content = bytes(json.dumps(django_response.data), encoding='utf8')
|
||||
resp.status_code = django_response.status_code
|
||||
|
||||
if request.config.getoption('verbose') > 0:
|
||||
logger.info('{} {} by {}, code:{}'.format(
|
||||
method, '/api/' + url.split('/api/')[1],
|
||||
request_user.username, resp.status_code
|
||||
))
|
||||
|
||||
return resp
|
||||
|
||||
stdout_buffer = io.StringIO()
|
||||
|
||||
Reference in New Issue
Block a user