def test_accept_reservation_fail(service: UpdateRoomClose, context: Context,
                                 house, room, reservation):
    service._reservations_repo = Mock(accept=Mock(return_value=Nothing))
    context.house = house
    context.room = room
    context.reservation = reservation

    result = service.accept_reservation(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.save
    assert result.failure().error.startswith("Error accept Reservation ID=")
def test_accept_reservation_ok(service: UpdateRoomClose, context: Context,
                               house, room, reservation):
    reservation = attr.evolve(reservation, is_verified=True)
    service._reservations_repo = Mock(accept=Mock(
        return_value=Some(reservation)))
    context.house = house
    context.room = room
    context.reservation = attr.evolve(reservation, is_verified=False)

    result = service.accept_reservation(context)
    assert is_successful(result)
    assert result.unwrap().reservation == reservation
def test_accept_reservation_error(service: UpdateRoomClose, context: Context,
                                  house, room, reservation):
    service._reservations_repo = Mock(accept=Mock(
        side_effect=RuntimeError("ERR")))
    context.house = house
    context.room = room
    context.reservation = reservation

    result = service.accept_reservation(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.error
    assert str(result.failure().exc) == "ERR"