示例#1
0
def test_check_reservation_wrong_house(service: ShowPricesForm,
                                       context: Context, house, reservation):
    context.house = house
    context.reservation = attr.evolve(reservation, house_id=999)

    result = service.check_reservation(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_reservation
示例#2
0
def test_select_reservation_room_ok(service: ShowPricesForm, context: Context,
                                    house, reservation):
    context.house = house
    context.reservation = reservation

    result = service.select_reservation_room(context)
    assert is_successful(result)
    assert result.unwrap().reservation_room == reservation.rooms[0]
示例#3
0
def test_select_reservation_missed_pk(service: ShowPricesForm,
                                      context: Context, house):
    context.house = house
    context.pk = None

    result = service.select_reservation(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_reservation
示例#4
0
def test_check_reservation_canceled(service: ShowPricesForm, context: Context,
                                    house, reservation):
    context.house = house
    context.reservation = attr.evolve(reservation,
                                      status=ReservationStatuses.CANCEL)

    result = service.check_reservation(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_reservation
示例#5
0
def test_select_reservation_room_wrong_id(service: ShowPricesForm,
                                          context: Context, house,
                                          reservation):
    context.house = house
    context.reservation = reservation
    context.room_id = 999

    result = service.select_reservation_room(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_reservation
示例#6
0
def test_select_rooms_ok(service: ShowPricesForm, context: Context, house,
                         room):
    service._rooms_repo = Mock(select=Mock(return_value=[room]))
    context.house = house

    result = service.select_rooms(context)
    assert is_successful(result)
    assert result.unwrap().rooms == [room]
示例#7
0
def test_select_rooms_error(service: ShowPricesForm, context: Context, house):
    service._rooms_repo = Mock(select=Mock(side_effect=RuntimeError('ERR')))
    context.house = house

    result = service.select_rooms(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.error
    assert str(result.failure().exc) == 'ERR'
示例#8
0
def test_select_rate_plans_ok(service: ShowPricesForm, context: Context, house,
                              rate_plan):
    service._prices_repo = Mock(select_plans=Mock(return_value=[rate_plan]))
    context.house = house

    result = service.select_rate_plans(context)
    assert is_successful(result)
    assert result.unwrap().rate_plans == [rate_plan]
示例#9
0
def test_select_reservation_ok(service: ShowPricesForm, context: Context,
                               house, reservation):
    service._reservations_repo = Mock(get=Mock(return_value=Some(reservation)))
    context.house = house

    result = service.select_reservation(context)
    assert is_successful(result)
    assert result.unwrap().reservation == reservation
示例#10
0
def test_select_reservation_fail(service: ShowPricesForm, context: Context,
                                 house):
    service._reservations_repo = Mock(get=Mock(return_value=Nothing))
    context.house = house

    result = service.select_reservation(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_reservation
示例#11
0
def test_select_cancellation_policies_ok(service: ShowPricesForm,
                                         context: Context, house):
    policy_1 = Policy(id=101, house_id=house.id, name='P1')
    policy_2 = Policy(id=102, house_id=house.id, name='P2')
    service._policies_repo = Mock(select=Mock(
        return_value=[policy_1, policy_2]))
    context.house = house

    result = service.select_cancellation_policies(context)
    assert is_successful(result)
    assert result.unwrap().policies == [policy_1, policy_2]
示例#12
0
def test_missed_house_id(service: ShowPricesForm, context: Context):
    context.house_id = None

    result = service.select_house(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_house
示例#13
0
def context(house, reservation, user) -> Context:
    return Context(house_id=house.id,
                   pk=reservation.id,
                   room_id=reservation.rooms[0].id,
                   user=user)