コード例 #1
0
def test_set_user_bank_details(client: TestClient, session: Session,
                               user: User, user_auth_header: dict):
    assert not user.bank_detail
    response = client.post(
        "/api/me/bank",
        headers=user_auth_header,
        json={
            "accountName": "Test Account Name",
            "accountNumber": "000000013423",
        },
    )
    assert response.status_code == 200
    result = response.json()
    assert "firstName" in result
    assert "lastName" in result
    assert "email" in result
    assert "id" in result
    assert "phoneNumber" in result
    assert "dob" in result
    assert "description" in result
    assert "city" in result
    assert "gender" in result
    session.expire_all()
    assert user.bank_detail
    assert user.bank_detail.account_name == "Test Account Name"
    assert user.bank_detail.account_number == "000000013423"
コード例 #2
0
def test_landlord_process_another_appliation_when_one_application_was_unsuccessful_ok(
    session: Session,
    application: Application,
    failed_apartment_application: ApartmentApplication,
    another_considered_apartment_application: ApartmentApplication,
):
    assert (another_considered_apartment_application.status ==
            ApartmentApplicationStatus.CONSIDERED)
    assert (not session.query(ApartmentApplication).join(Contract).filter(
        or_(
            ApartmentApplication.status
            == ApartmentApplicationStatus.PROCESSING,
            ApartmentApplication.status == ApartmentApplicationStatus.AWARDED,
        )).count())
    application.process_apartment_application(
        session, another_considered_apartment_application)
    session.expire_all()
    assert (another_considered_apartment_application.status ==
            ApartmentApplicationStatus.PROCESSING)
    assert (session.query(ApartmentApplication).join(Contract).filter(
        or_(
            ApartmentApplication.status ==
            ApartmentApplicationStatus.PROCESSING,
            ApartmentApplication.status == ApartmentApplicationStatus.AWARDED,
        )).count() == 1)
コード例 #3
0
def test_update_user_profile_description(client: TestClient, user: User,
                                         session: Session,
                                         user_auth_header: dict):
    new_description = "some description"
    assert user.description != new_description
    response = client.put(
        "/api/me/",
        headers=user_auth_header,
        json={
            "description": new_description,
            "firstName": user.first_name,
            "lastName": user.last_name,
            "email": user.email,
            "phone_number": user.phone_number,
        },
    )
    result = response.json()
    assert "firstName" in result
    assert "lastName" in result
    assert "email" in result
    assert "id" in result
    assert "phoneNumber" in result
    assert "dob" in result
    assert "description" in result
    assert "city" in result
    assert "gender" in result
    session.expire_all()
    xuser = session.query(User).get(user.id)
    assert response.status_code == 200
    assert xuser.description == new_description
コード例 #4
0
def test_update_set_tenant_lookingfor(client: TestClient, session: Session,
                                      tenant: Tenant,
                                      tenant_auth_header: dict):
    assert not tenant.looking_for
    response = client.post(
        "/api/me/looking-for",
        headers=tenant_auth_header,
        json={
            "houseType": HouseType.BUNGALOW.value,
            "city": "Some City",
            "maxBudget": 34.50,
        },
    )
    result = response.json()
    assert response.status_code == 200
    assert "firstName" in result
    assert "lastName" in result
    assert "email" in result
    assert "id" in result
    assert "phoneNumber" in result
    assert "dob" in result
    assert "description" in result
    assert "city" in result
    assert "gender" in result
    session.expire_all()
    assert tenant.looking_for
    assert tenant.looking_for.house_type == HouseType.BUNGALOW
    assert tenant.looking_for.city == "Some City"
    assert tenant.looking_for.max_budget == 34.5
コード例 #5
0
def test_update_user_password(
    client: TestClient,
    user: User,
    session: Session,
    user_auth_header: dict,
    user_create_data: dict,
):
    old_password = user_create_data["password"]
    new_password = "******"
    assert util.password_is_match(old_password, user.hashed_password)
    assert not util.password_is_match(new_password, user.hashed_password)
    response = client.put(
        "/api/me/password",
        headers=user_auth_header,
        json={
            "oldPassword": old_password,
            "newPassword": new_password,
        },
    )
    assert response.status_code == 200
    result = response.json()
    assert "firstName" in result
    assert "lastName" in result
    assert "email" in result
    assert "id" in result
    assert "phoneNumber" in result
    assert "dob" in result
    assert "description" in result
    assert "city" in result
    assert "gender" in result
    session.expire_all()
    assert not util.password_is_match(old_password, user.hashed_password)
    assert util.password_is_match(new_password, user.hashed_password)
コード例 #6
0
def test_landlord_confirm_keys_provided_to_tenant(
    client: TestClient,
    session: Session,
    landlord_auth_header: dict,
    awarded_apartment_application: ApartmentApplication,
):
    assert not awarded_apartment_application.contract.landlord_has_provided_keys
    response = client.post(
        f"/api/applications/{awarded_apartment_application.id}/keys/provided",
        headers=landlord_auth_header,
    )
    assert response.status_code == 200
    session.expire_all()
    assert awarded_apartment_application.contract.landlord_has_provided_keys
