diff options
author | Tommy Carpenter <tommy@research.att.com> | 2019-05-31 09:21:31 -0400 |
---|---|---|
committer | Tommy Carpenter <tommy@research.att.com> | 2019-06-05 11:59:13 +0000 |
commit | cbbf7f93f272ddff1c615eb287c7556972a16357 (patch) | |
tree | 967e7e536f0428410c19443d776ab28e9c468ee1 /tests/test_api.py | |
parent | e14b49ead38227ff17d760c4771d58d9c6d2e7c0 (diff) |
Add HTTPS Flag
Issue-ID: DCAEGEN2-1549
Change-Id: I24f84d13ddc4e4163c02814c2f841a5485dbf7a7
Signed-off-by: Tommy Carpenter <tommy@research.att.com>
Diffstat (limited to 'tests/test_api.py')
-rw-r--r-- | tests/test_api.py | 135 |
1 files changed, 99 insertions, 36 deletions
diff --git a/tests/test_api.py b/tests/test_api.py index 118a2a0..4356629 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -28,76 +28,139 @@ TEST_NAME = "test_service_component_name.unknown.unknown.unknown.dcae.onap.org" # http://flask.pocoo.org/docs/1.0/testing/ @pytest.fixture def cbsclient(): - db_fd, app.app.config['DATABASE'] = tempfile.mkstemp() - app.app.config['TESTING'] = True + db_fd, app.app.config["DATABASE"] = tempfile.mkstemp() + app.app.config["TESTING"] = True testclient = app.app.test_client() yield testclient os.close(db_fd) - os.unlink(app.app.config['DATABASE']) + os.unlink(app.app.config["DATABASE"]) def test_get(monkeypatch, cbsclient, monkeyed_requests_put): - monkeypatch.setattr('requests.put', monkeyed_requests_put) + monkeypatch.setattr("requests.put", monkeyed_requests_put) - res = cbsclient.get('/service_component/scn_exists', - headers={"x-onap-requestid": 123456789}) - assert(json.loads(res.data) == {"foo3": "bar3"}) - assert(res.status_code == 200) - assert(res.headers["x-onap-requestid"] == "123456789") + res = cbsclient.get("/service_component/scn_exists", headers={"x-onap-requestid": 123456789}) + assert json.loads(res.data) == {"foo3": "bar3"} + assert res.status_code == 200 + assert res.headers["x-onap-requestid"] == "123456789" - res = cbsclient.get('/service_component/scn_NOTexists', - headers={"x-onap-requestid": 123456789}) - assert(res.status_code == 404) - assert(res.headers["x-onap-requestid"] == "123456789") + res = cbsclient.get("/service_component/scn_NOTexists", headers={"x-onap-requestid": 123456789}) + assert res.status_code == 404 + assert res.headers["x-onap-requestid"] == "123456789" - res = cbsclient.get('/service_component/asdfasdf', - headers={"x-onap-requestid": 123456789}) - assert(res.status_code == 500) - assert(res.headers["x-onap-requestid"] == "123456789") + res = cbsclient.get("/service_component/asdfasdf", headers={"x-onap-requestid": 123456789}) + assert res.status_code == 500 + assert res.headers["x-onap-requestid"] == "123456789" def test_generic(monkeypatch, cbsclient, monkeyed_requests_get, monkeyed_requests_put): - monkeypatch.setattr('requests.put', monkeyed_requests_put) - monkeypatch.setattr('requests.get', monkeyed_requests_get) + monkeypatch.setattr("requests.put", monkeyed_requests_put) + monkeypatch.setattr("requests.get", monkeyed_requests_get) - res = cbsclient.get('/dti/{0}'.format(TEST_NAME)) + res = cbsclient.get("/dti/{0}".format(TEST_NAME)) assert json.loads(res.data) == {"my": "dti"} assert res.json == {"my": "dti"} assert res.status_code == 200 assert "x-onap-requestid" in res.headers - res = cbsclient.get('/nokeyforyou/{0}'.format(TEST_NAME)) + res = cbsclient.get("/nokeyforyou/{0}".format(TEST_NAME)) assert res.status_code == 404 assert "x-onap-requestid" in res.headers - res = cbsclient.get('/policies/{0}'.format(TEST_NAME)) + res = cbsclient.get("/policies/{0}".format(TEST_NAME)) assert res.status_code == 400 assert "x-onap-requestid" in res.headers -def test_resolve_all(monkeypatch, cbsclient, monkeyed_requests_put, monkeyed_get_connection_info_from_consul, expected_config): - monkeypatch.setattr('requests.put', monkeyed_requests_put) - monkeypatch.setattr('config_binding_service.client._get_connection_info_from_consul', monkeyed_get_connection_info_from_consul) - withstuff = {'config': {'my': 'amazing config'}, - 'dti': {'my': 'dti'}, - 'policies': {'items': [{'policyName': 'DCAE_alex.Config_MS_alex_microservice.132.xml', 'policyConfigMessage': 'Config Retrieved! ', 'responseAttributes': {}, 'policyConfigStatus': 'CONFIG_RETRIEVED', 'matchingConditions': {'ONAPName': 'DCAE', 'Name': 'DCAE', 'ConfigName': 'alex_config_name'}, 'config': {'policyScope': 'alex_policy_scope', 'configName': 'alex_config_name', 'description': 'test DCAE policy-handler', 'service': 'alex_service', 'policyName': 'alex_policy_name', 'riskLevel': '3', 'key1': 'value1', 'policy_hello': 'world!', 'content': {'foo': 'microservice3', 'foo_updated': '2018-01-30T13:25:33.222Z'}, 'riskType': '1712_ETE', 'guard': 'False', 'version': '0.0.1', 'location': 'Central', 'policy_updated_ts': '2018-02-19T15:09:55.217Z', 'updated_policy_id': 'DCAE_alex.Config_MS_alex_microservice', 'policy_updated_to_ver': '132', 'priority': '4', 'policy_updated_from_ver': '131', 'templateVersion': '2', 'uuid': '5e87d7c5-0daf-4b6b-ab92-5365cf5db1ef'}, 'property': None, 'type': 'JSON', 'policyVersion': '132'}, {'policyName': 'DCAE_alex.Config_db_client_policy_id_value.133.xml', 'policyConfigMessage': 'Config Retrieved! ', 'responseAttributes': {}, 'policyConfigStatus': 'CONFIG_RETRIEVED', 'matchingConditions': {'ONAPName': 'DCAE', 'Name': 'DCAE', 'ConfigName': 'alex_config_name'}, 'config': {'db_client_ts': '2017-11-21T12:12:13.696Z', 'db_client': 'ipsum', 'policy_hello': 'world!', 'policy_updated_from_ver': '132', 'updated_policy_id': 'DCAE_alex.Config_db_client_policy_id_value', 'policy_updated_ts': '2018-02-19T15:09:55.812Z', 'policy_updated_to_ver': '133'}, 'property': None, 'type': 'JSON', 'policyVersion': '133'}], 'event': {'action': 'gathered', 'timestamp': '2018-02-19 15:36:44.877380', 'update_id': 'bb73c20a-5ff8-450f-8223-da6720ade267', 'policies_count': 2}}} - - assert cbsclient.get('service_component_all/{0}'.format(TEST_NAME)).json == withstuff - - assert cbsclient.get('service_component_all/test_resolve_scn').json == {"config": expected_config} - - res = cbsclient.get('/service_component_all/{0}'.format(TEST_NAME)) +def test_resolve_all( + monkeypatch, cbsclient, monkeyed_requests_put, monkeyed_get_connection_info_from_consul, expected_config +): + monkeypatch.setattr("requests.put", monkeyed_requests_put) + monkeypatch.setattr( + "config_binding_service.client._get_connection_info_from_consul", monkeyed_get_connection_info_from_consul + ) + withstuff = { + "config": {"my": "amazing config"}, + "dti": {"my": "dti"}, + "policies": { + "items": [ + { + "policyName": "DCAE_alex.Config_MS_alex_microservice.132.xml", + "policyConfigMessage": "Config Retrieved! ", + "responseAttributes": {}, + "policyConfigStatus": "CONFIG_RETRIEVED", + "matchingConditions": {"ONAPName": "DCAE", "Name": "DCAE", "ConfigName": "alex_config_name"}, + "config": { + "policyScope": "alex_policy_scope", + "configName": "alex_config_name", + "description": "test DCAE policy-handler", + "service": "alex_service", + "policyName": "alex_policy_name", + "riskLevel": "3", + "key1": "value1", + "policy_hello": "world!", + "content": {"foo": "microservice3", "foo_updated": "2018-01-30T13:25:33.222Z"}, + "riskType": "1712_ETE", + "guard": "False", + "version": "0.0.1", + "location": "Central", + "policy_updated_ts": "2018-02-19T15:09:55.217Z", + "updated_policy_id": "DCAE_alex.Config_MS_alex_microservice", + "policy_updated_to_ver": "132", + "priority": "4", + "policy_updated_from_ver": "131", + "templateVersion": "2", + "uuid": "5e87d7c5-0daf-4b6b-ab92-5365cf5db1ef", + }, + "property": None, + "type": "JSON", + "policyVersion": "132", + }, + { + "policyName": "DCAE_alex.Config_db_client_policy_id_value.133.xml", + "policyConfigMessage": "Config Retrieved! ", + "responseAttributes": {}, + "policyConfigStatus": "CONFIG_RETRIEVED", + "matchingConditions": {"ONAPName": "DCAE", "Name": "DCAE", "ConfigName": "alex_config_name"}, + "config": { + "db_client_ts": "2017-11-21T12:12:13.696Z", + "db_client": "ipsum", + "policy_hello": "world!", + "policy_updated_from_ver": "132", + "updated_policy_id": "DCAE_alex.Config_db_client_policy_id_value", + "policy_updated_ts": "2018-02-19T15:09:55.812Z", + "policy_updated_to_ver": "133", + }, + "property": None, + "type": "JSON", + "policyVersion": "133", + }, + ], + "event": { + "action": "gathered", + "timestamp": "2018-02-19 15:36:44.877380", + "update_id": "bb73c20a-5ff8-450f-8223-da6720ade267", + "policies_count": 2, + }, + }, + } + + assert cbsclient.get("service_component_all/{0}".format(TEST_NAME)).json == withstuff + + assert cbsclient.get("service_component_all/test_resolve_scn").json == {"config": expected_config} + + res = cbsclient.get("/service_component_all/{0}".format(TEST_NAME)) assert json.loads(res.data) == withstuff assert res.json == withstuff assert res.status_code == 200 assert "x-onap-requestid" in res.headers - res = cbsclient.get('/service_component_all/test_resolve_scn') + res = cbsclient.get("/service_component_all/test_resolve_scn") assert res.status_code == 200 assert res.json == {"config": expected_config} - res = cbsclient.get('/service_component_all/scn_NOTexists') + res = cbsclient.get("/service_component_all/scn_NOTexists") assert res.status_code == 404 assert "x-onap-requestid" in res.headers |