From a3c005940682c9a4a965bdc5eb80d655f7b20a69 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 16 Oct 2024 09:16:20 +0000 Subject: [PATCH] Test for raising error --- inventree/base.py | 8 +++++++- test/test_order.py | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/inventree/base.py b/inventree/base.py index ea247d3..4a56c48 100644 --- a/inventree/base.py +++ b/inventree/base.py @@ -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 [] diff --git a/test/test_order.py b/test/test_order.py index c7111d5..0836567 100644 --- a/test/test_order.py +++ b/test/test_order.py @@ -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)