# Path: armada/api/controller/test.py
# CONF = cfg.CONF
# class TestReleasesReleaseNameController(api.BaseResource):
# class TestReleasesManifestController(api.BaseResource):
#     def on_get(self, req, resp, release):
#     def _format_validation_response(self, req, resp, result, details):
#     def _validate_documents(self, req, resp, documents):
#     def on_post(self, req, resp):
# 
# Path: armada/common/policies/base.py
# ARMADA = 'armada:%s'
# TILLER = 'tiller:%s'
# RULE_ADMIN_REQUIRED = 'rule:admin_required'
# RULE_ADMIN_OR_TARGET_PROJECT = (
#     'rule:admin_required or project_id:%(target.project.id)s')
# RULE_SERVICE_OR_ADMIN = 'rule:service_or_admin'
# def list_rules():
# 
# Path: armada/exceptions/manifest_exceptions.py
# class ManifestException(base.ArmadaBaseException):
# 
# Path: armada/tests/test_utils.py
# def rand_uuid_hex():
# def rand_name(name='', prefix='armada'):
# def rand_bool():
# def rand_int(min, max):
# def rand_password(length=15):
# def attr(**kwargs):
#     def decorator(f):
# 
# Path: armada/tests/unit/api/base.py
# class BaseControllerTest(test_base.ArmadaTestCase):
#     def setUp(self):


import json
import os
import yaml
import mock
from armada.api.controller import test
from armada.common.policies import base as policy_base
from armada.exceptions import manifest_exceptions
from armada.tests import test_utils
from armada.tests.unit.api import base
        self.policy.set_rules(rules)

        mock_manifest.return_value.get_manifest.side_effect = (
            manifest_exceptions.ManifestException(details='foo'))

        manifest_path = os.path.join(os.getcwd(), 'examples',
                                     'keystone-manifest.yaml')
        with open(manifest_path, 'r') as f:
            payload = f.read()

        resp = self.app.simulate_post('/api/v1.0/tests', body=payload)
        self.assertEqual(400, resp.status_code)

        resp_body = json.loads(resp.text)
        self.assertEqual(400, resp_body['code'])
        self.assertEqual(1, resp_body['details']['errorCount'])
        self.assertEqual(
            [{'message': (
                'An error occurred while generating the manifest: foo.'),
              'error': True,
              'kind': 'ValidationMessage',
              'level': 'Error',
              'name': 'ARM001',
              'documents': []}],
            resp_body['details']['messageList'])
        self.assertEqual(('Failed to validate documents or generate Armada '
                          'Manifest from documents.'),
                         resp_body['message'])



# Path: armada/api/controller/test.py
# CONF = cfg.CONF
# class TestReleasesReleaseNameController(api.BaseResource):
# class TestReleasesManifestController(api.BaseResource):
#     def on_get(self, req, resp, release):
#     def _format_validation_response(self, req, resp, result, details):
#     def _validate_documents(self, req, resp, documents):
#     def on_post(self, req, resp):
# 
# Path: armada/common/policies/base.py
# ARMADA = 'armada:%s'
# TILLER = 'tiller:%s'
# RULE_ADMIN_REQUIRED = 'rule:admin_required'
# RULE_ADMIN_OR_TARGET_PROJECT = (
#     'rule:admin_required or project_id:%(target.project.id)s')
# RULE_SERVICE_OR_ADMIN = 'rule:service_or_admin'
# def list_rules():
# 
# Path: armada/exceptions/manifest_exceptions.py
# class ManifestException(base.ArmadaBaseException):
# 
# Path: armada/tests/test_utils.py
# def rand_uuid_hex():
# def rand_name(name='', prefix='armada'):
# def rand_bool():
# def rand_int(min, max):
# def rand_password(length=15):
# def attr(**kwargs):
#     def decorator(f):
# 
# Path: armada/tests/unit/api/base.py
# class BaseControllerTest(test_base.ArmadaTestCase):
#     def setUp(self):


# Path: armada/tests/unit/api/test_test_controller.py
import json
import os
import yaml
import mock
from armada.api.controller import test
from armada.common.policies import base as policy_base
from armada.exceptions import manifest_exceptions
from armada.tests import test_utils
from armada.tests.unit.api import base

        self.policy.set_rules(rules)

        mock_manifest.return_value.get_manifest.side_effect = (
            manifest_exceptions.ManifestException(details='foo'))

        manifest_path = os.path.join(os.getcwd(), 'examples',
                                     'keystone-manifest.yaml')
        with open(manifest_path, 'r') as f:
            payload = f.read()

        resp = self.app.simulate_post('/api/v1.0/tests', body=payload)
        self.assertEqual(400, resp.status_code)

        resp_body = json.loads(resp.text)
        self.assertEqual(400, resp_body['code'])
        self.assertEqual(1, resp_body['details']['errorCount'])
        self.assertEqual(
            [{'message': (
                'An error occurred while generating the manifest: foo.'),
              'error': True,
              'kind': 'ValidationMessage',
              'level': 'Error',
              'name': 'ARM001',
              'documents': []}],
            resp_body['details']['messageList'])
        self.assertEqual(('Failed to validate documents or generate Armada '
                          'Manifest from documents.'),
                         resp_body['message'])



@test_utils.attr(type=['negative'])