def test_bad_hostname(monkeypatch, monkeyed_requests_get_404): monkeypatch.setattr("requests.get", monkeyed_requests_get_404) with pytest.raises(CantGetConfig): get_config() with pytest.raises(CantGetConfig): get_all() try: get_config() except CantGetConfig as e: assert e.code == 404 assert e.text == ""
def test_https_url(monkeypatch, monkeyed_requests_get_https): """ this doesn't really test https; because of all the cert stuff, however it tests that the url gets formed correctly in the presence of this env variable """ monkeypatch.setattr("requests.get", monkeyed_requests_get_https) monkeypatch.setenv("DCAE_CA_CERTPATH", "1") assert get_config() == {"key_to_your_heart": 666} assert get_all() == { "config": { "key_to_your_heart": 666 }, "dti": { "some amazing": "dti stuff" }, "policies": { "event": { "foo": "bar" }, "items": [{ "foo2": "bar2" }] }, "otherkey": { "foo3": "bar3" }, }
def test_http(monkeypatch, monkeyed_requests_get): monkeypatch.setattr("requests.get", monkeyed_requests_get) assert get_config() == {"key_to_your_heart": 666} assert get_all() == { "config": { "key_to_your_heart": 666 }, "dti": { "some amazing": "dti stuff" }, "policies": { "event": { "foo": "bar" }, "items": [{ "foo2": "bar2" }] }, "otherkey": { "foo3": "bar3" }, }
def _loadconfig(self): self._config = get_config()
from onap_dcae_cbs_docker_client import client client.get_config() client.get_all()
def test_badenv(monkeypatch): monkeypatch.delenv("CONFIG_BINDING_SERVICE") with pytest.raises(ENVsMissing): get_config() with pytest.raises(ENVsMissing): get_all()
def test_unreachable(monkeypatch, monkeyed_requests_get_unreachable): monkeypatch.setattr("requests.get", monkeyed_requests_get_unreachable) with pytest.raises(CBSUnreachable): get_config() with pytest.raises(CBSUnreachable): get_all()