Skip to content

Commit

Permalink
Test for raising error
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingersGat committed Oct 16, 2024
1 parent 7fc87a9 commit a3c0059
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion inventree/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,13 @@ def list(cls, api, **kwargs):
except requests.exceptions.HTTPError as e:
logger.error(f"Error during list request: {e}")
# Return an empty list
return []

raise_error = kwargs.get('raise_error', False)

if raise_error:
raise e
else:
return []

if response is None:
return []
Expand Down
8 changes: 8 additions & 0 deletions test/test_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,14 @@ def test_invalid_list(self):
results = order.PurchaseOrder.list(self.api, project_code=999999999)
self.assertEqual(len(results), 0)

# Try the same again, but raise the eror
with self.assertRaises(HTTPError):
results = order.PurchaseOrder.list(
self.api,
project_code=999999999,
raise_error=True
)

# Find a valid project code
n = ProjectCode.count(self.api)

Expand Down

0 comments on commit a3c0059

Please sign in to comment.