Ejemplo n.º 1
0
async def register_landlord(
    data: UserCreateSchema,
    background_tasks: BackgroundTasks,
    application: Application = Depends(dependencies.get_application),
    session: Session = Depends(dependencies.get_database_session),
):
    try:
        existing_user_with_email = (
            session.query(User).filter(User.email == data.email).one_or_none()
        )
        if existing_user_with_email:
            raise HTTPException(409, "User with email already exists")
        existing_user_with_phonenumber = (
            session.query(User)
            .filter(User.phone_number == data.phone_number)
            .one_or_none()
        )
        if existing_user_with_phonenumber:
            raise HTTPException(409, "User with phone number aready exists")
        result = application.create_landlord(session, **data.dict())
        background_tasks.add_task(
            util.send_email,
            to=result.email,
            subject="Verify Acccount",
            message=generate_email_verification_text(result),
            html=generate_email_verification_html(result),
        )
        return result
    except ApplicationError as e:
        raise HTTPException(401, str(e))
Ejemplo n.º 2
0
def test_create_landlord(application: Application, session: Session,
                         landlord_create_data: dict):
    del landlord_create_data["role"]
    assert not session.query(User).count()
    landlord: User = application.create_landlord(session,
                                                 **landlord_create_data)
    assert landlord
    assert not landlord.dob
    assert landlord.role == UserRole.LANDLORD
    assert session.query(User).count() == 1
Ejemplo n.º 3
0
def another_landlord(session: Session, application: Application) -> Landlord:
    return application.create_landlord(
        session,
        "Another",
        "Landlord",
        datetime.utcnow().date(),
        "*****@*****.**",
        "001234578",
        "password",
    )