summaryrefslogtreecommitdiffstats
path: root/onap-dcae-cbs-docker-client/tests
diff options
context:
space:
mode:
Diffstat (limited to 'onap-dcae-cbs-docker-client/tests')
-rw-r--r--onap-dcae-cbs-docker-client/tests/conftest.py50
-rw-r--r--onap-dcae-cbs-docker-client/tests/test_client.py22
2 files changed, 54 insertions, 18 deletions
diff --git a/onap-dcae-cbs-docker-client/tests/conftest.py b/onap-dcae-cbs-docker-client/tests/conftest.py
index 05d2eb5..b927412 100644
--- a/onap-dcae-cbs-docker-client/tests/conftest.py
+++ b/onap-dcae-cbs-docker-client/tests/conftest.py
@@ -33,6 +33,18 @@ class FakeResponse:
return self.thejson
+good_resp_all = FakeResponse(
+ status_code=200,
+ thejson={
+ "config": {"key_to_your_heart": 666},
+ "dti": {"some amazing": "dti stuff"},
+ "policies": {"event": {"foo": "bar"}, "items": [{"foo2": "bar2"}]},
+ "otherkey": {"foo3": "bar3"},
+ },
+)
+good_resp_conf = FakeResponse(status_code=200, thejson={"key_to_your_heart": 666})
+
+
@pytest.fixture
def monkeyed_requests_get():
"""
@@ -40,19 +52,10 @@ def monkeyed_requests_get():
"""
def _monkeyed_requests_get(url):
- if url == "http://config_binding_service:10000/service_component_all/mybestfrienddotcom":
- return FakeResponse(
- status_code=200,
- thejson={
- "config": {"key_to_your_heart": 666},
- "dti": {"some amazing": "dti stuff"},
- "policies": {"event": {"foo": "bar"}, "items": [{"foo2": "bar2"}]},
- "otherkey": {"foo3": "bar3"},
- },
- )
-
- elif url == "http://config_binding_service:10000/service_component/mybestfrienddotcom":
- return FakeResponse(status_code=200, thejson={"key_to_your_heart": 666})
+ if url == "http://config-binding-service:10000/service_component_all/testhostname":
+ return good_resp_all
+ elif url == "http://config-binding-service:10000/service_component/testhostname":
+ return good_resp_conf
else:
raise Exception("Unexpected URL {0}!".format(url))
@@ -60,14 +63,31 @@ def monkeyed_requests_get():
@pytest.fixture
+def monkeyed_requests_get_https():
+ """
+ mock for the CBS get
+ """
+
+ def _monkeyed_requests_get_https(url, verify=""):
+ if url == "https://config-binding-service:10443/service_component_all/testhostname":
+ return good_resp_all
+ elif url == "https://config-binding-service:10443/service_component/testhostname":
+ return good_resp_conf
+ else:
+ raise Exception("Unexpected URL {0}!".format(url))
+
+ return _monkeyed_requests_get_https
+
+
+@pytest.fixture
def monkeyed_requests_get_404():
def _monkeyed_requests_get_404(url):
"""
get that pretends that key doesnt exist
"""
if url in [
- "http://config_binding_service:10000/service_component_all/mybestfrienddotcom",
- "http://config_binding_service:10000/service_component/mybestfrienddotcom",
+ "http://config-binding-service:10000/service_component_all/testhostname",
+ "http://config-binding-service:10000/service_component/testhostname",
]:
return FakeResponse(status_code=404, thejson={})
raise Exception("Unexpected URL {0}!".format(url))
diff --git a/onap-dcae-cbs-docker-client/tests/test_client.py b/onap-dcae-cbs-docker-client/tests/test_client.py
index b1589c2..132ab33 100644
--- a/onap-dcae-cbs-docker-client/tests/test_client.py
+++ b/onap-dcae-cbs-docker-client/tests/test_client.py
@@ -18,13 +18,29 @@ from onap_dcae_cbs_docker_client.client import get_config, get_all
from onap_dcae_cbs_docker_client.exceptions import CantGetConfig, CBSUnreachable, ENVsMissing
-def test_config(monkeypatch, monkeyed_requests_get):
+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 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}
-def test_all(monkeypatch, monkeyed_requests_get):
- monkeypatch.setattr("requests.get", monkeyed_requests_get)
assert get_all() == {
"config": {"key_to_your_heart": 666},
"dti": {"some amazing": "dti stuff"},