# Path: mistralclient/api/base.py
# class Resource(object):
# class ResourceManager(object):
# class APIException(Exception):
#     def __init__(self, manager, data):
#     def _set_defaults(self):
#     def _set_attributes(self):
#     def to_dict(self):
#     def __str__(self):
# def _check_items(obj, searches):
# def extract_json(response, response_key):
#     def __init__(self, http_client, enforce_raw_definitions=False):
#     def get_contents_if_file(self, contents_or_file_name):
#     def find(self, **kwargs):
#     def list(self):
#     def _build_query_params(marker=None, limit=None, sort_keys=None,
#                             sort_dirs=None, fields=None, filters=None,
#                             scope=None, namespace=None):
#     def _ensure_not_empty(self, **kwargs):
#     def _validate(self, url, data, response_key=None, dump_json=True,
#                   headers=None, is_iter_resp=False):
#     def _create(self, url, data, response_key=None, dump_json=True,
#                 headers=None, is_iter_resp=False, resp_status_ok=201,
#                 as_class=True):
#     def _update(self, url, data, response_key=None, dump_json=True,
#                 headers=None, is_iter_resp=False):
#     def _list(self, url, response_key=None, headers=None,
#               returned_res_cls=None):
#     def _get(self, url, response_key=None, headers=None):
#     def _delete(self, url, headers=None):
#     def _raise_api_exception(resp):
# def get_json(response):
#     def __init__(self, error_code=None, error_message=None):
# 
# Path: mistralclient/api/v2/environments.py
# class Environment(base.Resource):
# class EnvironmentManager(base.ResourceManager):
#     def _set_attributes(self):
#     def create(self, **kwargs):
#     def update(self, **kwargs):
#     def list(self, marker='', limit=None, sort_keys='', sort_dirs='',
#              fields='', **filters):
#     def get(self, name):
#     def delete(self, name):
# 
# Path: mistralclient/tests/unit/v2/base.py
# class BaseClientV2Test(base.BaseClientTest):
#     TEST_URL = 'http://mistral.example.com'
#     def setUp(self):
# 
# Path: mistralclient/utils.py
# def do_action_on_many(action, resources, success_msg, error_msg):
# def load_content(content):
# def load_file(path):
# def get_contents_if_file(contents_or_file_name):
# def load_json(input_string):


import collections
import copy
import os.path
import pkg_resources as pkg
from oslo_serialization import jsonutils
from urllib import parse
from urllib import request
from mistralclient.api import base as api_base
from mistralclient.api.v2 import environments
from mistralclient.tests.unit.v2 import base
from mistralclient import utils
            'tests/unit/resources/env_v2.json'
        )
        path = os.path.abspath(path)

        # Convert the file path to file URI
        uri = parse.urljoin('file:', request.pathname2url(path))
        data = collections.OrderedDict(
            utils.load_content(
                utils.get_contents_if_file(uri)
            )
        )

        self.requests_mock.post(self.TEST_URL + URL_TEMPLATE,
                                status_code=201,
                                json=data)
        file_input = {'file': uri}
        env = self.environments.create(**file_input)

        self.assertIsNotNone(env)

        expected_data = copy.deepcopy(data)
        expected_data['variables'] = jsonutils.dumps(
            expected_data['variables'])

        self.assertEqual(expected_data, self.requests_mock.last_request.json())

    def test_create_without_name(self):
        data = copy.deepcopy(ENVIRONMENT)
        data.pop('name')


# Path: mistralclient/api/base.py
# class Resource(object):
# class ResourceManager(object):
# class APIException(Exception):
#     def __init__(self, manager, data):
#     def _set_defaults(self):
#     def _set_attributes(self):
#     def to_dict(self):
#     def __str__(self):
# def _check_items(obj, searches):
# def extract_json(response, response_key):
#     def __init__(self, http_client, enforce_raw_definitions=False):
#     def get_contents_if_file(self, contents_or_file_name):
#     def find(self, **kwargs):
#     def list(self):
#     def _build_query_params(marker=None, limit=None, sort_keys=None,
#                             sort_dirs=None, fields=None, filters=None,
#                             scope=None, namespace=None):
#     def _ensure_not_empty(self, **kwargs):
#     def _validate(self, url, data, response_key=None, dump_json=True,
#                   headers=None, is_iter_resp=False):
#     def _create(self, url, data, response_key=None, dump_json=True,
#                 headers=None, is_iter_resp=False, resp_status_ok=201,
#                 as_class=True):
#     def _update(self, url, data, response_key=None, dump_json=True,
#                 headers=None, is_iter_resp=False):
#     def _list(self, url, response_key=None, headers=None,
#               returned_res_cls=None):
#     def _get(self, url, response_key=None, headers=None):
#     def _delete(self, url, headers=None):
#     def _raise_api_exception(resp):
# def get_json(response):
#     def __init__(self, error_code=None, error_message=None):
# 
# Path: mistralclient/api/v2/environments.py
# class Environment(base.Resource):
# class EnvironmentManager(base.ResourceManager):
#     def _set_attributes(self):
#     def create(self, **kwargs):
#     def update(self, **kwargs):
#     def list(self, marker='', limit=None, sort_keys='', sort_dirs='',
#              fields='', **filters):
#     def get(self, name):
#     def delete(self, name):
# 
# Path: mistralclient/tests/unit/v2/base.py
# class BaseClientV2Test(base.BaseClientTest):
#     TEST_URL = 'http://mistral.example.com'
#     def setUp(self):
# 
# Path: mistralclient/utils.py
# def do_action_on_many(action, resources, success_msg, error_msg):
# def load_content(content):
# def load_file(path):
# def get_contents_if_file(contents_or_file_name):
# def load_json(input_string):


# Path: mistralclient/tests/unit/v2/test_environments.py
import collections
import copy
import os.path
import pkg_resources as pkg
from oslo_serialization import jsonutils
from urllib import parse
from urllib import request
from mistralclient.api import base as api_base
from mistralclient.api.v2 import environments
from mistralclient.tests.unit.v2 import base
from mistralclient import utils

            'tests/unit/resources/env_v2.json'
        )
        path = os.path.abspath(path)

        # Convert the file path to file URI
        uri = parse.urljoin('file:', request.pathname2url(path))
        data = collections.OrderedDict(
            utils.load_content(
                utils.get_contents_if_file(uri)
            )
        )

        self.requests_mock.post(self.TEST_URL + URL_TEMPLATE,
                                status_code=201,
                                json=data)
        file_input = {'file': uri}
        env = self.environments.create(**file_input)

        self.assertIsNotNone(env)

        expected_data = copy.deepcopy(data)
        expected_data['variables'] = jsonutils.dumps(
            expected_data['variables'])

        self.assertEqual(expected_data, self.requests_mock.last_request.json())

    def test_create_without_name(self):
        data = copy.deepcopy(ENVIRONMENT)
        data.pop('name')


        e = self.assertRaises(api_base.APIException,