move plugins from from ccsdk to dcaegen2
[dcaegen2/platform/plugins.git] / clamp-policy / tests / test_tasks.py
1 # ================================================================================
2 # Copyright (c) 2019 Wipro Limited Intellectual Property. All rights reserved.
3 # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
4 # ================================================================================
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 # ============LICENSE_END=========================================================
17 #
18
19 """unit tests for tasks in clamppolicyplugin"""
20
21 import json
22
23 import pytest
24 from cloudify.exceptions import NonRecoverableError
25 from cloudify.state import current_ctx
26
27 from clamppolicyplugin import tasks
28 from tests.log_ctx import CtxLogger
29 from tests.mock_cloudify_ctx import (TARGET_NODE_ID, TARGET_NODE_NAME,
30                                      MockCloudifyContextFull)
31 from tests.mock_setup import (CONFIG_NAME, MONKEYED_POLICY_ID, POLICY_BODY,
32                               POLICY_ID, POLICY_MODEL_ID, POLICY_NAME, MonkeyedNode,
33                               MonkeyedPolicyBody, MonkeyedResponse)
34
35 from cloudify.mocks import MockCloudifyContext
36 from cloudify.state import current_ctx
37
38 def monkeyed_policy_handler_get(full_path, headers=None):
39     """monkeypatch for the GET to policy-engine"""
40     return MonkeyedResponse(full_path, headers,
41         MonkeyedPolicyBody.create_policy(MONKEYED_POLICY_ID))
42
43 def test_policy_get():
44     """test policy_get operation on clamp.nodes.policy node"""
45     mock_ctx = MockCloudifyContext(node_id='policy_model_id',node_name='clamp.nodes.policy')
46     current_ctx.set(mock_ctx)
47     tasks.policy_get()