move plugins from from ccsdk to dcaegen2
[dcaegen2/platform/plugins.git] / dmaap / tests / conftest.py
1 # ============LICENSE_START=======================================================
2 # org.onap.dcae
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
9 #
10 #      http://www.apache.org/licenses/LICENSE-2.0
11 #
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=========================================================
18 #
19
20 import pytest
21
22 import requests
23
24 @pytest.fixture()
25 def mockconsul(monkeypatch):
26     """ Override the regular Consul interface"""
27     def fake_get_config(self, key):
28         config={'dmaap': {
29             'username': 'testuser@dmaaptest.example.com',
30             'url': 'https://dmaaptest.example.com:8443/webapi',
31             'password' : 'testpassword',
32             'owner': 'dcaeorch'
33         }}
34         return config
35
36     def fake_get_service(self, service_name):
37         service_address = "myAddress"
38         service_port= "8443"
39         return service_address, service_port
40
41     def fake_add_to_entry(self, key, add_name, add_value):
42         return True
43
44     def fake_delete_entry(self, entry_name):
45         return True
46
47     def fake_init(self, api_url, user, password, logger):
48         pass
49
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)
56
57     def get_handle():
58         return ConsulHandle('mockconsul', None, None, None)
59     return get_handle
60
61
62 @pytest.fixture()
63 def mockdmaapbc(monkeypatch):
64
65     def fake_get(url, auth):
66     #    print "fake_get: {0}, {1}".format(url, auth)
67         r = requests.Response()
68         r.status_code = 200
69         return r
70     def fake_post(url, auth, json):
71     #    print "fake_post: {0}, {1}, {2}".format(url, auth, json)
72         r = requests.Response()
73         r.status_code = 200
74         return r
75     def fake_delete(url, auth):
76     #    print "fake_delete: {0}, {1}".format(url, auth)
77         r = requests.Response()
78         r.status_code = 200
79         return r
80     def fake_json(self):
81         return {"fqtn":"test_fqtn"}
82
83     import requests
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)
88