Exemple #1
0
    def post(self):
        username = request.json.get('username', None)
        password = request.json.get('password', None)

        result, user = user_crud.create_user(username, password)
        if result:
            return user
        else:
            return None
Exemple #2
0
def test_create_user_basic():
    user_crud.create_user("ronaldo", "fenomeno123")
    user = user_crud.get_user_by_username("ronaldo")
    assert user == User("ronaldo", "fenomeno123")
Exemple #3
0
def test_create_user_ids():
    user_crud.create_user("ronaldinho", "j0g4muit0")
    user1 = user_crud.get_user_by_id(1)
    user2 = user_crud.get_user_by_id(2)
    assert user1 == User("ronaldo", "fenomeno123")
    assert user2 == User("ronaldinho", "j0g4muit0")
Exemple #4
0
def test_create_user_repeated_username():
    user_crud.create_user("ronaldo", "fenomeno123")
    user_crud.create_user("ronaldo", "fenomeno123")
    user = user_crud.get_user_by_id(2)
    assert user is None
Exemple #5
0
def create(user: schemas.UserCreate, db: Session = Depends(get_db)):
    db_user = user_crud.get_user_by_email(db, user.email)
    if db_user:
        raise HTTPException(status_code=400,
                            detail="Email already registered.")
    return user_crud.create_user(db=db, user=user)