コード例 #7
0
def test_another_landlord_reject_tenants_application_fail(
    client: TestClient,
    new_apartment_application: ApartmentApplication,
    session: Session,
    another_landlord_auth_header: dict,
):
    assert new_apartment_application.status == ApartmentApplicationStatus.NEW
    response = client.post(
        f"/api/applications/{new_apartment_application.id}/reject",
        headers=another_landlord_auth_header,
    )
    assert response.status_code == 404
    session.expire_all()
    new_apartment_application = session.query(ApartmentApplication).get(
        new_apartment_application.id)
    assert new_apartment_application.status == ApartmentApplicationStatus.NEW
コード例 #8
0
def test_process_apartment_application(
    client: TestClient,
    considered_apartment_application: ApartmentApplication,
    landlord_auth_header: dict,
    session: Session,
):
    assert not considered_apartment_application.contract
    response = client.post(
        f"/api/applications/{considered_apartment_application.id}/process",
        headers=landlord_auth_header,
    )
    assert response.status_code == 200
    session.expire_all()
    assert (considered_apartment_application.status ==
            ApartmentApplicationStatus.PROCESSING)
    assert considered_apartment_application.contract
    assert considered_apartment_application.contract.status == ContractStatus.NEW
コード例 #9
0
def test_tenant_confirm_received_keys(
    client: TestClient,
    session: Session,
    tenant_auth_header: dict,
    awarded_apartment_application: ApartmentApplication,
):
    awarded_apartment_application.contract.landlord_has_provided_keys = True
    session.commit()
    assert not awarded_apartment_application.contract.tenant_has_received_keys
    response = client.post(
        f"/api/applications/{awarded_apartment_application.id}/keys/received",
        headers=tenant_auth_header,
    )
    assert response.status_code == 200
    session.expire_all()
    assert awarded_apartment_application.contract.landlord_has_provided_keys
    assert awarded_apartment_application.contract.tenant_has_received_keys
コード例 #10
0
def test_landlord_consider_tenants_application_ok(
    client: TestClient,
    new_apartment_application: ApartmentApplication,
    session: Session,
    landlord_auth_header: dict,
):
    assert new_apartment_application.status == ApartmentApplicationStatus.NEW
    response = client.post(
        f"/api/applications/{new_apartment_application.id}/consider",
        headers=landlord_auth_header,
    )
    result = response.json()
    assert response.status_code == 200
    assert isinstance(result, dict)
    session.expire_all()
    new_apartment_application = session.query(ApartmentApplication).get(
        new_apartment_application.id)
    assert new_apartment_application.status == ApartmentApplicationStatus.CONSIDERED
コード例 #11
0
def test_tenant_reject_invitation_ok(
    client: TestClient,
    session: Session,
    booking_request: BookingRequest,
    tenant_auth_header: dict,
):
    assert session.query(BookingRequest).count() == 1
    assert booking_request.status == BookingRequestStatus.PENDING
    response = client.delete(
        f"/api/invites/{booking_request.id}",
        headers=tenant_auth_header,
    )
    assert response.status_code == 200
    result = response.json()
    assert "apartmentId" in result
    assert "tenantId" in result
    assert "status" in result
    assert result["status"] == BookingRequestStatus.REJECTED.value
    session.expire_all()
    assert booking_request.status == BookingRequestStatus.REJECTED
コード例 #12
0
def test_cancel_contract_ok(
    process_apartment_application: ApartmentApplication,
    application: Application,
    session: Session,
):
    canceled_on = datetime.now()
    assert process_apartment_application.contract.status == ContractStatus.NEW
    assert not process_apartment_application.contract.tenant_declined
    assert not process_apartment_application.contract.tenant_declined_on
    application.cancel_contract(
        session,
        process_apartment_application,
        canceled_on,
    )
    session.expire_all()
    apartment_application = session.query(ApartmentApplication).get(
        process_apartment_application.id)
    assert apartment_application.status == ApartmentApplicationStatus.FAILED
    assert apartment_application.contract.status == ContractStatus.CANCELED
    assert apartment_application.contract.canceled_on == canceled_on
    assert apartment_application.contract.canceled
コード例 #13
0
def test_landlord_update_apartments_ok(
    client: TestClient,
    session: Session,
    landlord_auth_header: dict,
    application: Application,
):
    application.create_amenity(session, "first")
    application.create_amenity(session, "second")
    assert not session.query(Apartment).count()
    response = client.post("/api/apartments/",
                           json=apartment_create_data,
                           headers=landlord_auth_header)
    assert response.status_code == 201
    assert session.query(Apartment).count() == 1
    apartment = session.query(Apartment).all()[0]
    assert apartment.name != "updated name"
    assert apartment.amenities == []
    response = client.put(
        f"/api/apartments/{apartment.id}",
        json={
            "name": "updated name",
            "amenities": ["first", "second"]
        },
        headers=landlord_auth_header,
    )
    result = response.json()
    expected_keys = [
        *apartment_create_data.keys(), "id", "amenityTitles", "totalPrice"
    ]
    expected_keys.remove("amenities")
    expected_keys.remove("longitude")
    expected_keys.remove("latitude")
    assert all(key in result for key in expected_keys)
    assert response.status_code == 200
    session.expire_all()
    assert session.query(Apartment).count() == 1
    apartment = session.query(Apartment).all()[0]
    assert apartment.name == "updated name"
    assert len(apartment.amenities) == 2
