# 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
    def test_test_controller_test_fail(self, mock_tiller):
        rules = {'armada:test_release': '@'}
        self.policy.set_rules(rules)

        testing_release = mock_tiller.return_value.testing_release
        testing_release.return_value = mock.Mock(
            **{'info.status.last_test_suite_run.result': [
                mock.Mock(status='FAILED')]})

        resp = self.app.simulate_get('/api/v1.0/test/fake-release')
        self.assertEqual(200, resp.status_code)
        self.assertEqual('MESSAGE: Test Fail',
                         json.loads(resp.text)['message'])

    @mock.patch.object(test, 'Tiller')
    def test_test_controller_no_test_found(self, mock_tiller):
        rules = {'armada:test_release': '@'}
        self.policy.set_rules(rules)

        mock_tiller.return_value.testing_release.return_value = None

        resp = self.app.simulate_get('/api/v1.0/test/fake-release')
        self.assertEqual(200, resp.status_code)
        self.assertEqual('MESSAGE: No test found',
                         json.loads(resp.text)['message'])


@test_utils.attr(type=['negative'])
class TestReleasesManifestControllerNegativeTest(base.BaseControllerTest):


# 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

    def test_test_controller_test_fail(self, mock_tiller):
        rules = {'armada:test_release': '@'}
        self.policy.set_rules(rules)

        testing_release = mock_tiller.return_value.testing_release
        testing_release.return_value = mock.Mock(
            **{'info.status.last_test_suite_run.result': [
                mock.Mock(status='FAILED')]})

        resp = self.app.simulate_get('/api/v1.0/test/fake-release')
        self.assertEqual(200, resp.status_code)
        self.assertEqual('MESSAGE: Test Fail',
                         json.loads(resp.text)['message'])

    @mock.patch.object(test, 'Tiller')
    def test_test_controller_no_test_found(self, mock_tiller):
        rules = {'armada:test_release': '@'}
        self.policy.set_rules(rules)

        mock_tiller.return_value.testing_release.return_value = None

        resp = self.app.simulate_get('/api/v1.0/test/fake-release')
        self.assertEqual(200, resp.status_code)
        self.assertEqual('MESSAGE: No test found',
                         json.loads(resp.text)['message'])


@test_utils.attr(type=['negative'])
class TestReleasesManifestControllerNegativeTest(base.BaseControllerTest):


    @mock.patch.object(test, 'Manifest')