def test_select_reservations_ok(service: UpdateReservationCache, context: Context, house, reservation): service._reservations_repo = Mock(select=Mock(return_value=[reservation])) context.house = house result = service.select_reservations(context) assert is_successful(result) assert result.unwrap().reservations == [reservation]
def test_select_reservations_error(service: UpdateReservationCache, context: Context, house): service._reservations_repo = Mock(select=Mock( side_effect=RuntimeError('ERR'))) context.house = house result = service.select_reservations(context) assert not is_successful(result) assert result.failure().failure == ReservationErrors.error assert str(result.failure().exc) == 'ERR'
def test_success(service: UpdateReservationCache, house, reservation, rate_plan, user): service._houses_repo = Mock(get=Mock(return_value=Some(house))) service._reservations_repo = Mock(select=Mock(return_value=[reservation])) service._cache_repo = Mock(save=Mock(return_value=True), delete=Mock(return_value=None)) service._prices_repo = Mock(select_plans=Mock(return_value=[rate_plan])) service._members_repo = Mock(get_bot_user=Mock(return_value=Some(user))) service.get_rpc_api = Mock(return_value=Mock( select_invoices_for_order=Mock(return_value=[ Mock(id=987, amount_total=50.0, amount_residual=20.0) ]))) result = service.execute(house_id=house.id) assert is_successful(result)