summaryrefslogtreecommitdiffstats
path: root/onap-dcae-cbs-docker-client/tests
diff options
context:
space:
mode:
authorEdyta Krukowska <edyta.krukowska@nokia.com>2021-05-12 12:00:07 +0200
committerEdyta Krukowska <edyta.krukowska@nokia.com>2021-05-17 10:14:13 +0200
commit1002e423a67cc4c22846ffc333b8027230e55dcb (patch)
treec356d859c8a6981dda9b6f804b74f9ba8a06b4e5 /onap-dcae-cbs-docker-client/tests
parentad98c5f8850ffa031882e90b4f081c7f5e7c1709 (diff)
Add env service for configuration
Issue-ID: DCAEGEN2-2630 Signed-off-by: Edyta Krukowska <edyta.krukowska@nokia.com> Change-Id: I86b4a84fd49bfe41afd39a9a2096d72d8263e63a
Diffstat (limited to 'onap-dcae-cbs-docker-client/tests')
-rw-r--r--onap-dcae-cbs-docker-client/tests/conftest.py76
-rw-r--r--onap-dcae-cbs-docker-client/tests/test_client.py36
2 files changed, 112 insertions, 0 deletions
diff --git a/onap-dcae-cbs-docker-client/tests/conftest.py b/onap-dcae-cbs-docker-client/tests/conftest.py
index b927412..0f34ff1 100644
--- a/onap-dcae-cbs-docker-client/tests/conftest.py
+++ b/onap-dcae-cbs-docker-client/tests/conftest.py
@@ -1,5 +1,6 @@
# ================================================================================
# Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2021 Nokia. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -44,6 +45,30 @@ good_resp_all = FakeResponse(
)
good_resp_conf = FakeResponse(status_code=200, thejson={"key_to_your_heart": 666})
+good_resp_conf_env = FakeResponse(status_code=200, thejson={"key_to_your_heart": "${TEST_ENV}"})
+
+good_resp_all_env = FakeResponse(
+ status_code=200,
+ thejson={
+ "config": {"key_to_your_heart": "${TEST_ENV}"},
+ "dti": {"some amazing": "dti stuff"},
+ "policies": {"event": {"foo": "bar"}, "items": [{"foo2": "bar2"}]},
+ "otherkey": {"foo3": "bar3"},
+ },
+)
+
+good_resp_conf_wrong_env = FakeResponse(status_code=200, thejson={"key_to_your_heart": "${WRONG_TEST_ENV}"})
+
+good_resp_all_wrong_env = FakeResponse(
+ status_code=200,
+ thejson={
+ "config": {"key_to_your_heart": "${WRONG_TEST_ENV}"},
+ "dti": {"some amazing": "dti stuff"},
+ "policies": {"event": {"foo": "bar"}, "items": [{"foo2": "bar2"}]},
+ "otherkey": {"foo3": "bar3"},
+ },
+)
+
@pytest.fixture
def monkeyed_requests_get():
@@ -80,6 +105,57 @@ def monkeyed_requests_get_https():
@pytest.fixture
+def monkeyed_requests_get_with_env():
+ """
+ mock for the CBS get
+ """
+
+ def _monkeyed_requests_get(url):
+ if url == "http://config-binding-service:10000/service_component_all/testhostname":
+ return good_resp_all_env
+ elif url == "http://config-binding-service:10000/service_component/testhostname":
+ return good_resp_conf_env
+ else:
+ raise Exception("Unexpected URL {0}!".format(url))
+
+ return _monkeyed_requests_get
+
+
+@pytest.fixture
+def monkeyed_requests_get_https_env():
+ """
+ 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_env
+ elif url == "https://config-binding-service:10443/service_component/testhostname":
+ return good_resp_conf_env
+ else:
+ raise Exception("Unexpected URL {0}!".format(url))
+
+ return _monkeyed_requests_get_https
+
+
+@pytest.fixture
+def monkeyed_requests_get_http_with_wrong_env():
+ """
+ mock for the CBS get
+ """
+
+ def _monkeyed_requests_get(url):
+ if url == "http://config-binding-service:10000/service_component_all/testhostname":
+ return good_resp_all_wrong_env
+ elif url == "http://config-binding-service:10000/service_component/testhostname":
+ return good_resp_conf_wrong_env
+ else:
+ raise Exception("Unexpected URL {0}!".format(url))
+
+ return _monkeyed_requests_get
+
+
+@pytest.fixture
def monkeyed_requests_get_404():
def _monkeyed_requests_get_404(url):
"""
diff --git a/onap-dcae-cbs-docker-client/tests/test_client.py b/onap-dcae-cbs-docker-client/tests/test_client.py
index 132ab33..3b10923 100644
--- a/onap-dcae-cbs-docker-client/tests/test_client.py
+++ b/onap-dcae-cbs-docker-client/tests/test_client.py
@@ -1,5 +1,6 @@
# ================================================================================
# Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2021 Nokia. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -77,3 +78,38 @@ def test_badenv(monkeypatch):
get_config()
with pytest.raises(ENVsMissing):
get_all()
+
+
+def test_http_with_env(monkeypatch, monkeyed_requests_get_with_env):
+ monkeypatch.setattr("requests.get", monkeyed_requests_get_with_env)
+
+ assert get_config() == {"key_to_your_heart": "test_env"}
+
+ assert get_all() == {
+ "config": {"key_to_your_heart": "test_env"},
+ "dti": {"some amazing": "dti stuff"},
+ "policies": {"event": {"foo": "bar"}, "items": [{"foo2": "bar2"}]},
+ "otherkey": {"foo3": "bar3"},
+ }
+
+
+def test_https_with_env(monkeypatch, monkeyed_requests_get_https_env):
+ monkeypatch.setattr("requests.get", monkeyed_requests_get_https_env)
+ monkeypatch.setenv("DCAE_CA_CERTPATH", "1")
+
+ assert get_config() == {"key_to_your_heart": "test_env"}
+
+ assert get_all() == {
+ "config": {"key_to_your_heart": "test_env"},
+ "dti": {"some amazing": "dti stuff"},
+ "policies": {"event": {"foo": "bar"}, "items": [{"foo2": "bar2"}]},
+ "otherkey": {"foo3": "bar3"},
+ }
+
+
+def test_http_with_wrong_env(monkeypatch, monkeyed_requests_get_http_with_wrong_env):
+ monkeypatch.setattr("requests.get", monkeyed_requests_get_http_with_wrong_env)
+ with pytest.raises(ENVsMissing):
+ get_config()
+ with pytest.raises(ENVsMissing):
+ get_all()