Update timezone module tests to reflect changes in mock_open

This commit is contained in:
Erik Johnson 2018-06-17 23:55:48 -05:00
parent fc0aa9934f
commit ed40371a06
No known key found for this signature in database
GPG Key ID: 5E5583C437808F3F

View File

@ -203,13 +203,11 @@ class TimezoneModuleTestCase(TestCase, LoaderModuleMockMixin):
:return:
'''
with patch.dict(timezone.__grains__, {'os_family': ['Gentoo']}):
_fopen = mock_open()
with patch('salt.utils.files.fopen', _fopen):
with patch('salt.utils.files.fopen', mock_open()) as m_open:
assert timezone.set_zone(self.TEST_TZ)
name, args, kwargs = _fopen.mock_calls[0]
assert args == ('/etc/timezone', 'w')
name, args, kwargs = _fopen.return_value.__enter__.return_value.write.mock_calls[0]
assert args == ('UTC',)
fh_ = m_open.filehandles['/etc/timezone'][0]
assert fh_.call_args == ('/etc/timezone', 'w'), fh_.call_args
assert fh_.write_calls == ['UTC', '\n'], fh_.write_calls
@skipIf(salt.utils.platform.is_windows(), 'os.symlink not available in Windows')
@patch('salt.utils.path.which', MagicMock(return_value=False))
@ -222,13 +220,11 @@ class TimezoneModuleTestCase(TestCase, LoaderModuleMockMixin):
:return:
'''
with patch.dict(timezone.__grains__, {'os_family': ['Debian']}):
_fopen = mock_open()
with patch('salt.utils.files.fopen', _fopen):
with patch('salt.utils.files.fopen', mock_open()) as m_open:
assert timezone.set_zone(self.TEST_TZ)
name, args, kwargs = _fopen.mock_calls[0]
assert args == ('/etc/timezone', 'w')
name, args, kwargs = _fopen.return_value.__enter__.return_value.write.mock_calls[0]
assert args == ('UTC',)
fh_ = m_open.filehandles['/etc/timezone'][0]
assert fh_.call_args == ('/etc/timezone', 'w'), fh_.call_args
assert fh_.write_calls == ['UTC', '\n'], fh_.write_calls
@skipIf(salt.utils.platform.is_windows(), 'os.symlink not available in Windows')
@patch('salt.utils.path.which', MagicMock(return_value=True))