def test_save_cache_ok(service: UpdateReservationCache, context: Context,
                       house, room_type):
    service._cache_repo = Mock(save=Mock(return_value=True))
    context.house = house
    context.cached_reservations = [
        CachedReservation(
            pk='111-1',
            reservation_id=111,
            grid='roomtype',
            grid_id=room_type.id,
            checkin=datetime.datetime.combine(datetime.date.today(),
                                              datetime.time(14)),
            checkout=datetime.datetime.combine(
                datetime.date.today() + datetime.timedelta(days=1),
                datetime.time(11)),
        )
    ]

    result = service.save_cache(context)
    assert is_successful(result)
def test_save_cache_error(service: UpdateReservationCache, context: Context,
                          house, room_type):
    service._cache_repo = Mock(save=Mock(side_effect=RuntimeError('ERR')))
    context.house = house
    context.cached_reservations = [
        CachedReservation(
            pk='111-1',
            reservation_id=111,
            grid='roomtype',
            grid_id=room_type.id,
            checkin=datetime.datetime.combine(datetime.date.today(),
                                              datetime.time(14)),
            checkout=datetime.datetime.combine(
                datetime.date.today() + datetime.timedelta(days=1),
                datetime.time(11)),
        )
    ]

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