mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-07 06:34:23 -07:00
Move modules and module_utils unit tests to correct place (#81)
* Move modules and module_utils unit tests to correct place. * Update ignore.txt * Fix imports. * Fix typos. * Fix more typos.
This commit is contained in:
parent
ab3c2120fb
commit
be191cce6c
1170 changed files with 732 additions and 751 deletions
29
tests/unit/plugins/modules/packaging/os/conftest.py
Normal file
29
tests/unit/plugins/modules/packaging/os/conftest.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
from ansible_collections.community.general.tests.unit.compat.mock import patch
|
||||
from ansible.module_utils.six.moves import xmlrpc_client
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def get_method_name(request_body):
|
||||
return xmlrpc_client.loads(request_body)[1]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_request(request, mocker):
|
||||
responses = request.getfixturevalue('testcase')['calls']
|
||||
module_name = request.module.TESTED_MODULE
|
||||
|
||||
def transport_request(host, handler, request_body, verbose=0):
|
||||
"""Fake request"""
|
||||
method_name = get_method_name(request_body)
|
||||
excepted_name, response = responses.pop(0)
|
||||
if method_name == excepted_name:
|
||||
if isinstance(response, Exception):
|
||||
raise response
|
||||
else:
|
||||
return response
|
||||
else:
|
||||
raise Exception('Expected call: %r, called with: %r' % (excepted_name, method_name))
|
||||
|
||||
target = '{0}.xmlrpc_client.Transport.request'.format(module_name)
|
||||
mocker.patch(target, side_effect=transport_request)
|
Loading…
Add table
Add a link
Reference in a new issue