# Path: armada/api/controller/tiller.py
# CONF = cfg.CONF
# LOG = logging.getLogger(__name__)
# class Status(api.BaseResource):
# class Release(api.BaseResource):
#     def on_get(self, req, resp):
#     def on_get(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/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 mock
from oslo_config import cfg
from armada.api.controller import tiller as tiller_controller
from armada.common.policies import base as policy_base
from armada.tests import test_utils
from armada.tests.unit.api import base
    def test_tiller_releases_with_params(self, mock_tiller):
        """Tests GET /api/v1.0/releases endpoint with query parameters."""
        rules = {'tiller:get_release': '@'}
        self.policy.set_rules(rules)

        def _get_fake_release(name, namespace):
            fake_release = mock.Mock(namespace='%s_namespace' % namespace)
            fake_release.configure_mock(name=name)
            return fake_release

        mock_tiller.return_value.list_releases.return_value = [
            _get_fake_release('foo', 'bar'), _get_fake_release('baz', 'qux')
        ]

        result = self.app.simulate_get('/api/v1.0/releases',
                                       params_csv=False,
                                       params={'tiller_host': 'fake_host',
                                               'tiller_port': '98765',
                                               'tiller_namespace': 'fake_ns'})
        expected = {
            'releases': {'bar_namespace': ['foo'], 'qux_namespace': ['baz']}
        }

        self.assertEqual(expected, result.json)
        mock_tiller.assert_called_once_with(tiller_host='fake_host',
                                            tiller_port=98765,
                                            tiller_namespace='fake_ns')
        mock_tiller.return_value.list_releases.assert_called_once_with()



# Path: armada/api/controller/tiller.py
# CONF = cfg.CONF
# LOG = logging.getLogger(__name__)
# class Status(api.BaseResource):
# class Release(api.BaseResource):
#     def on_get(self, req, resp):
#     def on_get(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/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_tiller_controller.py
import mock
from oslo_config import cfg
from armada.api.controller import tiller as tiller_controller
from armada.common.policies import base as policy_base
from armada.tests import test_utils
from armada.tests.unit.api import base

    def test_tiller_releases_with_params(self, mock_tiller):
        """Tests GET /api/v1.0/releases endpoint with query parameters."""
        rules = {'tiller:get_release': '@'}
        self.policy.set_rules(rules)

        def _get_fake_release(name, namespace):
            fake_release = mock.Mock(namespace='%s_namespace' % namespace)
            fake_release.configure_mock(name=name)
            return fake_release

        mock_tiller.return_value.list_releases.return_value = [
            _get_fake_release('foo', 'bar'), _get_fake_release('baz', 'qux')
        ]

        result = self.app.simulate_get('/api/v1.0/releases',
                                       params_csv=False,
                                       params={'tiller_host': 'fake_host',
                                               'tiller_port': '98765',
                                               'tiller_namespace': 'fake_ns'})
        expected = {
            'releases': {'bar_namespace': ['foo'], 'qux_namespace': ['baz']}
        }

        self.assertEqual(expected, result.json)
        mock_tiller.assert_called_once_with(tiller_host='fake_host',
                                            tiller_port=98765,
                                            tiller_namespace='fake_ns')
        mock_tiller.return_value.list_releases.assert_called_once_with()



class TillerControllerNegativeRbacTest(base.BaseControllerTest):