Skip to content

Commit f24cf31

Browse files
add tests to ensure no regression for bug
1 parent ff6e8dc commit f24cf31

1 file changed

Lines changed: 34 additions & 8 deletions

File tree

tests/test_base.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
import pytest
2-
import tests.common as common
3-
import nomad
41
import os
2+
3+
import mock
4+
import pytest
5+
import requests
56
import responses
67

8+
import nomad
9+
import tests.common as common
10+
711

812
def test_base_region_qs():
913
n = nomad.Nomad(host=common.IP, port=common.NOMAD_PORT, verify=False, token=common.NOMAD_TOKEN, region="random")
@@ -46,11 +50,33 @@ def test_base_delete_connection_error():
4650
j = n.job.deregister_job("example")
4751

4852

49-
def test_base_raise_exception_():
50-
n = nomad.Nomad(
51-
host="162.16.10.102", port=common.NOMAD_PORT, timeout=0.001, verify=False)
52-
with pytest.raises(nomad.api.exceptions.BaseNomadException):
53-
j = n.job.deregister_job("example")
53+
@mock.patch("nomad.api.base.requests.Session")
54+
def test_base_raise_exception_not_requests_response_object(mock_requests):
55+
mock_requests().delete.side_effect = [requests.RequestException()]
56+
57+
try:
58+
n = nomad.Nomad(
59+
host="162.16.10.102",
60+
port=common.NOMAD_PORT,
61+
timeout=0.001,
62+
verify=False
63+
)
64+
65+
_ = n.job.deregister_job("example")
66+
67+
except nomad.api.exceptions.BaseNomadException as err:
68+
assert hasattr(err, "text") is False
69+
assert isinstance(err.nomad_resp, requests.RequestException)
70+
assert "raised due" in str(err)
71+
72+
73+
def test_base_raise_exception_is_requests_response_object(nomad_setup):
74+
try:
75+
_ = nomad_setup.job.deregister_job("example")
76+
except nomad.api.exceptions.BaseNomadException as err:
77+
assert hasattr(err, "text") is True
78+
assert isinstance(err.nomad_resp, requests.Response)
79+
assert "raised with" in str(err)
5480

5581

5682
@pytest.mark.skipif(tuple(int(i) for i in os.environ.get("NOMAD_VERSION").split(".")) < (0, 7, 0), reason="Nomad dispatch not supported")

0 commit comments

Comments
 (0)