def test_select_rate_plan_ok(service: CalculateNewReservation, context: Context, house, rate_plan): service._prices_repo = Mock(get_plan=Mock(return_value=Some(rate_plan))) context.house = house result = service.select_rate_plan(context) assert is_successful(result) assert result.unwrap().rate_plan == rate_plan
def test_select_rate_plan_fail(service: CalculateNewReservation, context: Context, house): service._prices_repo = Mock(get_plan=Mock(return_value=Nothing)) context.house = house result = service.select_rate_plan(context) assert not is_successful(result) assert result.failure().failure == ReservationErrors.missed_rateplan
def test_missed_plan_id(service: CalculateNewReservation, context: Context, house): context.house = house context.plan_id = None result = service.select_rate_plan(context) assert not is_successful(result) assert result.failure().failure == ReservationErrors.missed_rateplan
def test_select_rate_plan_error(service: CalculateNewReservation, context: Context, house): service._prices_repo = Mock(get_plan=Mock(side_effect=RuntimeError("ERR"))) context.house = house result = service.select_rate_plan(context) assert not is_successful(result) assert result.failure().failure == ReservationErrors.error assert str(result.failure().exc) == "ERR"