# Path: ironicclient/exc.py
# class AmbiguousAuthSystem(exceptions.ClientException):
# class InvalidAttribute(exceptions.ClientException):
# class StateTransitionFailed(exceptions.ClientException):
# class StateTransitionTimeout(exceptions.ClientException):
# def from_response(response, message=None, traceback=None, method=None,
#                   url=None):
# 
# Path: ironicclient/tests/unit/utils.py
# class BaseTestCase(testtools.TestCase):
# class FakeAPI(object):
# class FakeConnection(object):
# class FakeResponse(object):
#     def setUp(self):
#     def __init__(self, responses, path_prefix=None):
#     def _request(self, method, url, headers=None, body=None, params=None):
#     def raw_request(self, *args, **kwargs):
#     def json_request(self, *args, **kwargs):
#     def __init__(self, response=None, path_prefix=None):
#     def request(self, method, conn_url, **kwargs):
#     def setresponse(self, response):
#     def getresponse(self):
#     def __repr__(self):
#     def __init__(self, headers, body=None, version=None, status=None,
#                  reason=None, request_headers={}):
#     def getheaders(self):
#     def getheader(self, key, default):
#     def read(self, amt):
#     def __repr__(self):
# def mockSessionResponse(headers, content=None, status_code=None, version=None,
#                         request_headers={}):
# def mockSession(headers, content=None, status_code=None, version=None):
# 
# Path: ironicclient/v1/create_resources.py
# def create_resources(client, filenames):
#     """Create resources using their JSON or YAML descriptions.
# 
#     :param client: an instance of ironic client;
#     :param filenames: a list of filenames containing JSON or YAML resources
#         definitions.
#     :raises: ClientException if any operation during files processing/resource
#         creation fails.
#     """
#     errors = []
#     resources = []
#     for resource_file in filenames:
#         try:
#             resource = load_from_file(resource_file)
#             jsonschema.validate(resource, _CREATE_SCHEMA)
#             resources.append(resource)
#         except (exc.ClientException, jsonschema.ValidationError) as e:
#             errors.append(e)
#     if errors:
#         raise exc.ClientException('While validating the resources file(s), the'
#                                   ' following error(s) were encountered:\n%s' %
#                                   '\n'.join(str(e) for e in errors))
#     for r in resources:
#         errors.extend(create_chassis(client, r.get('chassis', [])))
#         errors.extend(create_nodes(client, r.get('nodes', [])))
#     if errors:
#         raise exc.ClientException('During resources creation, the following '
#                                   'error(s) were encountered:\n%s' %
#                                   '\n'.join(str(e) for e in errors))


import builtins
import jsonschema
from unittest import mock
from ironicclient import exc
from ironicclient.tests.unit import utils
from ironicclient.v1 import create_resources


