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_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_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_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