# Path: cloudify_deployment_proxy/tests/base.py
# class DeploymentProxyTestBase(testtools.TestCase):
# 
#     def tearDown(self):
#         current_ctx.clear()
#         super(DeploymentProxyTestBase, self).tearDown()
# 
#     def get_mock_ctx(self,
#                      test_name,
#                      test_properties=DEPLOYMENT_PROXY_PROPS,
#                      node_type=DEPLOYMENT_PROXY_TYPE,
#                      retry_number=0):
# 
#         test_node_id = test_name
#         test_properties = test_properties
# 
#         operation = json.loads(json.dumps({
#             'retry_number': retry_number
#         }))
#         ctx = MockCloudifyContext(
#             node_id=test_node_id,
#             deployment_id=test_name,
#             operation=operation,
#             properties=test_properties
#         )
# 
#         ctx.operation._operation_context = json.loads(json.dumps(
#             {'name': 'some.test'}))
#         ctx.node.type_hierarchy = \
#             json.loads(json.dumps(['cloudify.nodes.Root', node_type]))
#         try:
#             ctx.node.type = node_type
#         except AttributeError:
#             ctx.logger.error('Failed to set node type attribute.')
# 
#         return ctx
# 
# Path: cloudify_deployment_proxy/tests/client_mock.py
# class MockCloudifyRestClient(object):
# 
#     def __init__(self):
#         self.blueprints = MockBlueprintsClient()
#         self.deployments = MockDeploymentsClient()
#         self.executions = MockExecutionsClient()
#         self.node_instances = MockNodeInstancesClient()
#         self.events = MockEventsClient()
#         self.secrets = MagicMock()
#         self.plugins = MagicMock()


import mock
from cloudify.state import current_ctx
from cloudify.exceptions import NonRecoverableError
from cloudify_rest_client.exceptions import CloudifyClientError
from ..tasks import upload_blueprint
from .base import DeploymentProxyTestBase
from ..constants import EXTERNAL_RESOURCE
from .client_mock import MockCloudifyRestClient
            list_response = cfy_mock_client.blueprints.list()
            list_response[0]['id'] = test_name

            blueprint_params = {}
            blueprint_params['blueprint'] = {}
            blueprint_params['blueprint']['blueprint_id'] = test_name
            blueprint_params['blueprint']['blueprint_archive'] = archive
            blueprint_params['blueprint'][EXTERNAL_RESOURCE] = True
            self.resource_config['resource_config'] = blueprint_params

            def mock_return(*args, **kwargs):
                del args, kwargs
                return list_response

            cfy_mock_client.blueprints.list = mock_return
            mock_client.return_value = cfy_mock_client
            output = upload_blueprint(operation='upload_blueprint',
                                      **self.resource_config)
            self.assertFalse(output)

    def test_upload_blueprint_success(self):
        # Test that upload blueprint succeeds

        test_name = 'test_upload_blueprint_success'
        archive = 'sample_file.zip'
        _ctx = self.get_mock_ctx(test_name)
        _ctx._resources = {'sample_file.zip': 'Sample Blueprint'}
        current_ctx.set(_ctx)

        with mock.patch('cloudify.manager.get_rest_client') as mock_client:

# Path: cloudify_deployment_proxy/tests/base.py
# class DeploymentProxyTestBase(testtools.TestCase):
# 
#     def tearDown(self):
#         current_ctx.clear()
#         super(DeploymentProxyTestBase, self).tearDown()
# 
#     def get_mock_ctx(self,
#                      test_name,
#                      test_properties=DEPLOYMENT_PROXY_PROPS,
#                      node_type=DEPLOYMENT_PROXY_TYPE,
#                      retry_number=0):
# 
#         test_node_id = test_name
#         test_properties = test_properties
# 
#         operation = json.loads(json.dumps({
#             'retry_number': retry_number
#         }))
#         ctx = MockCloudifyContext(
#             node_id=test_node_id,
#             deployment_id=test_name,
#             operation=operation,
#             properties=test_properties
#         )
# 
#         ctx.operation._operation_context = json.loads(json.dumps(
#             {'name': 'some.test'}))
#         ctx.node.type_hierarchy = \
#             json.loads(json.dumps(['cloudify.nodes.Root', node_type]))
#         try:
#             ctx.node.type = node_type
#         except AttributeError:
#             ctx.logger.error('Failed to set node type attribute.')
# 
#         return ctx
# 
# Path: cloudify_deployment_proxy/tests/client_mock.py
# class MockCloudifyRestClient(object):
# 
#     def __init__(self):
#         self.blueprints = MockBlueprintsClient()
#         self.deployments = MockDeploymentsClient()
#         self.executions = MockExecutionsClient()
#         self.node_instances = MockNodeInstancesClient()
#         self.events = MockEventsClient()
#         self.secrets = MagicMock()
#         self.plugins = MagicMock()


# Path: cloudify_deployment_proxy/tests/test_blueprints.py
import mock
from cloudify.state import current_ctx
from cloudify.exceptions import NonRecoverableError
from cloudify_rest_client.exceptions import CloudifyClientError
from ..tasks import upload_blueprint
from .base import DeploymentProxyTestBase
from ..constants import EXTERNAL_RESOURCE
from .client_mock import MockCloudifyRestClient

            list_response = cfy_mock_client.blueprints.list()
            list_response[0]['id'] = test_name

            blueprint_params = {}
            blueprint_params['blueprint'] = {}
            blueprint_params['blueprint']['blueprint_id'] = test_name
            blueprint_params['blueprint']['blueprint_archive'] = archive
            blueprint_params['blueprint'][EXTERNAL_RESOURCE] = True
            self.resource_config['resource_config'] = blueprint_params

            def mock_return(*args, **kwargs):
                del args, kwargs
                return list_response

            cfy_mock_client.blueprints.list = mock_return
            mock_client.return_value = cfy_mock_client
            output = upload_blueprint(operation='upload_blueprint',
                                      **self.resource_config)
            self.assertFalse(output)

    def test_upload_blueprint_success(self):
        # Test that upload blueprint succeeds

        test_name = 'test_upload_blueprint_success'
        archive = 'sample_file.zip'
        _ctx = self.get_mock_ctx(test_name)
        _ctx._resources = {'sample_file.zip': 'Sample Blueprint'}
        current_ctx.set(_ctx)

        with mock.patch('cloudify.manager.get_rest_client') as mock_client:

            mock_client.return_value = MockCloudifyRestClient()