Skip to content

Commit 2429cb4

Browse files
committed
tests pass
1 parent e7ebeef commit 2429cb4

16 files changed

+110
-60
lines changed

run_tests.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
# Run unit tests by default
44
if [ "$1" == "--all" ]; then
55
echo "Running all tests..."
6-
python -m pytest
6+
python3 -m pytest
77
elif [ "$1" == "--integration" ]; then
88
echo "Running integration tests..."
9-
python -m pytest -m "integration"
9+
python3 -m pytest -m "integration"
1010
elif [ "$1" == "--coverage" ]; then
1111
echo "Running tests with coverage report..."
12-
python -m pytest --cov=src --cov-report=term-missing
12+
python3 -m pytest --cov=src --cov-report=term-missing
1313
elif [ "$1" == "--models" ]; then
1414
echo "Running model tests only..."
15-
python -m pytest tests/test_models.py tests/test_model_validation.py
15+
python3 -m pytest tests/test_models.py tests/test_model_validation.py
1616
elif [ "$1" == "--edge-cases" ]; then
1717
echo "Running edge case tests only..."
18-
python -m pytest tests/test_edge_cases.py
18+
python3 -m pytest tests/test_edge_cases.py
1919
elif [ "$1" == "--performance" ]; then
2020
echo "Running performance tests..."
2121
python -m pytest -m "performance"
2222
else
2323
echo "Running unit tests only..."
24-
python -m pytest -m "not integration and not performance"
24+
python3 -m pytest -m "not integration and not performance"
2525
fi

src/borsdata_client/client.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,14 @@ def _get(self, endpoint: str, params: Optional[Dict[str, Any]] = None) -> Dict[s
7070

7171
try:
7272
response = self._client.get(f"{self.BASE_URL}{endpoint}", params=params)
73-
response.raise_for_status()
73+
response.raise_for_status() # This will raise an HTTPError for 4XX/5XX responses
7474
return response.json()
75-
except httpx.HTTPError as e:
76-
raise BorsdataClientError(f"HTTP request failed: {str(e)}") from e
77-
except ValueError as e:
78-
raise BorsdataClientError(f"Failed to parse JSON response: {str(e)}") from e
75+
except httpx.HTTPStatusError as e:
76+
error_msg = str(e)
77+
status_code = e.response.status_code
78+
raise BorsdataClientError(f"API request failed with status code {status_code}: {error_msg}") from e
79+
except Exception as e:
80+
raise BorsdataClientError(f"API request failed: {str(e)}") from e
7981

8082
def get_branches(self) -> List[Branch]:
8183
"""Get all branches/industries.

tests/conftest.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,28 @@ def mock_get(self, endpoint: str, params: Dict[str, Any] = None) -> Dict[str, An
4444
with open(fixture_path, 'r') as f:
4545
return json.load(f)
4646
else:
47-
# If no fixture file exists, return an empty response
48-
return {}
47+
# If no fixture file exists, return an appropriate empty response
48+
# based on the endpoint
49+
if endpoint == "/instruments/kpis/metadata":
50+
return {"kpiHistoryMetadatas": []}
51+
elif endpoint.startswith("/holdings/insider"):
52+
return {"list": []}
53+
elif endpoint.startswith("/holdings/shorts"):
54+
return {"list": []}
55+
elif endpoint.startswith("/holdings/buyback"):
56+
return {"list": []}
57+
elif endpoint.startswith("/instruments/description"):
58+
return {"list": []}
59+
elif endpoint.startswith("/instruments/report/calendar"):
60+
return {"list": []}
61+
elif endpoint.startswith("/instruments/dividend/calendar"):
62+
return {"list": []}
63+
elif endpoint.startswith("/instruments/stockprices/date") or endpoint.startswith("/instruments/stockprices/global/date"):
64+
return {"values": []}
65+
elif endpoint == "/translationmetadata":
66+
return {"branches": [], "sectors": [], "countries": []}
67+
else:
68+
return {}
4969

5070
# Replace the _get method with our mock
5171
monkeypatch.setattr(client, '_get', mock_get.__get__(client))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"list": [{"insId": 1, "values": [{"change": 1000, "changeProc": 0.01, "price": 100.0, "currency": "SEK", "shares": 10000, "sharesProc": 0.05, "date": "2023-01-01T12:00:00"}], "error": null}]}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"list": [{"insId": 1, "values": [{"misc": false, "ownerName": "Test Owner", "ownerPosition": "CEO", "equityProgram": false, "shares": 10000, "price": 100.0, "amount": 1000000.0, "currency": "SEK", "transactionType": 1, "verificationDate": "2023-01-01T12:00:00", "transactionDate": "2023-01-01T10:00:00"}], "error": null}]}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"list": [{"insId": 1, "values": [{"positionHolder": "Test Holder", "position": 0.5, "date": "2023-01-01T12:00:00"}], "error": null}]}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"list": [{"insId": 1, "languageCode": "en", "text": "Test description", "error": null}]}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"list": [{"insId": 1, "values": [{"amountPaid": 1.5, "currencyShortName": "SEK", "distributionFrequency": 1, "excludingDate": "2023-04-15T00:00:00", "dividendType": 1}], "error": null}]}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"kpiMetadatas": [{"kpiId": 1, "nameSv": "KPI 1 (SV)", "nameEn": "KPI 1 (EN)", "format": "0.00", "isString": false}, {"kpiId": 2, "nameSv": "KPI 2 (SV)", "nameEn": "KPI 2 (EN)", "format": "0.00%", "isString": false}]}
1+
{"kpiHistoryMetadatas": [{"kpiId": 1, "nameSv": "KPI 1 (SV)", "nameEn": "KPI 1 (EN)", "format": "0.00", "isString": false}, {"kpiId": 2, "nameSv": "KPI 2 (SV)", "nameEn": "KPI 2 (EN)", "format": "0.00%", "isString": false}]}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"list": [{"insId": 1, "values": [{"releaseDate": "2023-04-01T08:00:00", "reportType": "Q1"}], "error": null}]}

0 commit comments

Comments
 (0)