def test_chhomephone(self): ''' Test if the user's Home Phone is changed ''' mock = MagicMock(return_value=False) with patch.object(useradd, '_get_gecos', mock): self.assertFalse(useradd.chhomephone('salt', 1)) mock = MagicMock(return_value={'homephone': '1'}) with patch.object(useradd, '_get_gecos', mock): self.assertTrue(useradd.chhomephone('salt', 1)) mock = MagicMock(return_value={'homephone': '2'}) with patch.object(useradd, '_get_gecos', mock): mock = MagicMock(return_value=None) with patch.dict(useradd.__salt__, {'cmd.run': mock}): mock = MagicMock(return_value={'homephone': '3'}) with patch.object(useradd, 'info', mock): self.assertFalse(useradd.chhomephone('salt', 1)) mock = MagicMock(return_value={'homephone': '3'}) with patch.object(useradd, '_get_gecos', mock): mock = MagicMock(return_value=None) with patch.dict(useradd.__salt__, {'cmd.run': mock}): mock = MagicMock(return_value={'homephone': '3'}) with patch.object(useradd, 'info', mock): self.assertFalse(useradd.chhomephone('salt', 1))
def test_chhomephone(self): """ Test if the user's Home Phone is changed """ mock = MagicMock(return_value=False) with patch.object(useradd, "_get_gecos", mock): self.assertFalse(useradd.chhomephone("salt", 1)) mock = MagicMock(return_value={"homephone": "1"}) with patch.object(useradd, "_get_gecos", mock): self.assertTrue(useradd.chhomephone("salt", 1)) mock = MagicMock(return_value={"homephone": "2"}) with patch.object(useradd, "_get_gecos", mock): mock = MagicMock(return_value=None) with patch.dict(useradd.__salt__, {"cmd.run": mock}): mock = MagicMock(return_value={"homephone": "3"}) with patch.object(useradd, "info", mock): self.assertFalse(useradd.chhomephone("salt", 1)) mock = MagicMock(return_value={"homephone": "3"}) with patch.object(useradd, "_get_gecos", mock): mock = MagicMock(return_value=None) with patch.dict(useradd.__salt__, {"cmd.run": mock}): mock = MagicMock(return_value={"homephone": "3"}) with patch.object(useradd, "info", mock): self.assertFalse(useradd.chhomephone("salt", 1))
def test_chhomephone(self): ''' Test if the user's Home Phone is changed ''' mock = MagicMock(return_value=False) with patch.object(useradd, '_get_gecos', mock): self.assertFalse(useradd.chhomephone('salt', 1)) mock = MagicMock(return_value={'homephone': '1'}) with patch.object(useradd, '_get_gecos', mock): self.assertTrue(useradd.chhomephone('salt', 1)) mock = MagicMock(return_value={'homephone': '2'}) with patch.object(useradd, '_get_gecos', mock): mock = MagicMock(return_value=None) with patch.dict(useradd.__salt__, {'cmd.run': mock}): mock = MagicMock(return_value={'homephone': '3'}) with patch.object(useradd, 'info', mock): self.assertFalse(useradd.chhomephone('salt', 1)) mock = MagicMock(return_value={'homephone': '3'}) with patch.object(useradd, '_get_gecos', mock): mock = MagicMock(return_value=None) with patch.dict(useradd.__salt__, {'cmd.run': mock}): mock = MagicMock(return_value={'homephone': '3'}) with patch.object(useradd, 'info', mock): self.assertFalse(useradd.chhomephone('salt', 1))
def test_chhomephone(): # command not found with patch("salt.utils.path.which", MagicMock(return_value=None)): mock = MagicMock() with patch.object( useradd, "_get_gecos", MagicMock(return_value={"homephone": "1"})), patch.dict( useradd.__salt__, {"cmd.run": mock}): with pytest.raises(CommandExecutionError): useradd.chhomephone("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.chhomephone("salt", 1) is False mock = MagicMock(return_value={"homephone": "1"}) with patch.object(useradd, "_get_gecos", mock): assert useradd.chhomephone("salt", 1) is True mock = MagicMock(return_value={"homephone": "2"}) with patch.object(useradd, "_get_gecos", mock): mock = MagicMock(return_value=None) with patch.dict(useradd.__salt__, {"cmd.run": mock}): mock = MagicMock(return_value={"homephone": "3"}) with patch.object(useradd, "info", mock): assert useradd.chhomephone("salt", 1) is False mock = MagicMock(return_value={"homephone": "3"}) with patch.object(useradd, "_get_gecos", mock): mock = MagicMock(return_value=None) with patch.dict(useradd.__salt__, {"cmd.run": mock}): mock = MagicMock(return_value={"homephone": "3"}) with patch.object(useradd, "info", mock): assert useradd.chhomephone("salt", 1) is False