def test_bad_pwd(self, mocker): mocker.patch.object(User, "get", return_value=userm) userm.password = "******" userm.check_password.return_value = False with pytest.raises(exceptions.Forbidden) as exc: login(cred, "jwt") assert str(exc.value) == "Incorrect username or password."
def test_fail_user_inactive(self, mocker): mocker.patch.object(User, "get", return_value=userm) userm.check_password.return_value = True userm.actif = False jwt = mocker.MagicMock() jwt.encode.return_value = True with pytest.raises(exceptions.Forbidden) as exc: login(cred, jwt) assert str(exc.value) == "Utilisateur inactif"
def test_fail_token_none(self, mocker): mocker.patch.object(User, "get", return_value=userm) userm.check_password.return_value = True jwt = mocker.MagicMock() jwt.encode.return_value = None with pytest.raises(exceptions.ConfigurationError) as exc: login(cred, jwt) assert str(exc.value) == "échec de l'encodage jwt"
def test_login_pass(self, mocker): mocker.patch.object(User, "get", return_value=userm) userm.check_password.return_value = True jwt = mocker.MagicMock() jwt.encode = lambda x: x assert {"id", "username", "iat", "exp"} == set(login(cred, jwt).keys())
def test_bad_username(self, mocker): mocker.patch.object(User, "get", return_value=None) with pytest.raises(exceptions.Forbidden) as exc: login(cred, "jwt") assert str(exc.value) == "Incorrect username or password."