def test_get_by_id(self): """Get user by ID.""" user = User('*****@*****.**') user.save() retrieved = User.get_by_id(user.id) assert retrieved == user
def post(self): parser = reqparse.RequestParser() parser.add_argument('email', required=True, help='email field is required') parser.add_argument('full_name', required=True, help='full_name field is required') parser.add_argument('username', required=True, help='username field is required') parser.add_argument('password', required=True, help='password field is required') parser.parse_args() full_name = request.form['full_name'] email = request.form['email'] password = request.form['password'] username = request.form['username'] user = User(full_name, username, email, password) check_user = user.check_username_email(username, email) if check_user == None: user.save() user_details = { 'id': user.id, 'username': user.username, 'email': user.email, 'full_name': user.full_name } token = create_access_token(identity=user.id) return { 'message': 'User created successfully', 'user': user_details, 'token': token } else: if check_user.username == username: return {'message': 'Username already in use'}, 409 else: return {'message': 'Email already in use'}, 409
def test_password_is_nullable(self): """Test null password.""" user = User(email='*****@*****.**') user.save() assert user.password is None
def test_created_at_defaults_to_datetime(self): """Test creation date.""" user = User(email='*****@*****.**') user.save() assert bool(user.created_at) assert isinstance(user.created_at, dt.datetime)