mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add unit test for new method 'user.chother'
This commit is contained in:
parent
694882632c
commit
7dea455c12
1 changed files with 34 additions and 2 deletions
|
@ -46,7 +46,8 @@ class UserAddTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'fullname': 'root',
|
||||
'roomnumber': '',
|
||||
'workphone': '',
|
||||
'homephone': ''}
|
||||
'homephone': '',
|
||||
'other': ''}
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
|
@ -96,7 +97,8 @@ class UserAddTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'fullname': 'root',
|
||||
'roomnumber': '',
|
||||
'workphone': '',
|
||||
'homephone': ''}]
|
||||
'homephone': '',
|
||||
'other': ''}]
|
||||
with patch('salt.modules.useradd._format_info', MagicMock(return_value=self.mock_pwall)):
|
||||
self.assertEqual(useradd.getent(), ret)
|
||||
|
||||
|
@ -330,6 +332,36 @@ class UserAddTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch.object(useradd, 'info', mock):
|
||||
self.assertFalse(useradd.chhomephone('salt', 1))
|
||||
|
||||
# 'chother' function tests: 1
|
||||
|
||||
def test_chother(self):
|
||||
'''
|
||||
Test if the user's other GECOS attribute is changed
|
||||
'''
|
||||
mock = MagicMock(return_value=False)
|
||||
with patch.object(useradd, '_get_gecos', mock):
|
||||
self.assertFalse(useradd.chother('salt', 1))
|
||||
|
||||
mock = MagicMock(return_value={'other': 'foobar'})
|
||||
with patch.object(useradd, '_get_gecos', mock):
|
||||
self.assertTrue(useradd.chother('salt', 'foobar'))
|
||||
|
||||
mock = MagicMock(return_value={'other': 'foobar2'})
|
||||
with patch.object(useradd, '_get_gecos', mock):
|
||||
mock = MagicMock(return_value=None)
|
||||
with patch.dict(useradd.__salt__, {'cmd.run': mock}):
|
||||
mock = MagicMock(return_value={'other': 'foobar3'})
|
||||
with patch.object(useradd, 'info', mock):
|
||||
self.assertFalse(useradd.chother('salt', 'foobar'))
|
||||
|
||||
mock = MagicMock(return_value={'other': 'foobar3'})
|
||||
with patch.object(useradd, '_get_gecos', mock):
|
||||
mock = MagicMock(return_value=None)
|
||||
with patch.dict(useradd.__salt__, {'cmd.run': mock}):
|
||||
mock = MagicMock(return_value={'other': 'foobar3'})
|
||||
with patch.object(useradd, 'info', mock):
|
||||
self.assertFalse(useradd.chother('salt', 'foobar'))
|
||||
|
||||
# 'info' function tests: 1
|
||||
|
||||
@skipIf(HAS_PWD is False, 'The pwd module is not available')
|
||||
|
|
Loading…
Add table
Reference in a new issue