mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 00:55:19 +00:00
Update nfs3 module tests to reflect changes in mock_open
This commit is contained in:
parent
b7eab25d6c
commit
16c414e120
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user