Пример #1
0
    def test_create_user_with_payload_is_none(self):
        data = {

        }

        #Call the API create user
        response = create_user(data)
        assert response == None
Пример #2
0
    def test_create_user_which_payload_has_invalid_keys(self):
        data = {
            "key_invalid": 1,
        }

        # Call the API create user
        response = create_user(data)

        assert response == None
Пример #3
0
def create_user(
    user: _schemas.UserCreate, db: _orm.Session = _fastapi.Depends(_services.get_db)
):
    db_user = _services.get_user_by_email(db=db, email=user.email)
    if db_user:
        raise _fastapi.HTTPException(
            status_code=400, detail="woops the email is in use"
        )
    return _services.create_user(db=db, user=user)
Пример #4
0
    def test_create_user_which_payload_has_duplicate_keys(self):
        data = {
            "name" : "lazada_one",
            "name" : "lazada_two"
        }

        # Call the API create user
        response = create_user(data)

        assert response == None
Пример #5
0
def create_user(user: schemas.NewUser):
    try:
        user = services.create_user(user, ioc)
        return { "status": "success", "user": user }, status.HTTP_201_CREATED
    except Exception as exception:
        exception_name = exception.args[0]
        if exception_name == 'Conflict':
            raise HTTPException(status_code=409, detail='User already registered')
        else:
            raise HTTPException(status_code=500, detail='Server internal error')
Пример #6
0
    def test_create_user(self):

        #Post data with keys 'name', 'username', 'email', 'phone', 'website'
        data = {
            "name": "lazada",
            "username": "******",
            "email": "*****@*****.**",
            "phone": "021321321",
            "website": "abc.com.vn"
        }

        #Call API create new user
        response = create_user(data)

        #Parse to json
        json_response = response.json()

        #Confirm that user is created via all information are correct
        assert json_response["id"] == 11
        assert json_response["name"] == data["name"]
        assert json_response["username"] == data["username"]
        assert json_response["email"] == data["email"]
        assert json_response["phone"] == data["phone"]
        assert json_response["website"] == data["website"]
Пример #7
0
def create_user(
    user: schemas.UserCreate, repo: Repository = Depends(get_users_repository)
):
    return services.create_user(repo, user)
Пример #8
0
async def user_create(user: UserCreateRequest) -> User:
    try:
        user = create_user(**user.dict())
    except IntegrityError:
        raise HTTPException(status_code=400)
    return User(**user.__data__)
Пример #9
0
def cancel_activation():
    try:
        user = services.create_user(user, ioc)
        return { "status": "success", "user": user }, status.HTTP_201_CREATED
    except Exception as exception:
        raise HTTPException(status_code=500, detail='Server internal error')