def post(self, request, data): """Changes the authenticated user's password if the old password is correct.""" handler = UserHandler() handler.change_password(request.user, data["old_password"], data["new_password"]) return Response("", status=204)
def test_change_password(data_fixture): user = data_fixture.create_user(email='test@localhost', password='******') handler = UserHandler() with pytest.raises(InvalidPassword): handler.change_password(user, 'INCORRECT', 'new') user.refresh_from_db() assert user.check_password('test') user = handler.change_password(user, 'test', 'new') assert user.check_password('new')
def test_change_password(data_fixture): user = data_fixture.create_user(email="test@localhost", password="******") handler = UserHandler() with pytest.raises(InvalidPassword): handler.change_password(user, "INCORRECT", "new") user.refresh_from_db() assert user.check_password("test") user = handler.change_password(user, "test", "new") assert user.check_password("new")