Skip to content

Commit e4c886f

Browse files
committed
changes to tests
1 parent 2429cb4 commit e4c886f

12 files changed

+135
-60
lines changed

run_all_tests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# run_all_tests.py
2+
import os
3+
import subprocess
4+
from dotenv import load_dotenv
5+
6+
# Load environment variables from .env file
7+
load_dotenv()
8+
9+
# Run all tests
10+
subprocess.run(["python", "-m", "pytest"])

run_tests.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
#!/bin/bash
22

3-
# Run unit tests by default
3+
# Load environment variables from .env file
4+
if [ -f .env ]; then
5+
export $(grep -v '^#' .env | xargs)
6+
fi
7+
8+
# Run tests
49
if [ "$1" == "--all" ]; then
510
echo "Running all tests..."
6-
python3 -m pytest
11+
python -m pytest
712
elif [ "$1" == "--integration" ]; then
813
echo "Running integration tests..."
9-
python3 -m pytest -m "integration"
14+
python -m pytest tests/test_integration.py -v
1015
elif [ "$1" == "--coverage" ]; then
1116
echo "Running tests with coverage report..."
1217
python3 -m pytest --cov=src --cov-report=term-missing
@@ -18,8 +23,8 @@ elif [ "$1" == "--edge-cases" ]; then
1823
python3 -m pytest tests/test_edge_cases.py
1924
elif [ "$1" == "--performance" ]; then
2025
echo "Running performance tests..."
21-
python -m pytest -m "performance"
26+
python -m pytest tests/test_performance.py -v
2227
else
23-
echo "Running unit tests only..."
24-
python3 -m pytest -m "not integration and not performance"
28+
echo "Running unit tests..."
29+
python -m pytest tests/test_client.py tests/test_models.py tests/test_errors.py tests/test_edge_cases.py tests/test_model_validation.py
2530
fi

src/borsdata_client/models.py

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,17 @@ class StockPriceLastValue(BaseModel):
269269
l: float = Field(description="Low price")
270270
c: float = Field(description="Closing price")
271271
o: float = Field(description="Opening price")
272-
v: int = Field(description="Volume")
272+
v: Optional[int] = Field(None, description="Volume")
273273

274274

275275
class StockPriceLastResponse(BaseModel):
276276
"""Response model for last stock prices."""
277-
values: List[StockPriceLastValue]
277+
stockPricesList: List[Dict[str, Any]]
278+
279+
@property
280+
def values(self) -> List[StockPriceLastValue]:
281+
"""Convert the stockPricesList to a list of StockPriceLastValue objects."""
282+
return [StockPriceLastValue(**item) for item in self.stockPricesList]
278283

279284

280285
class StockSplit(BaseModel):
@@ -299,6 +304,55 @@ class TranslationItem(BaseModel):
299304

300305
class TranslationMetadataResponse(BaseModel):
301306
"""Response model for translation metadata."""
302-
branches: Optional[List[TranslationItem]]
303-
sectors: Optional[List[TranslationItem]]
304-
countries: Optional[List[TranslationItem]]
307+
translationMetadatas: List[Dict[str, Any]]
308+
309+
@property
310+
def branches(self) -> List[TranslationItem]:
311+
"""Get branch translations."""
312+
result = []
313+
for item in self.translationMetadatas:
314+
if item.get("translationKey", "").startswith("L_BRANCH_"):
315+
try:
316+
branch_id = int(item.get("translationKey", "").split("_")[-1])
317+
result.append(TranslationItem(
318+
id=branch_id,
319+
nameSv=item.get("nameSv"),
320+
nameEn=item.get("nameEn")
321+
))
322+
except (ValueError, IndexError):
323+
pass
324+
return result
325+
326+
@property
327+
def sectors(self) -> List[TranslationItem]:
328+
"""Get sector translations."""
329+
result = []
330+
for item in self.translationMetadatas:
331+
if item.get("translationKey", "").startswith("L_SECTOR_"):
332+
try:
333+
sector_id = int(item.get("translationKey", "").split("_")[-1])
334+
result.append(TranslationItem(
335+
id=sector_id,
336+
nameSv=item.get("nameSv"),
337+
nameEn=item.get("nameEn")
338+
))
339+
except (ValueError, IndexError):
340+
pass
341+
return result
342+
343+
@property
344+
def countries(self) -> List[TranslationItem]:
345+
"""Get country translations."""
346+
result = []
347+
for item in self.translationMetadatas:
348+
if item.get("translationKey", "").startswith("L_COUNTRY_"):
349+
try:
350+
country_id = int(item.get("translationKey", "").split("_")[-1])
351+
result.append(TranslationItem(
352+
id=country_id,
353+
nameSv=item.get("nameSv"),
354+
nameEn=item.get("nameEn")
355+
))
356+
except (ValueError, IndexError):
357+
pass
358+
return result

