Skip to content

Commit

Permalink
Add missing coverage (betodealmeida#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida authored Jun 4, 2024
1 parent 69fa7bf commit 70a60df
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/shillelagh/adapters/api/generic_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def get_data( # pylint: disable=unused-argument, too-many-arguments
response = self._session.get(self.uri)
payload = response.json()
if not response.ok:
raise ProgrammingError(f'Error: {payload["message"]}')
raise ProgrammingError(f'Error: {payload["error"]["message"]}')

for i, row in enumerate(jsonpath.findall(self.path, payload)):
row = {
Expand Down
6 changes: 4 additions & 2 deletions tests/adapters/api/generic_json_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,14 @@ def test_generic_json(requests_mock: Mocker) -> None:

requests_mock.get(
"https://example.org/data.json",
json={"message": "An error occurred"},
json={
"error": {"code": 1002, "message": "API key is invalid or not provided."},
},
status_code=500,
)
with pytest.raises(ProgrammingError) as excinfo:
list(cursor.execute(sql))
assert str(excinfo.value) == "Error: An error occurred"
assert str(excinfo.value) == "Error: API key is invalid or not provided."


def test_generic_json_complex_type(requests_mock: Mocker) -> None:
Expand Down

0 comments on commit 70a60df

Please sign in to comment.