# Path: monasca_api/common/policy/policy_engine.py
# CONF = cfg.CONF
# LOG = logging.getLogger(__name__)
# POLICIES = None
# USER_BASED_RESOURCES = ['os-keypairs']
# KEY_EXPR = re.compile(r'%\((\w+)\)s')
# _ENFORCER = None
# DEFAULT_POLICY_FILE = 'policy.yaml'
#         _ENFORCER = None
#         _ENFORCER = policy.Enforcer(CONF,
#                                     policy_file=policy_file,
#                                     rules=rules,
#                                     default_rule=default_rule,
#                                     use_conf=use_conf
#                                     )
# def reset():
# def init(policy_file=None, rules=None, default_rule=None, use_conf=True):
# def _serialize_rules(rules):
# def _warning_for_deprecated_user_based_rules(rules):
# def register_rules(enforcer):
# def authorize(context, action, target, do_raise=True):
# def check_is_admin(context):
# def set_rules(rules, overwrite=True, use_conf=False):  # pragma: no cover
# def verify_deprecated_policy(old_policy, new_policy, default_rule, context):
# def get_rules():
# def get_enforcer():
#     def __init__(self, kind, match):
#     def __call__(self, target, creds, enforcer):
# class IsAdminCheck(policy.Check):


from falcon import testing
from oslo_context import context
from oslo_policy import policy as os_policy
from monasca_api.api.core import request
from monasca_api.common.policy import policy_engine as policy
from monasca_api.policies import roles_list_to_check_str
from monasca_api.tests import base
        self.delegate_roles = ['admin']

    def test_alarms_policies_roles(self):
        alarms_policies = {
            'api:alarms:definition:post': self.default_roles,
            'api:alarms:definition:get':
                self.default_roles + self.readonly_roles,
            'api:alarms:definition:put': self.default_roles,
            'api:alarms:definition:patch': self.default_roles,
            'api:alarms:definition:delete': self.default_roles,
            'api:alarms:put': self.default_roles,
            'api:alarms:patch': self.default_roles,
            'api:alarms:delete': self.default_roles,
            'api:alarms:get': self.default_roles + self.readonly_roles,
            'api:alarms:count': self.default_roles + self.readonly_roles,
            'api:alarms:state_history': self.default_roles + self.readonly_roles
        }

        self._assert_rules(alarms_policies)

    def test_metrics_policies_roles(self):
        metrics_policies = {
            'api:metrics:get': self.default_roles + self.readonly_roles,
            'api:metrics:post': self.agent_roles + self.default_roles,
            'api:metrics:dimension:values':
                self.default_roles + self.readonly_roles,
            'api:metrics:dimension:names':
                self.default_roles + self.readonly_roles

        }

# Path: monasca_api/common/policy/policy_engine.py
# CONF = cfg.CONF
# LOG = logging.getLogger(__name__)
# POLICIES = None
# USER_BASED_RESOURCES = ['os-keypairs']
# KEY_EXPR = re.compile(r'%\((\w+)\)s')
# _ENFORCER = None
# DEFAULT_POLICY_FILE = 'policy.yaml'
#         _ENFORCER = None
#         _ENFORCER = policy.Enforcer(CONF,
#                                     policy_file=policy_file,
#                                     rules=rules,
#                                     default_rule=default_rule,
#                                     use_conf=use_conf
#                                     )
# def reset():
# def init(policy_file=None, rules=None, default_rule=None, use_conf=True):
# def _serialize_rules(rules):
# def _warning_for_deprecated_user_based_rules(rules):
# def register_rules(enforcer):
# def authorize(context, action, target, do_raise=True):
# def check_is_admin(context):
# def set_rules(rules, overwrite=True, use_conf=False):  # pragma: no cover
# def verify_deprecated_policy(old_policy, new_policy, default_rule, context):
# def get_rules():
# def get_enforcer():
#     def __init__(self, kind, match):
#     def __call__(self, target, creds, enforcer):
# class IsAdminCheck(policy.Check):


# Path: monasca_api/tests/test_policy.py
from falcon import testing
from oslo_context import context
from oslo_policy import policy as os_policy
from monasca_api.api.core import request
from monasca_api.common.policy import policy_engine as policy
from monasca_api.policies import roles_list_to_check_str
from monasca_api.tests import base

        self.delegate_roles = ['admin']

    def test_alarms_policies_roles(self):
        alarms_policies = {
            'api:alarms:definition:post': self.default_roles,
            'api:alarms:definition:get':
                self.default_roles + self.readonly_roles,
            'api:alarms:definition:put': self.default_roles,
            'api:alarms:definition:patch': self.default_roles,
            'api:alarms:definition:delete': self.default_roles,
            'api:alarms:put': self.default_roles,
            'api:alarms:patch': self.default_roles,
            'api:alarms:delete': self.default_roles,
            'api:alarms:get': self.default_roles + self.readonly_roles,
            'api:alarms:count': self.default_roles + self.readonly_roles,
            'api:alarms:state_history': self.default_roles + self.readonly_roles
        }

        self._assert_rules(alarms_policies)

    def test_metrics_policies_roles(self):
        metrics_policies = {
            'api:metrics:get': self.default_roles + self.readonly_roles,
            'api:metrics:post': self.agent_roles + self.default_roles,
            'api:metrics:dimension:values':
                self.default_roles + self.readonly_roles,
            'api:metrics:dimension:names':
                self.default_roles + self.readonly_roles

        }

        self._assert_rules(metrics_policies)