tests/conftest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ def mock_get(self, endpoint: str, params: Dict[str, Any] = None) -> Dict[str, An
6161
elif endpoint.startswith("/instruments/dividend/calendar"):
6262
return {"list": []}
6363
elif endpoint.startswith("/instruments/stockprices/date") or endpoint.startswith("/instruments/stockprices/global/date"):
64-
return {"values": []}
64+
return {"stockPricesList": []}
65+
elif endpoint.startswith("/instruments/stockprices/last") or endpoint.startswith("/instruments/stockprices/global/last"):
66+
return {"stockPricesList": []}
6567
elif endpoint == "/translationmetadata":
66-
return {"branches": [], "sectors": [], "countries": []}
68+
return {"translationMetadatas": []}
6769
else:
6870
return {}
6971

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"values": [{"i": 1, "d": "2023-01-15", "h": 105.5, "l": 103.0, "c": 104.0, "o": 103.5, "v": 15000}]}
1+
{"stockPricesList": [{"i": 1, "d": "2023-01-15", "h": 105.5, "l": 103.0, "c": 104.0, "o": 103.5, "v": 15000}]}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"values": [{"i": 1001, "d": "2023-01-15", "h": 305.5, "l": 303.0, "c": 304.0, "o": 303.5, "v": 35000}]}
1+
{"stockPricesList": [{"i": 1001, "d": "2023-01-15", "h": 305.5, "l": 303.0, "c": 304.0, "o": 303.5, "v": 35000}]}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"values": [{"i": 1001, "d": "2023-01-15", "h": 305.5, "l": 303.0, "c": 304.0, "o": 303.5, "v": 35000}]}
1+
{"stockPricesList": [{"i": 1001, "d": "2023-01-15", "h": 305.5, "l": 303.0, "c": 304.0, "o": 303.5, "v": 35000}]}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"values": [{"i": 1, "d": "2023-01-15", "h": 105.5, "l": 103.0, "c": 104.0, "o": 103.5, "v": 15000}, {"i": 2, "d": "2023-01-15", "h": 205.5, "l": 203.0, "c": 204.0, "o": 203.5, "v": 25000}]}
1+
{"stockPricesList": [{"i": 1, "d": "2023-01-15", "h": 105.5, "l": 103.0, "c": 104.0, "o": 103.5, "v": 15000}, {"i": 2, "d": "2023-01-15", "h": 205.5, "l": 203.0, "c": 204.0, "o": 203.5, "v": 25000}]}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"branches": [{"id": 1, "nameSv": "Branch 1 (SV)", "nameEn": "Branch 1 (EN)"}], "sectors": [{"id": 10, "nameSv": "Sector 1 (SV)", "nameEn": "Sector 1 (EN)"}], "countries": [{"id": 2, "nameSv": "Country 1 (SV)", "nameEn": "Country 1 (EN)"}]}
1+
{"translationMetadatas": [{"nameSv": "Branch 1 (SV)", "nameEn": "Branch 1 (EN)", "translationKey": "L_BRANCH_1"}, {"nameSv": "Sector 1 (SV)", "nameEn": "Sector 1 (EN)", "translationKey": "L_SECTOR_10"}, {"nameSv": "Country 1 (SV)", "nameEn": "Country 1 (EN)", "translationKey": "L_COUNTRY_2"}]}

tests/test_edge_cases.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ def mock_get(self, endpoint, params=None):
4343
elif endpoint == "/instruments/dividends/calendar":
4444
return {"list": []}
4545
elif endpoint == "/instruments/stockprices/last":
46-
return {"values": []}
46+
return {"stockPricesList": []}
4747
elif endpoint == "/instruments/stockprices/global/last":
48-
return {"values": []}
48+
return {"stockPricesList": []}
4949
elif endpoint.startswith("/instruments/stockprices/"):
50-
return {"values": []}
50+
return {"stockPricesList": []}
5151
elif endpoint.startswith("/instruments/stockprices/global/"):
52-
return {"values": []}
52+
return {"stockPricesList": []}
5353
elif endpoint == "/instruments/stocksplits":
5454
return {"stockSplits": []}
5555
elif endpoint == "/instruments/StockSplits":
@@ -64,6 +64,8 @@ def mock_get(self, endpoint, params=None):
6464
return {"list": []}
6565
elif endpoint == "/instruments/dividend/calendar":
6666
return {"list": []}
67+
elif endpoint == "/translationmetadata":
68+
return {"translationMetadatas": []}
6769
else:
6870
return {}
6971

@@ -104,7 +106,7 @@ def mock_get(endpoint, params=None):
104106
if endpoint.startswith("/instruments/") and endpoint.endswith("/stockprices"):
105107
return {"instrument": 1, "stockPricesList": []}
106108
elif endpoint.startswith("/instruments/stockprices/"):
107-
return {"values": []}
109+
return {"stockPricesList": []}
108110
else:
109111
return {}
110112

0 commit comments

Comments
 (0)