def test_check_reservation_verified(service: AcceptReservationChanges,
                                    context: Context, house, reservation):
    context.house = house
    context.source = attr.evolve(reservation, is_verified=True)

    result = service.check_reservation(context)
    assert is_successful(result)
def test_check_reservation_ok(service: AcceptReservationChanges,
                              context: Context, house, reservation):
    context.house = house
    context.source = reservation

    result = service.check_reservation(context)
    assert is_successful(result)
def test_check_reservation_room_close(service: AcceptReservationChanges,
                                      context: Context, house, reservation):
    context.house = house
    context.source = attr.evolve(reservation, status=ReservationStatuses.CLOSE)

    result = service.check_reservation(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_reservation
def test_check_reservation_manual(service: AcceptReservationChanges,
                                  context: Context, house, reservation):
    context.house = house
    context.source = attr.evolve(reservation, source=ReservationSources.MANUAL)

    result = service.check_reservation(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_reservation
def test_select_reservation_missed_pk(service: AcceptReservationChanges,
                                      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
def test_check_reservation_wrong_house(service: AcceptReservationChanges,
                                       context: Context, house, reservation):
    context.house = house
    context.source = attr.evolve(reservation, house_id=999)

    result = service.check_reservation(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_reservation
def test_accept_changes_ok(service: AcceptReservationChanges, context: Context,
                           house, reservation):
    _reservation = attr.evolve(reservation, is_verified=True)
    service._reservations_repo = Mock(accept=Mock(
        return_value=Some(_reservation)))
    context.house = house
    context.source = reservation

    result = service.accept_changes(context)
    assert is_successful(result)
    assert result.unwrap().reservation == _reservation
def test_accept_changes_fail(service: AcceptReservationChanges,
                             context: Context, house, reservation):
    service._reservations_repo = Mock(accept=Mock(return_value=Nothing))
    context.house = house
    context.source = reservation

    result = service.accept_changes(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.error
    assert result.failure().error.startswith(
        'Error accept changes for Reservation ID=')
def test_accept_changes_error(service: AcceptReservationChanges,
                              context: Context, house, reservation):
    service._reservations_repo = Mock(accept=Mock(
        side_effect=RuntimeError('ERR')))
    context.house = house
    context.source = reservation

    result = service.accept_changes(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.error
    assert str(result.failure().exc) == 'ERR'
def test_accept_changes_for_verified(service: AcceptReservationChanges,
                                     context: Context, house, reservation):
    _reservation = attr.evolve(reservation, is_verified=True)
    service._reservations_repo = Mock(accept=Mock(
        side_effect=RuntimeError('ERR')))
    context.house = house
    context.source = _reservation

    result = service.accept_changes(context)
    assert is_successful(result)
    assert result.unwrap().reservation == _reservation
def test_select_reservation_ok(service: AcceptReservationChanges,
                               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().source == reservation
def test_select_reservation_fail(service: AcceptReservationChanges,
                                 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
def test_select_reservation_error(service: AcceptReservationChanges,
                                  context: Context, house):
    service._reservations_repo = Mock(get=Mock(
        side_effect=RuntimeError('ERR')))
    context.house = house

    result = service.select_reservation(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.error
    assert str(result.failure().exc) == 'ERR'
def test_missed_house_id(service: AcceptReservationChanges, context: Context):
    context.house_id = None

    result = service.select_house(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_house
def context(house, reservation, user) -> Context:
    return Context(house_id=house.id,
                   pk=reservation.id,
                   user=user,
                   price_ids=[311, 313])