Update new network unit test to reflect changes in mock_open

This commit is contained in:
Erik Johnson 2018-06-18 12:13:49 -05:00
parent a8f11594f1
commit cc002b8fd7
No known key found for this signature in database
GPG key ID: 5E5583C437808F3F

View file

@ -230,16 +230,14 @@ class NetworkTestCase(TestCase, LoaderModuleMockMixin):
Test for Modify hostname
'''
self.assertFalse(network.mod_hostname(None))
file_d = '\n'.join(['#', 'A B C D,E,F G H'])
with patch.object(salt.utils.path, 'which', return_value='hostname'):
with patch.dict(network.__salt__,
{'cmd.run': MagicMock(return_value=None)}):
file_d = '\n'.join(['#', 'A B C D,E,F G H'])
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()
with patch.dict(network.__grains__, {'os_family': 'A'}):
self.assertTrue(network.mod_hostname('hostname'))
with patch.object(salt.utils.path, 'which', return_value='hostname'), \
patch.dict(network.__salt__,
{'cmd.run': MagicMock(return_value=None)}), \
patch.dict(network.__grains__, {'os_family': 'A'}), \
patch('salt.utils.files.fopen', mock_open(read_data=file_d)):
self.assertTrue(network.mod_hostname('hostname'))
def test_connect(self):
'''