Ejemplo n.º 1
0
async def register_tenant(
    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_tenant(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_tenant(application: Application, session: Session,
                       tenant_create_data: dict):
    del tenant_create_data["role"]
    assert not session.query(User).count()
    tenant: User = application.create_tenant(session, **tenant_create_data)
    assert tenant
    assert tenant.dob
    assert tenant.role == UserRole.TENANT
    assert session.query(User).count() == 1
Ejemplo n.º 3
0
def another_tenant(session: Session, application: Application) -> Tenant:
    return application.create_tenant(
        session,
        "Another",
        "Tenant",
        datetime.utcnow().date(),
        "*****@*****.**",
        "01023478",
        "password",
    )
Ejemplo n.º 4
0
def new_apartment_applications(
        session: Session, application: Application,
        apartment: Apartment) -> List[ApartmentApplication]:
    applications = []
    for i in range(5):
        tenant = application.create_tenant(
            session,
            f"fname{i}",
            f"lname{i}",
            datetime.now().date(),
            f"jdoe{i}#email.com",
            f"012345{i}",
            f"password{i}",
        )
        applications.append(
            application.apply_for_apartment(session, tenant, apartment))
    return applications