-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add common unit test module and 'dhcp_relay' resource module unit tes…
…ts (#148)
- Loading branch information
1 parent
011dcc7
commit a8914ec
Showing
12 changed files
with
924 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
""" | ||
Compatibility shim for mock imports in modules and module_utils. | ||
This can be removed once support for Python 2.7 is dropped. | ||
""" | ||
from __future__ import (absolute_import, division, print_function) | ||
__metaclass__ = type | ||
|
||
try: | ||
from unittest.mock import ( | ||
call, | ||
patch, | ||
mock_open, | ||
MagicMock, | ||
Mock, | ||
) | ||
except ImportError: | ||
from mock import ( | ||
call, | ||
patch, | ||
mock_open, | ||
MagicMock, | ||
Mock, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# (c) 2014, Toshio Kuratomi <[email protected]> | ||
# | ||
# This file is part of Ansible | ||
# | ||
# Ansible is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Ansible is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
# Make coding more python3-ish | ||
from __future__ import (absolute_import, division, print_function) | ||
__metaclass__ = type | ||
|
||
# Allow wildcard import because we really do want to import all of | ||
# unittests's symbols into this compat shim | ||
# pylint: disable=wildcard-import,unused-wildcard-import | ||
from unittest import * | ||
|
||
if not hasattr(TestCase, 'assertRaisesRegex'): | ||
# added in Python 3.2 | ||
TestCase.assertRaisesRegex = TestCase.assertRaisesRegexp |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright (c) 2017 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 | ||
|
||
import json | ||
|
||
import pytest | ||
|
||
from ansible.module_utils.six import string_types | ||
from ansible.module_utils._text import to_bytes | ||
from ansible.module_utils.common._collections_compat import MutableMapping | ||
|
||
|
||
@pytest.fixture | ||
def patch_ansible_module(request, mocker): | ||
if isinstance(request.param, string_types): | ||
args = request.param | ||
elif isinstance(request.param, MutableMapping): | ||
if 'ANSIBLE_MODULE_ARGS' not in request.param: | ||
request.param = {'ANSIBLE_MODULE_ARGS': request.param} | ||
if '_ansible_remote_tmp' not in request.param['ANSIBLE_MODULE_ARGS']: | ||
request.param['ANSIBLE_MODULE_ARGS']['_ansible_remote_tmp'] = '/tmp' | ||
if '_ansible_keep_remote_files' not in request.param['ANSIBLE_MODULE_ARGS']: | ||
request.param['ANSIBLE_MODULE_ARGS']['_ansible_keep_remote_files'] = False | ||
args = json.dumps(request.param) | ||
else: | ||
raise Exception('Malformed data to the patch_ansible_module pytest fixture') | ||
|
||
mocker.patch('ansible.module_utils.basic._ANSIBLE_ARGS', to_bytes(args)) |
Empty file.
Empty file.
Oops, something went wrong.