summaryrefslogtreecommitdiffstats
path: root/dcae-policy/tests/test_tasks.py
diff options
context:
space:
mode:
authorLusheng Ji <lji@research.att.com>2018-03-27 02:18:13 +0000
committerGerrit Code Review <gerrit@onap.org>2018-03-27 02:18:13 +0000
commit342c2890e9b46b483244773b2337c8f56ae9bd0d (patch)
treeac21ecf7f6df46674b28960a6f50571d4120d5c8 /dcae-policy/tests/test_tasks.py
parent5536545e42a15d0ab6a389b3856b390d997d3b08 (diff)
parent19470fb77656cd6680058f456fb0f09e86f504dc (diff)
Merge "2.2.0 dcaepolicyplugin and data types"
Diffstat (limited to 'dcae-policy/tests/test_tasks.py')
-rw-r--r--dcae-policy/tests/test_tasks.py47
1 files changed, 40 insertions, 7 deletions
diff --git a/dcae-policy/tests/test_tasks.py b/dcae-policy/tests/test_tasks.py
index 9bcf4ff..b9b69b9 100644
--- a/dcae-policy/tests/test_tasks.py
+++ b/dcae-policy/tests/test_tasks.py
@@ -166,9 +166,22 @@ def monkeyed_discovery_get_failure(full_path):
def test_discovery_failure(monkeypatch):
"""test finding policy-handler in consul"""
monkeypatch.setattr('requests.get', monkeyed_discovery_get_failure)
- expected = None
- tasks.PolicyHandler._lazy_init()
- assert expected == tasks.PolicyHandler._url
+
+ node_policy = MonkeyedNode(
+ 'test_dcae_policy_node_id',
+ 'test_dcae_policy_node_name',
+ tasks.DCAE_POLICY_TYPE,
+ {POLICY_ID: MONKEYED_POLICY_ID}
+ )
+ try:
+ current_ctx.set(node_policy.ctx)
+ tasks.PolicyHandler._lazy_init()
+ assert tasks.PolicyHandler.DEFAULT_URL == tasks.PolicyHandler._url
+
+ finally:
+ tasks.PolicyHandler._url = None
+ MockCloudifyContextFull.clear()
+ current_ctx.clear()
def monkeyed_discovery_get(full_path):
"""monkeypatch for the GET to consul"""
@@ -178,17 +191,36 @@ def monkeyed_discovery_get(full_path):
def test_discovery(monkeypatch):
"""test finding policy-handler in consul"""
monkeypatch.setattr('requests.get', monkeyed_discovery_get)
- expected = "http://monkey-policy-handler-address:9999"
- tasks.PolicyHandler._lazy_init()
- assert expected == tasks.PolicyHandler._url
-def monkeyed_policy_handler_get(full_path, headers):
+ node_policy = MonkeyedNode(
+ 'test_dcae_policy_node_id',
+ 'test_dcae_policy_node_name',
+ tasks.DCAE_POLICY_TYPE,
+ {POLICY_ID: MONKEYED_POLICY_ID}
+ )
+
+ try:
+ current_ctx.set(node_policy.ctx)
+ expected = "http://monkey-policy-handler-address:9999"
+ CtxLogger.log_ctx_info("before PolicyHandler._lazy_init")
+ tasks.PolicyHandler._lazy_init()
+ CtxLogger.log_ctx_info("after PolicyHandler._lazy_init")
+ assert expected == tasks.PolicyHandler._url
+
+ finally:
+ tasks.PolicyHandler._url = None
+ MockCloudifyContextFull.clear()
+ current_ctx.clear()
+
+
+def monkeyed_policy_handler_get(full_path, headers=None):
"""monkeypatch for the GET to policy-engine"""
return MonkeyedResponse(full_path, headers, \
MonkeyedPolicyBody.create_policy(MONKEYED_POLICY_ID))
def test_policy_get(monkeypatch):
"""test policy_get operation on dcae.nodes.policy node"""
+ tasks.PolicyHandler._url = tasks.PolicyHandler.DEFAULT_URL
monkeypatch.setattr('requests.get', monkeyed_policy_handler_get)
node_policy = MonkeyedNode(
@@ -236,6 +268,7 @@ def monkeyed_policy_handler_find(full_path, json, headers):
def test_policies_find(monkeypatch):
"""test policy_get operation on dcae.nodes.policies node"""
+ tasks.PolicyHandler._url = tasks.PolicyHandler.DEFAULT_URL
monkeypatch.setattr('requests.post', monkeyed_policy_handler_find)
node_policies = MonkeyedNode(