Ejemplo n.º 1
0
def test_all_other_applications_rejected_on_application_completed_ok(
    session: Session,
    application: Application,
    new_apartment_applications: List[ApartmentApplication],
):
    assert len(new_apartment_applications) == 5
    assert all(app.status == ApartmentApplicationStatus.NEW
               for app in new_apartment_applications)
    app1, app2, app3, app4, app5 = new_apartment_applications
    application.reject_apartment_application(session, app1)
    application.consider_apartment_application(session, app2)
    application.consider_apartment_application(session, app3)
    application.process_apartment_application(session, app3)
    application.consider_apartment_application(session, app4)
    application.consider_apartment_application(session, app5)
    assert app1.status == ApartmentApplicationStatus.REJECTED
    assert all(app.status == ApartmentApplicationStatus.CONSIDERED
               for app in (app2, app4, app5))
    assert app3.status == ApartmentApplicationStatus.PROCESSING
    application.tenant_signed_contract(session, app3, datetime.now())
    application.landlord_signed_contract(session, app3, datetime.now())
    assert app1.status == ApartmentApplicationStatus.REJECTED
    assert all(app.status == ApartmentApplicationStatus.CONSIDERED
               for app in (app2, app4, app5))
    assert app3.status == ApartmentApplicationStatus.AWARDED
    application.provide_keys_to_tenant(session, app3)
    application.tenant_receive_keys(session, app3)
    assert all(app.status == ApartmentApplicationStatus.REJECTED
               for app in (app1, app2, app4, app5))
    assert app3.status == ApartmentApplicationStatus.COMPLETED
Ejemplo n.º 2
0
def test_landlord_reject_apartment_application_not_in_new_status_fail(
    application: Application,
    session: Session,
    considered_apartment_application: ApartmentApplication,
):
    assert (considered_apartment_application.status ==
            ApartmentApplicationStatus.CONSIDERED)
    with pytest.raises(ApplicationError):
        application.reject_apartment_application(
            session, considered_apartment_application)
Ejemplo n.º 3
0
def reject_application(
    application_id: UUID,
    background_tasks: BackgroundTasks,
    landlord: Landlord = Depends(deps.get_current_landlord),
    session: Session = Depends(deps.get_database_session),
    app: Application = Depends(deps.get_application),
):
    try:
        apartment_application: ApartmentApplication = (
            session.query(ApartmentApplication)
            .join(Apartment, ApartmentApplication.apartment_id == Apartment.id)
            .filter(ApartmentApplication.id == application_id)
            .filter(Apartment.landlord_id == landlord.id)
            .one_or_none()
        )
        if not apartment_application:
            raise HTTPException(404, "application not found")
        email_message = f"Your application for apartment {apartment_application.apartment.name} rejected."
        background_tasks.add_task(
            send_email,
            to=apartment_application.tenant.email,
            subject="Digirent Apartment Application Notification",
            message=email_message,
        )
        return app.reject_apartment_application(session, apartment_application)
    except ApplicationError as e:
        raise HTTPException(400, str(e))
Ejemplo n.º 4
0
def test_landlord_reject_new_apartment_application_ok(
    new_apartment_application: ApartmentApplication,
    application: Application,
    session: Session,
):
    tenant_application = application.reject_apartment_application(
        session, new_apartment_application)
    assert tenant_application.status == ApartmentApplicationStatus.REJECTED
    tenant_application_db = (session.query(ApartmentApplication).filter_by(
        tenant_id=new_apartment_application.tenant.id).filter_by(
            apartment_id=new_apartment_application.apartment.id).one_or_none())
    assert tenant_application_db.status == ApartmentApplicationStatus.REJECTED