|
1 | | -import pytest |
2 | | -import tests.common as common |
3 | | -import nomad |
4 | 1 | import os |
| 2 | + |
| 3 | +import mock |
| 4 | +import pytest |
| 5 | +import requests |
5 | 6 | import responses |
6 | 7 |
|
| 8 | +import nomad |
| 9 | +import tests.common as common |
| 10 | + |
7 | 11 |
|
8 | 12 | def test_base_region_qs(): |
9 | 13 | 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(): |
46 | 50 | j = n.job.deregister_job("example") |
47 | 51 |
|
48 | 52 |
|
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) |
54 | 80 |
|
55 | 81 |
|
56 | 82 | @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