aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTommy Carpenter <tommy@research.att.com>2018-02-15 21:10:17 -0500
committerTommy Carpenter <tommy@research.att.com>2018-02-15 21:10:35 -0500
commit3a3543f74d74d4410c3e4d414bebf3d1daba5a59 (patch)
treeff978a94aeee9a4c4db6fede7f592a67bfe27c1b
parent857c41af07fd88b50c2e960071611f425268e486 (diff)
More Unit Testing, Fix Liscenses
Issue-ID: DCAEGEN2-341 Change-Id: I9ecbb020775f7dca812e38691a27ef3966f260e6 Signed-off-by: Tommy Carpenter <tommy@research.att.com>
-rw-r--r--Changelog.md4
-rwxr-xr-xbin/run.py2
-rw-r--r--config_binding_service/__init__.py2
-rw-r--r--config_binding_service/client.py14
-rw-r--r--config_binding_service/controller.py2
-rw-r--r--config_binding_service/swagger/swagger.yaml4
-rw-r--r--pom.xml2
-rw-r--r--setup.py4
-rw-r--r--tests/test_binding.py70
9 files changed, 78 insertions, 26 deletions
diff --git a/Changelog.md b/Changelog.md
index 4a8ea05..7fe9f96 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
+## [1.3.1]
+* Add more tests (Currently 75%)
+* Fix liscenses
+
## [1.3.0]
* Sync ONAP with Internal CBS
* Add tests (Currently 62%)
diff --git a/bin/run.py b/bin/run.py
index 2a4f4ce..cc39a0a 100755
--- a/bin/run.py
+++ b/bin/run.py
@@ -1,8 +1,6 @@
#!/usr/bin/env python3
# ============LICENSE_START=======================================================
-# org.onap.dcae
-# ================================================================================
# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/config_binding_service/__init__.py b/config_binding_service/__init__.py
index c50f47f..5f09f1e 100644
--- a/config_binding_service/__init__.py
+++ b/config_binding_service/__init__.py
@@ -1,6 +1,4 @@
# ============LICENSE_START=======================================================
-# org.onap.dcae
-# ================================================================================
# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/config_binding_service/client.py b/config_binding_service/client.py
index 6b53996..a78a993 100644
--- a/config_binding_service/client.py
+++ b/config_binding_service/client.py
@@ -1,6 +1,4 @@
# ============LICENSE_START=======================================================
-# org.onap.dcae
-# ================================================================================
# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -55,11 +53,8 @@ def _consul_get_key(key):
return json.loads(base64.b64decode(D["Value"]).decode("utf-8"))
def _get_config_rels_dmaap(service_component_name):
- try:
- config = _consul_get_key(service_component_name) #not ok if no config
- except requests.exceptions.HTTPError as e:
- #might be a 404, or could be not even able to reach consul (503?), bubble up the requests error
- raise CantGetConfig(e.response.status_code, e.response.text)
+ #this one is critical, if we hit an error, blow up and raise to the caller
+ config = _consul_get_key(service_component_name) #not ok if no config
rels = []
dmaap = {}
@@ -177,7 +172,10 @@ def resolve(service_component_name):
"""
Return the bound config of service_component_name
"""
- config, rels, dmaap = _get_config_rels_dmaap(service_component_name)
+ try:
+ config, rels, dmaap = _get_config_rels_dmaap(service_component_name)
+ except requests.exceptions.HTTPError as e:
+ raise CantGetConfig(e.response.status_code, e.response.text)
_logger.info("Fetching {0}: config={1}, rels={2}".format(service_component_name, json.dumps(config), rels))
return _recurse(config, rels, dmaap)
diff --git a/config_binding_service/controller.py b/config_binding_service/controller.py
index ec6f05e..1841bed 100644
--- a/config_binding_service/controller.py
+++ b/config_binding_service/controller.py
@@ -1,6 +1,4 @@
# ============LICENSE_START=======================================================
-# org.onap.dcae
-# ================================================================================
# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/config_binding_service/swagger/swagger.yaml b/config_binding_service/swagger/swagger.yaml
index 31fc42a..ce6cf7d 100644
--- a/config_binding_service/swagger/swagger.yaml
+++ b/config_binding_service/swagger/swagger.yaml
@@ -1,6 +1,4 @@
# ============LICENSE_START=======================================================
-# org.onap.dcae
-# ================================================================================
# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,7 +20,7 @@
---
swagger: "2.0"
info:
- version: "1.3.0"
+ version: "1.3.1"
title: "Config Binding Service"
paths:
/service_component/{service_component_name}:
diff --git a/pom.xml b/pom.xml
index f8c1452..8edefe4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -29,7 +29,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property.
<groupId>org.onap.dcaegen2.platform</groupId>
<artifactId>configbinding</artifactId>
<name>dcaegen2-platform-configbinding</name>
- <version>1.3.0</version>
+ <version>1.3.1</version>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
diff --git a/setup.py b/setup.py
index b57713c..881234a 100644
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,4 @@
# ============LICENSE_START=======================================================
-# org.onap.dcae
-# ================================================================================
# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,7 +23,7 @@ from pip.download import PipSession
setup(
name='config_binding_service',
- version='1.3.0',
+ version='1.3.1',
packages=find_packages(),
author = "Tommy Carpenter",
author_email = "tommy@research.att.com",
diff --git a/tests/test_binding.py b/tests/test_binding.py
index 60c0809..0e5d05a 100644
--- a/tests/test_binding.py
+++ b/tests/test_binding.py
@@ -1,6 +1,4 @@
# ============LICENSE_START=======================================================
-# org.onap.dcae
-# ================================================================================
# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,6 +22,10 @@ import json
from requests.exceptions import HTTPError, RequestException
from requests import Response
+#####
+# MONKEYPATCHES
+#####
+
def monkeyed_get_connection_info_from_consul(service_component_name):
#shared monkeypatch. probably somewhat lazy because the function htis patches can be broken up.
if service_component_name == "cdap":
@@ -46,7 +48,7 @@ class FakeResponse():
self.text = text
self.status_code = status_code
-def monkeyed_consul_get_key(k):
+def monkeyed_consul_get(k):
if k == "dti_exists_test:dti":
return {"foo" : "bar"}
elif k == "dti_NOTexists_test:dti":
@@ -55,9 +57,40 @@ def monkeyed_consul_get_key(k):
return {"foo2" : "bar2"}
elif k == "policies_NOTexists_test:policies":
raise HTTPError(response = FakeResponse(text= "", status_code = 404))
+ else:
+ raise Exception("BLOW UP IN FIRE")
+
+def monkeyed_resolve(k):
+ if k == "scn_NOTexists":
+ raise client.CantGetConfig(code = 404, response = "")
+ elif k == "scn_exists":
+ return {"foo3" : "bar3"}
+ elif k == "scn_exists:rel":
+ return ["foo"]
+ elif k == "scn_exists:dmaap":
+ return {"foo4" : "bar4"}
+
+ elif k == "scn_exists_nord":
+ return {"foo5" : "bar5"}
+ elif k == "scn_exists_nord:rel":
+ raise HTTPError(response = FakeResponse(text= "", status_code = 404))
+ elif k == "scn_exists_nord:dmaap":
+ raise HTTPError(response = FakeResponse(text= "", status_code = 404))
+
+ else:
+ raise Exception("BLOW UP IN FIRE")
-def test_dti_policies(monkeypatch):
- monkeypatch.setattr('config_binding_service.client._consul_get_key', monkeyed_consul_get_key)
+#######
+# TESTS
+#######
+
+def test_get_config_rels_dmaap(monkeypatch):
+ monkeypatch.setattr('config_binding_service.client._consul_get_key', monkeyed_resolve)
+ assert ({"foo3" : "bar3"}, ["foo"], {"foo4" : "bar4"}) == client._get_config_rels_dmaap("scn_exists")
+ assert ({"foo5" : "bar5"}, [], {}) == client._get_config_rels_dmaap("scn_exists_nord")
+
+def test_dti(monkeypatch):
+ monkeypatch.setattr('config_binding_service.client._consul_get_key', monkeyed_consul_get)
assert client.resolve_DTI("dti_exists_test") == {"foo" : "bar"}
with pytest.raises(client.CantGetConfig):
@@ -70,6 +103,13 @@ def test_dti_policies(monkeypatch):
R = controller.dtievents("dti_NOTexists_test")
assert(R.status_code == 404)
+ R = controller.dtievents("asdfasdf")
+ assert(R.status_code == 500)
+
+
+def test_policies(monkeypatch):
+ monkeypatch.setattr('config_binding_service.client._consul_get_key', monkeyed_consul_get)
+
assert client.resolve_policies("policies_exists_test") == {"foo2" : "bar2"}
with pytest.raises(client.CantGetConfig):
client.resolve_policies("policies_NOTexists_test")
@@ -81,6 +121,26 @@ def test_dti_policies(monkeypatch):
R = controller.policies("policies_NOTexists_test")
assert(R.status_code == 404)
+ R = controller.policies("asdfasdf")
+ assert(R.status_code == 500)
+
+def test_bind_config_for_scn(monkeypatch):
+ monkeypatch.setattr('config_binding_service.client.resolve', monkeyed_resolve)
+
+ assert(client.resolve("scn_exists") == {"foo3" : "bar3"})
+ with pytest.raises(client.CantGetConfig):
+ client.resolve("scn_NOTexists")
+
+ R = controller.bind_config_for_scn("scn_exists")
+ assert(json.loads(R.data) == {"foo3" : "bar3"})
+ assert(R.status_code == 200)
+
+ R = controller.bind_config_for_scn("scn_NOTexists")
+ assert(R.status_code == 404)
+
+ R = controller.bind_config_for_scn("asdfasdf")
+ assert(R.status_code == 500)
+
def test_bad_config_http():
test_config = {'yeahhhhh' : "{{}}"}
test_rels = ["testing_bravo.somedomain.com"]