mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-02 15:21:25 -07:00
Move unit test compat code out of lib/ansible/
. (#46996)
* Move ansible.compat.tests to test/units/compat/. * Fix unit test references to ansible.compat.tests. * Move builtins compat to separate file. * Fix classification of test/units/compat/ dir.
This commit is contained in:
parent
6e2897647c
commit
3033fd96b0
462 changed files with 773 additions and 776 deletions
|
@ -22,9 +22,10 @@ from io import BytesIO
|
|||
|
||||
from ansible.module_utils.six.moves.urllib.error import HTTPError
|
||||
|
||||
from ansible.compat.tests import mock
|
||||
from ansible.compat.tests import unittest
|
||||
from ansible.compat.tests.mock import mock_open, patch
|
||||
from units.compat import mock
|
||||
from units.compat import unittest
|
||||
from units.compat.builtins import BUILTINS
|
||||
from units.compat.mock import mock_open, patch
|
||||
from ansible.errors import AnsibleConnectionFailure
|
||||
from ansible.module_utils.connection import ConnectionError
|
||||
from ansible.module_utils.network.ftd.common import HTTPMethod, ResponseParams
|
||||
|
@ -32,11 +33,6 @@ from ansible.module_utils.network.ftd.fdm_swagger_client import SpecProp, FdmSwa
|
|||
from ansible.module_utils.six import PY3, StringIO
|
||||
from ansible.plugins.httpapi.ftd import HttpApi
|
||||
|
||||
if PY3:
|
||||
BUILTINS_NAME = 'builtins'
|
||||
else:
|
||||
BUILTINS_NAME = '__builtin__'
|
||||
|
||||
EXPECTED_BASE_HEADERS = {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
|
@ -191,7 +187,7 @@ class TestFtdHttpApi(unittest.TestCase):
|
|||
self.connection_mock.send.return_value = self._connection_response('File content')
|
||||
|
||||
open_mock = mock_open()
|
||||
with patch('%s.open' % BUILTINS_NAME, open_mock):
|
||||
with patch('%s.open' % BUILTINS, open_mock):
|
||||
self.ftd_plugin.download_file('/files/1', '/tmp/test.txt')
|
||||
|
||||
open_mock.assert_called_once_with('/tmp/test.txt', 'wb')
|
||||
|
@ -206,7 +202,7 @@ class TestFtdHttpApi(unittest.TestCase):
|
|||
self.connection_mock.send.return_value = response, response_data
|
||||
|
||||
open_mock = mock_open()
|
||||
with patch('%s.open' % BUILTINS_NAME, open_mock):
|
||||
with patch('%s.open' % BUILTINS, open_mock):
|
||||
self.ftd_plugin.download_file('/files/1', '/tmp/')
|
||||
|
||||
open_mock.assert_called_once_with('/tmp/%s' % filename, 'wb')
|
||||
|
@ -219,7 +215,7 @@ class TestFtdHttpApi(unittest.TestCase):
|
|||
self.connection_mock.send.return_value = self._connection_response({'id': '123'})
|
||||
|
||||
open_mock = mock_open()
|
||||
with patch('%s.open' % BUILTINS_NAME, open_mock):
|
||||
with patch('%s.open' % BUILTINS, open_mock):
|
||||
resp = self.ftd_plugin.upload_file('/tmp/test.txt', '/files')
|
||||
|
||||
assert {'id': '123'} == resp
|
||||
|
@ -237,7 +233,7 @@ class TestFtdHttpApi(unittest.TestCase):
|
|||
self.connection_mock.send.return_value = self._connection_response('invalidJsonResponse')
|
||||
|
||||
open_mock = mock_open()
|
||||
with patch('%s.open' % BUILTINS_NAME, open_mock):
|
||||
with patch('%s.open' % BUILTINS, open_mock):
|
||||
with self.assertRaises(ConnectionError) as res:
|
||||
self.ftd_plugin.upload_file('/tmp/test.txt', '/files')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue