Пример #1
0
    def test_get_by_id(self):
        """Get user by ID."""
        user = User('foo', '*****@*****.**')
        user.save()

        retrieved = User.get_by_id(user.id)
        assert retrieved == user
Пример #2
0
 def create_user(self, arg_dict):
     try:
         user = User(**arg_dict)
     except AssertionError as ex:
         raise falcon.HTTPBadRequest('Could not create User.', ex.message)
     try:
         return user.save()
     except (IntegrityError, InvalidRequestError) as ex:
         DB.rollback()
         raise falcon.HTTPBadRequest('Could not create User.', 'That email is already taken.')
Пример #3
0
 def test_check_password(self):
     """Check password."""
     user = User.create(username='******',
                        email='*****@*****.**',
                        password='******')
     assert user.check_password('foobarbaz123') is True
     assert user.check_password('barfoobaz') is False
Пример #4
0
 def on_post(self, req, res, arg_dict):
     """Create a new session for the user"""
     user, key, error = User.sign_in(arg_dict)
     if error:
         raise falcon.HTTPBadRequest("Could not sign in", error)
     res.set_cookie("Authorization", key, domain=".rovu.com", secure=False)
     res.body = user_schema.dumps(user).data
     res.status = falcon.HTTP_201
Пример #5
0
def load_user(user_id):
    """Load user by ID."""
    return User.get_by_id(int(user_id))
Пример #6
0
 def test_password_is_nullable(self):
     """Test null password."""
     user = User(username='******', email='*****@*****.**')
     user.save()
     assert user.password is None
Пример #7
0
 def test_created_at_defaults_to_datetime(self):
     """Test creation date."""
     user = User(username='******', email='*****@*****.**')
     user.save()
     assert bool(user.created_at)
     assert isinstance(user.created_at, dt.datetime)
Пример #8
0
def _validate_key(key):
    return User.query().filter(User.auth_key == key).first()