summaryrefslogtreecommitdiffstats
path: root/onap-dcae-cbs-docker-client/tests/test_client.py
blob: db8e1b57ba30a2147921259caa9c05e0c3d1986b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# ================================================================================
# Copyright (c) 2017-2018 AT&T Intellectual Property. 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.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============LICENSE_END=========================================================
#
# ECOMP is a trademark and service mark of AT&T Intellectual Property.
from onap_dcae_cbs_docker_client.client import get_config
import requests

class FakeResponse:
    def __init__(self, status_code, thejson):
        self.status_code = status_code
        self.thejson = thejson
    def raise_for_status(self):
        pass
    def json(self):
        return self.thejson

def test_client(monkeypatch):

    def monkeyed_requests_get(url):
        #mock all the get calls for existent and non-existent
        if url == "http://consuldotcom:8500/v1/catalog/service/config_binding_service":
            return FakeResponse(
                       status_code = 200,
                       thejson = [
                           {"ServiceAddress" : "666.666.666.666",
                            "ServicePort" : 8888
                           }]
                )
        elif url == "http://666.666.666.666:8888/service_component/mybestfrienddotcom":
            return FakeResponse(
                       status_code = 200,
                       thejson = {"key_to_your_heart" : 666})


    monkeypatch.setattr('requests.get', monkeyed_requests_get)
    assert(get_config() == {"key_to_your_heart" : 666})