Lusheng Ji | cc30700 | 2018-02-12 11:04:54 -0500 | [diff] [blame] | 1 | # ================================================================================ |
| 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 Carpenter | d1a8143 | 2018-02-22 14:32:46 -0500 | [diff] [blame] | 18 | from onap_dcae_cbs_docker_client.client import get_config, get_all |
Tommy Carpenter | 7b31008 | 2017-09-25 11:45:12 -0400 | [diff] [blame] | 19 | |
Tommy Carpenter | 426fd9d | 2018-03-12 11:29:33 -0400 | [diff] [blame^] | 20 | |
Tommy Carpenter | 7b31008 | 2017-09-25 11:45:12 -0400 | [diff] [blame] | 21 | class FakeResponse: |
| 22 | def __init__(self, status_code, thejson): |
| 23 | self.status_code = status_code |
| 24 | self.thejson = thejson |
Tommy Carpenter | 426fd9d | 2018-03-12 11:29:33 -0400 | [diff] [blame^] | 25 | |
Tommy Carpenter | 7b31008 | 2017-09-25 11:45:12 -0400 | [diff] [blame] | 26 | def raise_for_status(self): |
| 27 | pass |
Tommy Carpenter | 426fd9d | 2018-03-12 11:29:33 -0400 | [diff] [blame^] | 28 | |
Tommy Carpenter | 7b31008 | 2017-09-25 11:45:12 -0400 | [diff] [blame] | 29 | def json(self): |
| 30 | return self.thejson |
| 31 | |
Tommy Carpenter | 426fd9d | 2018-03-12 11:29:33 -0400 | [diff] [blame^] | 32 | |
Tommy Carpenter | d1a8143 | 2018-02-22 14:32:46 -0500 | [diff] [blame] | 33 | def monkeyed_requests_get(url): |
Tommy Carpenter | 426fd9d | 2018-03-12 11:29:33 -0400 | [diff] [blame^] | 34 | # mock all the get calls for existent and non-existent |
Tommy Carpenter | d1a8143 | 2018-02-22 14:32:46 -0500 | [diff] [blame] | 35 | 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 Carpenter | 7b31008 | 2017-09-25 11:45:12 -0400 | [diff] [blame] | 46 | |
Tommy Carpenter | bfc70e5 | 2018-02-23 16:05:45 -0500 | [diff] [blame] | 47 | 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 Carpenter | d1a8143 | 2018-02-22 14:32:46 -0500 | [diff] [blame] | 52 | def test_config(monkeypatch): |
Tommy Carpenter | 7b31008 | 2017-09-25 11:45:12 -0400 | [diff] [blame] | 53 | monkeypatch.setattr('requests.get', monkeyed_requests_get) |
Tommy Carpenter | d1a8143 | 2018-02-22 14:32:46 -0500 | [diff] [blame] | 54 | assert(get_config() == {"key_to_your_heart": 666}) |
Tommy Carpenter | 7b31008 | 2017-09-25 11:45:12 -0400 | [diff] [blame] | 55 | |
Tommy Carpenter | 426fd9d | 2018-03-12 11:29:33 -0400 | [diff] [blame^] | 56 | |
Tommy Carpenter | d1a8143 | 2018-02-22 14:32:46 -0500 | [diff] [blame] | 57 | def 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"}}) |