Update nfs3 module tests to reflect changes in mock_open

This commit is contained in:
Erik Johnson 2018-06-18 12:28:38 -05:00
parent b7eab25d6c
commit 16c414e120
No known key found for this signature in database
GPG Key ID: 5E5583C437808F3F

View File

@ -10,6 +10,7 @@ from __future__ import absolute_import, print_function, unicode_literals
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase, skipIf
from tests.support.mock import (
MagicMock,
mock_open,
patch,
NO_MOCK,
@ -32,21 +33,21 @@ class NfsTestCase(TestCase, LoaderModuleMockMixin):
'''
Test for List configured exports
'''
file_d = '\n'.join(['A B1(23'])
with patch('salt.utils.files.fopen',
mock_open(read_data=file_d), create=True) as mfi:
mfi.return_value.__iter__.return_value = file_d.splitlines()
self.assertDictEqual(nfs3.list_exports(),
{'A': [{'hosts': 'B1', 'options': ['23']}]})
with patch('salt.utils.files.fopen', mock_open(read_data='A B1(23')):
exports = nfs3.list_exports()
assert exports == {'A': [{'hosts': 'B1', 'options': ['23']}]}, exports
def test_del_export(self):
'''
Test for Remove an export
'''
with patch.object(nfs3,
'list_exports',
return_value={'A':
[{'hosts':
['B1'], 'options': ['23']}]}):
with patch.object(nfs3, '_write_exports', return_value=None):
self.assertDictEqual(nfs3.del_export(path='A'), {})
list_exports_mock = MagicMock(return_value={
'A': [
{'hosts': ['B1'],
'options': ['23']},
],
})
with patch.object(nfs3, 'list_exports', list_exports_mock), \
patch.object(nfs3, '_write_exports', MagicMock(return_value=None)):
result = nfs3.del_export(path='A')
assert result == {}, result