# Path: cloudify_rest/tasks.py
# def _get_params_attributes(ctx, runtime_properties, params_list):
# def bunch_execute(templates=None, **kwargs):
# def execute(*argc, **kwargs):
# def execute_as_relationship(*argc, **kwargs):
# def execute_as_workflow(*args, **kwargs):
# def _execute_in_retry(template, params, instance_props, node_props,
#                       resource_callback=None, save_path=None,
#                       prerender=False, remove_calls=False, auth=None):
# def _execute(params, template_file, retry_count, retry_sleep, ctx, **kwargs):


import unittest
import requests_mock
import json
import os
import logging
from mock import MagicMock, patch
from cloudify.exceptions import RecoverableError, NonRecoverableError
from cloudify.mocks import MockCloudifyContext
from cloudify.state import current_ctx
from cloudify.manager import DirtyTrackingDict
from cloudify_rest import tasks
                 'id0': u'1',
                 'id1': u'101',
                 'owner1': {'id': 'Bob'},
                 'owner2': {'colour': 'red', 'name': 'bed', 'id': 'Carol'},
                 'owner0': {'colour': 'black', 'name': 'book'}})

    def test_execute_http_no_exception(self):
        _ctx = MockCloudifyContext('node_name',
                                   properties={'hosts': ['--fake.cake--',
                                                         'test123.test'],
                                               'port': -1,
                                               'ssl': False,
                                               'verify': False})
        _ctx.instance._runtime_properties = DirtyTrackingDict({})
        __location__ = os.path.realpath(
            os.path.join(os.getcwd(), os.path.dirname(__file__)))
        with open(os.path.join(__location__, 'template1.yaml'), 'r') as f:
            template = f.read()
        _ctx.get_resource = MagicMock(return_value=template.encode('utf-8'))
        _ctx.logger.setLevel(logging.DEBUG)
        current_ctx.set(_ctx)
        params = {'USER': 'testuser'}
        with requests_mock.mock(
                real_http=True) as m:  # real_http to check fake uri and get ex
            # call 1
            with open(
                os.path.join(__location__, 'get_response1.json'), 'r'
            ) as f:
                m.get('http://test123.test:80/testuser/test_rest/get',
                      json=json.load(f),

# Path: cloudify_rest/tasks.py
# def _get_params_attributes(ctx, runtime_properties, params_list):
# def bunch_execute(templates=None, **kwargs):
# def execute(*argc, **kwargs):
# def execute_as_relationship(*argc, **kwargs):
# def execute_as_workflow(*args, **kwargs):
# def _execute_in_retry(template, params, instance_props, node_props,
#                       resource_callback=None, save_path=None,
#                       prerender=False, remove_calls=False, auth=None):
# def _execute(params, template_file, retry_count, retry_sleep, ctx, **kwargs):


# Path: cloudify_rest/tests/test_plugin.py
import unittest
import requests_mock
import json
import os
import logging
from mock import MagicMock, patch
from cloudify.exceptions import RecoverableError, NonRecoverableError
from cloudify.mocks import MockCloudifyContext
from cloudify.state import current_ctx
from cloudify.manager import DirtyTrackingDict
from cloudify_rest import tasks

                 'id0': u'1',
                 'id1': u'101',
                 'owner1': {'id': 'Bob'},
                 'owner2': {'colour': 'red', 'name': 'bed', 'id': 'Carol'},
                 'owner0': {'colour': 'black', 'name': 'book'}})

    def test_execute_http_no_exception(self):
        _ctx = MockCloudifyContext('node_name',
                                   properties={'hosts': ['--fake.cake--',
                                                         'test123.test'],
                                               'port': -1,
                                               'ssl': False,
                                               'verify': False})
        _ctx.instance._runtime_properties = DirtyTrackingDict({})
        __location__ = os.path.realpath(
            os.path.join(os.getcwd(), os.path.dirname(__file__)))
        with open(os.path.join(__location__, 'template1.yaml'), 'r') as f:
            template = f.read()
        _ctx.get_resource = MagicMock(return_value=template.encode('utf-8'))
        _ctx.logger.setLevel(logging.DEBUG)
        current_ctx.set(_ctx)
        params = {'USER': 'testuser'}
        with requests_mock.mock(
                real_http=True) as m:  # real_http to check fake uri and get ex
            # call 1
            with open(
                os.path.join(__location__, 'get_response1.json'), 'r'
            ) as f:
                m.get('http://test123.test:80/testuser/test_rest/get',
                      json=json.load(f),

                      status_code=200)