blob: dd6ab102659afcec7ab26f390edb500732ccc4a5 [file] [log] [blame]
Lusheng Jicc307002018-02-12 11:04:54 -05001# ================================================================================
2# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
3# ================================================================================
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15# ============LICENSE_END=========================================================
16#
17# ECOMP is a trademark and service mark of AT&T Intellectual Property.
Tommy Carpenterd1a81432018-02-22 14:32:46 -050018from onap_dcae_cbs_docker_client.client import get_config, get_all
Tommy Carpenter7b310082017-09-25 11:45:12 -040019
Tommy Carpenter426fd9d2018-03-12 11:29:33 -040020
Tommy Carpenter7b310082017-09-25 11:45:12 -040021class FakeResponse:
22 def __init__(self, status_code, thejson):
23 self.status_code = status_code
24 self.thejson = thejson
Tommy Carpenter426fd9d2018-03-12 11:29:33 -040025
Tommy Carpenter7b310082017-09-25 11:45:12 -040026 def raise_for_status(self):
27 pass
Tommy Carpenter426fd9d2018-03-12 11:29:33 -040028
Tommy Carpenter7b310082017-09-25 11:45:12 -040029 def json(self):
30 return self.thejson
31
Tommy Carpenter426fd9d2018-03-12 11:29:33 -040032
Tommy Carpenterd1a81432018-02-22 14:32:46 -050033def monkeyed_requests_get(url):
Tommy Carpenter426fd9d2018-03-12 11:29:33 -040034 # mock all the get calls for existent and non-existent
Tommy Carpenterd1a81432018-02-22 14:32:46 -050035 if url == "http://consuldotcom:8500/v1/catalog/service/config_binding_service":
36 return FakeResponse(status_code=200,
37 thejson=[{"ServiceAddress": "666.666.666.666",
38 "ServicePort": 8888}])
39 elif url == "http://666.666.666.666:8888/service_component_all/mybestfrienddotcom":
40 return FakeResponse(status_code=200,
41 thejson={"config": {"key_to_your_heart": 666},
42 "dti": {"some amazing": "dti stuff"},
43 "policies": {"event": {"foo": "bar"},
44 "items": [{"foo2": "bar2"}]},
45 "otherkey": {"foo3": "bar3"}})
Tommy Carpenter7b310082017-09-25 11:45:12 -040046
Tommy Carpenterbfc70e52018-02-23 16:05:45 -050047 elif url == "http://666.666.666.666:8888/service_component/mybestfrienddotcom":
48 return FakeResponse(status_code=200,
49 thejson={"key_to_your_heart": 666})
50
51
Tommy Carpenterd1a81432018-02-22 14:32:46 -050052def test_config(monkeypatch):
Tommy Carpenter7b310082017-09-25 11:45:12 -040053 monkeypatch.setattr('requests.get', monkeyed_requests_get)
Tommy Carpenterd1a81432018-02-22 14:32:46 -050054 assert(get_config() == {"key_to_your_heart": 666})
Tommy Carpenter7b310082017-09-25 11:45:12 -040055
Tommy Carpenter426fd9d2018-03-12 11:29:33 -040056
Tommy Carpenterd1a81432018-02-22 14:32:46 -050057def test_all(monkeypatch):
58 monkeypatch.setattr('requests.get', monkeyed_requests_get)
59 assert(get_all() == {"config": {"key_to_your_heart": 666},
60 "dti": {"some amazing": "dti stuff"},
61 "policies": {"event": {"foo": "bar"},
62 "items": [{"foo2": "bar2"}]},
63 "otherkey": {"foo3": "bar3"}})