def test_select_price_restrictions_error(service: CalculateNewReservation, context: Context, house, room_type, rate_plan, rate): service._prices_repo = Mock(select_restrictions=Mock( side_effect=RuntimeError("ERR"))) context.house = house context.room_type = room_type context.rate_plan = rate_plan context.rate = rate result = service.select_price_restrictions(context) assert not is_successful(result) assert result.failure().failure == ReservationErrors.error assert str(result.failure().exc) == "ERR"
def test_select_price_restrictions_ok(service: CalculateNewReservation, context: Context, house, room_type, rate_plan, rate): period = [ datetime.date.today(), datetime.date.today() + datetime.timedelta(days=1) ] service._prices_repo = Mock(select_restrictions=Mock(return_value={ period[0]: Decimal(50), period[1]: Decimal(50) })) context.house = house context.room_type = room_type context.rate_plan = rate_plan context.rate = rate result = service.select_price_restrictions(context) assert is_successful(result) assert result.unwrap().price_restrictions == { period[0]: Decimal(50), period[1]: Decimal(50) }