def test_select_house_ok(service: AcceptHoldReservation, context: Context,
                         house):
    service._houses_repo = Mock(get=Mock(return_value=Some(house)))

    result = service.select_house(context)
    assert is_successful(result)
    assert result.unwrap().house == house
def test_select_house_error(service: AcceptHoldReservation, context: Context):
    service._houses_repo = Mock(get=Mock(side_effect=RuntimeError('ERR')))

    result = service.select_house(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.error
    assert str(result.failure().exc) == 'ERR'
def test_success_for_accepted(service: AcceptHoldReservation, house,
                              reservation, user):
    _reservation = attr.evolve(reservation, status=ReservationStatuses.NEW)
    service._houses_repo = Mock(get=Mock(return_value=Some(house)))
    service._reservations_repo = Mock(get=Mock(
        return_value=Some(_reservation)))
    service.get_rpc_api = Mock(return_value=Mock(confirm_quotation=Mock(
        return_value=None)))

    result = service.execute(house.id, reservation.id, user)
    assert is_successful(result)
    assert result.unwrap()
def test_select_house_fail(service: AcceptHoldReservation, context: Context):
    service._houses_repo = Mock(get=Mock(return_value=Nothing))

    result = service.select_house(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_house