# 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/actions.py
# class Action(base.Resource):
# class ActionManager(base.ResourceManager):
#     def create(self, definition, scope='private', namespace=''):
#     def update(self, definition, scope='private', id=None, namespace=''):
#     def list(self, marker='', limit=None, sort_keys='', sort_dirs='',
#              fields='', namespace='', **filters):
#     def get(self, identifier, namespace=''):
#     def delete(self, identifier, namespace=''):
#     def validate(self, definition):
# 
# Path: mistralclient/tests/unit/v2/base.py
# class BaseClientV2Test(base.BaseClientTest):
#     TEST_URL = 'http://mistral.example.com'
#     def setUp(self):


import os.path
import pkg_resources as pkg
from urllib import parse
from urllib import request
from mistralclient.api import base as api_base
from mistralclient.api.v2 import actions
from mistralclient.tests.unit.v2 import base
        self.assertIsNotNone(result)
        self.assertIn('valid', result)
        self.assertTrue(result['valid'])

        last_request = self.requests_mock.last_request
        self.assertEqual(ACTION_DEF, last_request.text)
        self.assertEqual('text/plain', last_request.headers['content-type'])

    def test_validate_failed(self):
        self.requests_mock.post(self.TEST_URL + URL_TEMPLATE_VALIDATE,
                                json={"valid": False,
                                      "error": "mocked error message"})

        result = self.actions.validate(INVALID_ACTION_DEF)

        self.assertIsNotNone(result)
        self.assertIn('valid', result)
        self.assertFalse(result['valid'])
        self.assertIn('error', result)
        self.assertIn("mocked error message", result['error'])

        last_request = self.requests_mock.last_request
        self.assertEqual('text/plain', last_request.headers['content-type'])

    def test_validate_api_failed(self):
        self.requests_mock.post(self.TEST_URL + URL_TEMPLATE_VALIDATE,
                                status_code=500,
                                json={})

        self.assertRaises(

# 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/actions.py
# class Action(base.Resource):
# class ActionManager(base.ResourceManager):
#     def create(self, definition, scope='private', namespace=''):
#     def update(self, definition, scope='private', id=None, namespace=''):
#     def list(self, marker='', limit=None, sort_keys='', sort_dirs='',
#              fields='', namespace='', **filters):
#     def get(self, identifier, namespace=''):
#     def delete(self, identifier, namespace=''):
#     def validate(self, definition):
# 
# Path: mistralclient/tests/unit/v2/base.py
# class BaseClientV2Test(base.BaseClientTest):
#     TEST_URL = 'http://mistral.example.com'
#     def setUp(self):


# Path: mistralclient/tests/unit/v2/test_actions.py
import os.path
import pkg_resources as pkg
from urllib import parse
from urllib import request
from mistralclient.api import base as api_base
from mistralclient.api.v2 import actions
from mistralclient.tests.unit.v2 import base

        self.assertIsNotNone(result)
        self.assertIn('valid', result)
        self.assertTrue(result['valid'])

        last_request = self.requests_mock.last_request
        self.assertEqual(ACTION_DEF, last_request.text)
        self.assertEqual('text/plain', last_request.headers['content-type'])

    def test_validate_failed(self):
        self.requests_mock.post(self.TEST_URL + URL_TEMPLATE_VALIDATE,
                                json={"valid": False,
                                      "error": "mocked error message"})

        result = self.actions.validate(INVALID_ACTION_DEF)

        self.assertIsNotNone(result)
        self.assertIn('valid', result)
        self.assertFalse(result['valid'])
        self.assertIn('error', result)
        self.assertIn("mocked error message", result['error'])

        last_request = self.requests_mock.last_request
        self.assertEqual('text/plain', last_request.headers['content-type'])

    def test_validate_api_failed(self):
        self.requests_mock.post(self.TEST_URL + URL_TEMPLATE_VALIDATE,
                                status_code=500,
                                json={})

        self.assertRaises(

            api_base.APIException,