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'))
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"))
def test_chother(): # command not found with patch("salt.utils.path.which", MagicMock(return_value=None)): mock = MagicMock() with patch.object(useradd, "_get_gecos", MagicMock(return_value={"other": "1"})), patch.dict( useradd.__salt__, {"cmd.run": mock}): with pytest.raises(CommandExecutionError): useradd.chother("salt", 2) mock.assert_not_called() # command found with patch("salt.utils.path.which", MagicMock(return_value="/sbin/usermod")): mock = MagicMock(return_value=False) with patch.object(useradd, "_get_gecos", mock): assert useradd.chother("salt", 1) is False mock = MagicMock(return_value={"other": "foobar"}) with patch.object(useradd, "_get_gecos", mock): assert useradd.chother("salt", "foobar") is True 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): assert useradd.chother("salt", "foobar") is False 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): assert useradd.chother("salt", "foobar") is False