summaryrefslogtreecommitdiff
path: root/test/test_api.py
diff options
context:
space:
mode:
authorScott Bahling <sbahling@suse.com>2020-02-13 11:43:10 +0100
committerScott Bahling <sbahling@suse.com>2020-02-13 11:43:10 +0100
commit650c9e5853ea57b985df1e9d97288a7d879a2e4f (patch)
tree56d4d974fc16c6d115c820de474e7218cb50dee0 /test/test_api.py
parent7806de5f05bbc153b8405f1e693e1ae202e2a54c (diff)
downloadobsapi-650c9e5853ea57b985df1e9d97288a7d879a2e4f.tar.gz
obsapi-650c9e5853ea57b985df1e9d97288a7d879a2e4f.tar.xz
obsapi-650c9e5853ea57b985df1e9d97288a7d879a2e4f.zip
Implement general exception handling
We trap the low level OBS api calls via a callback and check for success. If error returned, parse the OBS error response and raise an exception.
Diffstat (limited to 'test/test_api.py')
-rw-r--r--test/test_api.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/test_api.py b/test/test_api.py
index 09b2806..f6ccdf4 100644
--- a/test/test_api.py
+++ b/test/test_api.py
@@ -204,6 +204,15 @@ def locked_package_meta():
</package>"""
+@pytest.fixture
+def error_status():
+ return """<status code="Error">
+ <summary>This is the summary</summary>
+ <details>Here are the details</details>
+ </status>
+ """
+
+
def test_callback(requests_mock):
"""
Test that api callback works and returns a reference to
@@ -218,6 +227,15 @@ def test_callback(requests_mock):
assert api.lastapi is api.source
+def test_call_status_on_error(requests_mock, error_status):
+ requests_mock.get(rmock.ANY, text=error_status, status_code=404)
+ with pytest.raises(Exception):
+ api.ls()
+ assert api.call_status.code == "Error"
+ assert api.call_status.summary == "This is the summary"
+ assert api.call_status.details == "Here are the details"
+
+
def test_get_project_meta(requests_mock):
matcher = prj_meta_re
text = '<project/>'