def test_invite_tenant_for_already_awarded_apartment_fail( application: Application, session: Session, tenant: Tenant, another_tenant: Tenant, landlord: Landlord, awarded_apartment_application, ): with pytest.raises(ApplicationError): application.invite_tenant_to_apply( session, landlord, another_tenant, awarded_apartment_application.apartment)
def invite_tenant( data: InviteCreateSchema, landlord: Landlord = Depends(deps.get_current_active_landlord), session: Session = Depends(deps.get_database_session), application: Application = Depends(deps.get_application), ): try: existing_request = ( session.query(BookingRequest) .filter(BookingRequest.apartment_id == data.apartment_id) .filter(BookingRequest.tenant_id == data.tenant_id) .first() ) if existing_request: raise HTTPException( 400, "Tenant has already been invited to apply for this apartment" ) tenant: Tenant = session.query(Tenant).get(data.tenant_id) if not tenant: raise HTTPException(404, "Tenant not found") apartment: Apartment = ( session.query(Apartment) .filter(Apartment.landlord_id == landlord.id) .filter(Apartment.id == data.apartment_id) .first() ) if not apartment: raise HTTPException(404, "Apartment not found") return application.invite_tenant_to_apply(session, landlord, tenant, apartment) except ApplicationError as e: raise HTTPException(400, str(e))
def booking_request( application: Application, tenant: Tenant, landlord: Landlord, apartment: Apartment, session: Session, ): booking_request = application.invite_tenant_to_apply( session, landlord, tenant, apartment) assert booking_request.status == BookingRequestStatus.PENDING assert not booking_request.apartment_application_id return booking_request
def test_landlord_invite_tenant_to_apply( application: Application, session: Session, landlord: Landlord, tenant: Tenant, apartment: Apartment, ): assert not session.query(BookingRequest).count() booking_request: BookingRequest = application.invite_tenant_to_apply( session, landlord, tenant, apartment) assert booking_request.apartment_id == apartment.id assert booking_request.tenant_id == tenant.id assert not booking_request.apartment_application_id assert booking_request.status == BookingRequestStatus.PENDING