Files
openbb-invest-api/tests/test_openbb_service.py
Yaojia Wang a57a6835c5 test: fix broken tests after refactor
- Update test_openbb_service to import from obb_utils (to_list,
  first_or_empty) instead of removed _to_dicts/_first_or_empty
- Update test_stock_upgrades to mock openbb_service instead of
  finnhub_service (upgrades moved to yfinance)
2026-03-19 17:47:36 +01:00

48 lines
1.1 KiB
Python

from obb_utils import to_list, first_or_empty
class MockModel:
def __init__(self, data: dict):
self._data = data
def model_dump(self):
return self._data
class MockOBBject:
def __init__(self, results):
self.results = results
class TestToList:
def test_none_result(self):
assert to_list(None) == []
def test_none_results(self):
obj = MockOBBject(results=None)
assert to_list(obj) == []
def test_list_results(self):
obj = MockOBBject(results=[
MockModel({"a": 1}),
MockModel({"b": 2}),
])
result = to_list(obj)
assert len(result) == 2
assert result[0] == {"a": 1}
def test_single_result(self):
obj = MockOBBject(results=MockModel({"x": 42}))
result = to_list(obj)
assert result == [{"x": 42}]
class TestFirstOrEmpty:
def test_empty(self):
assert first_or_empty(None) == {}
def test_with_data(self):
obj = MockOBBject(results=[MockModel({"price": 150.0})])
result = first_or_empty(obj)
assert result == {"price": 150.0}