コード例 #14
0
def test_landlord_decline_new_contract_ok(
    process_apartment_application: ApartmentApplication,
    application: Application,
    session: Session,
):
    declined_on = datetime.now()
    assert process_apartment_application.contract.status == ContractStatus.NEW
    assert not process_apartment_application.contract.tenant_declined
    assert not process_apartment_application.contract.tenant_declined_on
    application.decline_contract(
        session,
        process_apartment_application,
        declined_on,
        process_apartment_application.apartment.landlord,
    )
    session.expire_all()
    apartment_application = session.query(ApartmentApplication).get(
        process_apartment_application.id)
    assert apartment_application.status == ApartmentApplicationStatus.FAILED
    assert apartment_application.contract.status == ContractStatus.DECLINED
    assert apartment_application.contract.landlord_declined_on == declined_on
    assert apartment_application.contract.landlord_declined
コード例 #15
0
def test_tenant_apply_for_apartment_if_previous_one_failed_ok(
    session: Session,
    application: Application,
    failed_apartment_application: ApartmentApplication,
):
    assert failed_apartment_application.status == ApartmentApplicationStatus.FAILED
    assert (session.query(ApartmentApplication).filter(
        ApartmentApplication.tenant_id ==
        failed_apartment_application.tenant_id).filter(
            ApartmentApplication.apartment_id ==
            failed_apartment_application.apartment_id).count() == 1)
    second_app = application.apply_for_apartment(
        session,
        failed_apartment_application.tenant,
        failed_apartment_application.apartment,
    )
    session.expire_all()
    assert (session.query(ApartmentApplication).filter(
        ApartmentApplication.tenant_id ==
        failed_apartment_application.tenant_id).filter(
            ApartmentApplication.apartment_id ==
            failed_apartment_application.apartment_id).count() == 2)
    assert (session.query(ApartmentApplication).get(
        second_app.id).status == ApartmentApplicationStatus.NEW)
コード例 #16
0
def test_update_user_profile_information(client: TestClient, user: User,
                                         user_auth_header: dict,
                                         session: Session):
    new_user_first_name = "some name"
    new_user_last_name = "some last name"
    new_gender = Gender.FEMALE
    assert user.first_name != new_user_first_name
    assert user.last_name != new_user_last_name
    response = client.put(
        "/api/me/",
        headers=user_auth_header,
        json={
            "firstName": new_user_first_name,
            "lastName": new_user_last_name,
            "email": user.email,
            "phoneNumber": user.phone_number,
            "dob": str(user.dob) if user.dob else None,
            "city": user.city,
            "gender": new_gender,
        },
    )
    result = response.json()
    assert response.status_code == 200
    assert "firstName" in result
    assert "lastName" in result
    assert "email" in result
    assert "id" in result
    assert "phoneNumber" in result
    assert "dob" in result
    assert "description" in result
    assert "city" in result
    assert "gender" in result
    session.expire_all()
    xuser = session.query(User).get(user.id)
    assert xuser.first_name == new_user_first_name
    assert xuser.last_name == new_user_last_name
コード例 #17
0
# changed.
#     For persistent instances result by query(), they are still persistent
# but expired, which means that qualify their attributes will reload them by
# emitting a query.
#     All objects not expunged are fully expired.
################################################################################
session.rollback()

################################################################################
#                               expire
# expire erase instances' attributes, and when those attributes are next
# accessed, a query is emitted. Only persistent instances has expired state.
################################################################################

session.expire(user)
session.expire_all()

################################################################################
#                             manage relationship
#     emit a query and load relationship objects during the first qualification
# if no eager load is applied.
################################################################################

# load ########################################################
# may emit a quer
addresses = user.addresses

# eager load through left join
session.query(User).options('addresses')

# eager load with join. cause the inner join followed by left outer join.
コード例 #18
0
# changed.
#     For persistent instances result by query(), they are still persistent
# but expired, which means that qualify their attributes will reload them by
# emitting a query.
#     All objects not expunged are fully expired.
################################################################################
session.rollback() 

################################################################################
#                               expire
# expire erase instances' attributes, and when those attributes are next
# accessed, a query is emitted. Only persistent instances has expired state.
################################################################################

session.expire(user)
session.expire_all() 


################################################################################
#                             manage relationship
#     emit a query and load relationship objects during the first qualification
# if no eager load is applied.
################################################################################

# load ########################################################
# may emit a quer
addresses = user.addresses

# eager load through left join
session.query(User).options('addresses')