def test_it_is_invalid_with_expired_token(self, pyramid_csrf_request): pyramid_csrf_request.registry.password_reset_serializer = ( self.FakeExpiredSerializer()) schema = ResetPasswordSchema().bind(request=pyramid_csrf_request) with pytest.raises(colander.Invalid) as exc: schema.deserialize({"user": "******", "password": "******"}) assert "user" in exc.value.asdict() assert "Reset code has expired." in exc.value.asdict()["user"]
def test_it_is_invalid_with_expired_token(self, pyramid_csrf_request): pyramid_csrf_request.registry.password_reset_serializer = ( self.FakeExpiredSerializer() ) schema = ResetPasswordSchema().bind(request=pyramid_csrf_request) with pytest.raises(colander.Invalid) as exc: schema.deserialize({"user": "******", "password": "******"}) assert "user" in exc.value.asdict() assert "Reset code has expired." in exc.value.asdict()["user"]
def test_it_is_invalid_with_expired_token(self, pyramid_csrf_request): pyramid_csrf_request.registry.password_reset_serializer = ( self.FakeExpiredSerializer()) schema = ResetPasswordSchema().bind(request=pyramid_csrf_request) with pytest.raises(colander.Invalid) as exc: schema.deserialize({ 'user': '******', 'password': '******', }) assert 'user' in exc.value.asdict() assert 'Reset code has expired.' in exc.value.asdict()['user']
def test_it_is_invalid_if_user_has_already_reset_their_password( self, pyramid_csrf_request, user_model ): pyramid_csrf_request.registry.password_reset_serializer = self.FakeSerializer() schema = ResetPasswordSchema().bind(request=pyramid_csrf_request) user = user_model.get_by_username.return_value user.password_updated = 2 with pytest.raises(colander.Invalid) as exc: schema.deserialize({"user": "******", "password": "******"}) assert "user" in exc.value.asdict() assert "This reset code has already been used." in exc.value.asdict()["user"]
def test_it_is_invalid_if_user_has_already_reset_their_password( self, pyramid_csrf_request, user_model): pyramid_csrf_request.registry.password_reset_serializer = self.FakeSerializer( ) schema = ResetPasswordSchema().bind(request=pyramid_csrf_request) user = user_model.get_by_username.return_value user.password_updated = 2 with pytest.raises(colander.Invalid) as exc: schema.deserialize({"user": "******", "password": "******"}) assert "user" in exc.value.asdict() assert "This reset code has already been used." in exc.value.asdict( )["user"]
def test_it_returns_user_when_valid(self, pyramid_csrf_request, user_model): pyramid_csrf_request.registry.password_reset_serializer = self.FakeSerializer() schema = ResetPasswordSchema().bind(request=pyramid_csrf_request) user = user_model.get_by_username.return_value user.password_updated = 0 appstruct = schema.deserialize({"user": "******", "password": "******"}) assert appstruct["user"] == user
def test_it_returns_user_when_valid(self, pyramid_csrf_request, user_model): pyramid_csrf_request.registry.password_reset_serializer = ( self.FakeSerializer()) schema = ResetPasswordSchema().bind(request=pyramid_csrf_request) user = user_model.get_by_username.return_value user.password_updated = 0 appstruct = schema.deserialize({ 'user': '******', 'password': '******', }) assert appstruct['user'] == user
def test_it_returns_user_when_valid(self, pyramid_csrf_request, user_model): pyramid_csrf_request.registry.password_reset_serializer = self.FakeSerializer( ) schema = ResetPasswordSchema().bind(request=pyramid_csrf_request) user = user_model.get_by_username.return_value user.password_updated = 0 appstruct = schema.deserialize({ "user": "******", "password": "******" }) assert appstruct["user"] == user
def test_it_is_invalid_with_password_too_short(self, pyramid_csrf_request): schema = ResetPasswordSchema().bind(request=pyramid_csrf_request) with pytest.raises(colander.Invalid) as exc: schema.deserialize({"password": "******"}) assert "password" in exc.value.asdict()