1 # ============LICENSE_START=======================================================
3 # ================================================================================
4 # Copyright (c) 2018-2020 AT&T Intellectual Property. All rights reserved.
5 # ================================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ============LICENSE_END=========================================================
25 def mockconsul(monkeypatch):
26 """ Override the regular Consul interface"""
27 def fake_get_config(self, key):
29 'username': 'testuser@dmaaptest.example.com',
30 'url': 'https://dmaaptest.example.com:8443/webapi',
31 'password' : 'testpassword',
36 def fake_get_service(self, service_name):
37 service_address = "myAddress"
39 return service_address, service_port
41 def fake_add_to_entry(self, key, add_name, add_value):
44 def fake_delete_entry(self, entry_name):
47 def fake_init(self, api_url, user, password, logger):
50 from consulif.consulif import ConsulHandle
51 monkeypatch.setattr(ConsulHandle, 'get_config', fake_get_config)
52 monkeypatch.setattr(ConsulHandle, 'get_service', fake_get_service)
53 monkeypatch.setattr(ConsulHandle, 'add_to_entry', fake_add_to_entry)
54 monkeypatch.setattr(ConsulHandle, 'delete_entry', fake_delete_entry)
55 monkeypatch.setattr(ConsulHandle, '__init__', fake_init)
58 return ConsulHandle('mockconsul', None, None, None)
63 def mockdmaapbc(monkeypatch):
65 def fake_get(url, auth):
66 # print "fake_get: {0}, {1}".format(url, auth)
67 r = requests.Response()
70 def fake_post(url, auth, json):
71 # print "fake_post: {0}, {1}, {2}".format(url, auth, json)
72 r = requests.Response()
75 def fake_delete(url, auth):
76 # print "fake_delete: {0}, {1}".format(url, auth)
77 r = requests.Response()
81 return {"fqtn":"test_fqtn"}
84 monkeypatch.setattr(requests.Response, "json", fake_json)
85 monkeypatch.setattr(requests, "get", fake_get)
86 monkeypatch.setattr(requests, "post", fake_post)
87 monkeypatch.setattr(requests, "delete", fake_delete)