class CreateResourcesTest(utils.BaseTestCase):

    def setUp(self):
        super(CreateResourcesTest, self).setUp()
        self.client = mock.MagicMock()

    @mock.patch.object(create_resources, 'create_nodes', autospec=True)
    @mock.patch.object(create_resources, 'create_chassis', autospec=True)
    @mock.patch.object(jsonschema, 'validate', autospec=True)
    @mock.patch.object(create_resources, 'load_from_file',
                       side_effect=[valid_json], autospec=True)
    def test_create_resources(
            self, mock_load, mock_validate, mock_chassis, mock_nodes):
        resources_files = ['file.json']
        create_resources.create_resources(self.client, resources_files)
        mock_load.assert_has_calls([
            mock.call('file.json')
        ])
        mock_validate.assert_called_once_with(valid_json, mock.ANY)
        mock_chassis.assert_called_once_with(self.client,
                                             valid_json['chassis'])
        mock_nodes.assert_called_once_with(self.client,
                                           valid_json['nodes'])

    @mock.patch.object(create_resources, 'create_nodes', autospec=True)
    @mock.patch.object(create_resources, 'create_chassis', autospec=True)
    @mock.patch.object(jsonschema, 'validate', autospec=True)
    @mock.patch.object(create_resources, 'load_from_file',

# Path: ironicclient/exc.py
# class AmbiguousAuthSystem(exceptions.ClientException):
# class InvalidAttribute(exceptions.ClientException):
# class StateTransitionFailed(exceptions.ClientException):
# class StateTransitionTimeout(exceptions.ClientException):
# def from_response(response, message=None, traceback=None, method=None,
#                   url=None):
# 
# Path: ironicclient/tests/unit/utils.py
# class BaseTestCase(testtools.TestCase):
# class FakeAPI(object):
# class FakeConnection(object):
# class FakeResponse(object):
#     def setUp(self):
#     def __init__(self, responses, path_prefix=None):
#     def _request(self, method, url, headers=None, body=None, params=None):
#     def raw_request(self, *args, **kwargs):
#     def json_request(self, *args, **kwargs):
#     def __init__(self, response=None, path_prefix=None):
#     def request(self, method, conn_url, **kwargs):
#     def setresponse(self, response):
#     def getresponse(self):
#     def __repr__(self):
#     def __init__(self, headers, body=None, version=None, status=None,
#                  reason=None, request_headers={}):
#     def getheaders(self):
#     def getheader(self, key, default):
#     def read(self, amt):
#     def __repr__(self):
# def mockSessionResponse(headers, content=None, status_code=None, version=None,
#                         request_headers={}):
# def mockSession(headers, content=None, status_code=None, version=None):
# 
# Path: ironicclient/v1/create_resources.py
# def create_resources(client, filenames):
#     """Create resources using their JSON or YAML descriptions.
# 
#     :param client: an instance of ironic client;
#     :param filenames: a list of filenames containing JSON or YAML resources
#         definitions.
#     :raises: ClientException if any operation during files processing/resource
#         creation fails.
#     """
#     errors = []
#     resources = []
#     for resource_file in filenames:
#         try:
#             resource = load_from_file(resource_file)
#             jsonschema.validate(resource, _CREATE_SCHEMA)
#             resources.append(resource)
#         except (exc.ClientException, jsonschema.ValidationError) as e:
#             errors.append(e)
#     if errors:
#         raise exc.ClientException('While validating the resources file(s), the'
#                                   ' following error(s) were encountered:\n%s' %
#                                   '\n'.join(str(e) for e in errors))
#     for r in resources:
#         errors.extend(create_chassis(client, r.get('chassis', [])))
#         errors.extend(create_nodes(client, r.get('nodes', [])))
#     if errors:
#         raise exc.ClientException('During resources creation, the following '
#                                   'error(s) were encountered:\n%s' %
#                                   '\n'.join(str(e) for e in errors))


# Path: ironicclient/tests/unit/v1/test_create_resources.py
import builtins
import jsonschema
from unittest import mock
from ironicclient import exc
from ironicclient.tests.unit import utils
from ironicclient.v1 import create_resources



class CreateResourcesTest(utils.BaseTestCase):

    def setUp(self):
        super(CreateResourcesTest, self).setUp()
        self.client = mock.MagicMock()

    @mock.patch.object(create_resources, 'create_nodes', autospec=True)
    @mock.patch.object(create_resources, 'create_chassis', autospec=True)
    @mock.patch.object(jsonschema, 'validate', autospec=True)
    @mock.patch.object(create_resources, 'load_from_file',
                       side_effect=[valid_json], autospec=True)
    def test_create_resources(
            self, mock_load, mock_validate, mock_chassis, mock_nodes):
        resources_files = ['file.json']
        create_resources.create_resources(self.client, resources_files)
        mock_load.assert_has_calls([
            mock.call('file.json')
        ])
        mock_validate.assert_called_once_with(valid_json, mock.ANY)
        mock_chassis.assert_called_once_with(self.client,
                                             valid_json['chassis'])
        mock_nodes.assert_called_once_with(self.client,
                                           valid_json['nodes'])

    @mock.patch.object(create_resources, 'create_nodes', autospec=True)
    @mock.patch.object(create_resources, 'create_chassis', autospec=True)
    @mock.patch.object(jsonschema, 'validate', autospec=True)
    @mock.patch.object(create_resources, 'load_from_file',

                       side_effect=exc.ClientException, autospec=True)