# 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 errors
from falcon import testing
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.tests import base
from monasca_api.common.rest import utils as rest_utils
import monasca_api.v2.reference.helpers as helpers
    def test_validate_json_content_type(self):
        req = request.Request(
            testing.create_environ(
                headers={'Content-Type': 'application/json'}
            )
        )
        helpers.validate_json_content_type(req)

    def test_validate_json_content_type_incorrect_content_type(self):
        req = request.Request(
            testing.create_environ(
                headers={'Content-Type': 'multipart/form-data'}
            )
        )
        self.assertRaises(errors.HTTPBadRequest, helpers.validate_json_content_type, req)

    def test_validate_json_content_type_missing_content_type(self):
        req = request.Request(testing.create_environ())
        self.assertRaises(errors.HTTPBadRequest, helpers.validate_json_content_type, req)


class TestGetXTenantOrTenantId(base.BaseApiTestCase):
    def setUp(self):
        super(TestGetXTenantOrTenantId, self).setUp()
        rules = [
            os_policy.RuleDefault("example:allowed", "@"),
            os_policy.RuleDefault("example:denied", "!"),
            os_policy.RuleDefault("example:authorized",
                                  "role:role_1 or role:role_2")
        ]

# 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_helpers.py
from falcon import errors
from falcon import testing
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.tests import base
from monasca_api.common.rest import utils as rest_utils
import monasca_api.v2.reference.helpers as helpers

    def test_validate_json_content_type(self):
        req = request.Request(
            testing.create_environ(
                headers={'Content-Type': 'application/json'}
            )
        )
        helpers.validate_json_content_type(req)

    def test_validate_json_content_type_incorrect_content_type(self):
        req = request.Request(
            testing.create_environ(
                headers={'Content-Type': 'multipart/form-data'}
            )
        )
        self.assertRaises(errors.HTTPBadRequest, helpers.validate_json_content_type, req)

    def test_validate_json_content_type_missing_content_type(self):
        req = request.Request(testing.create_environ())
        self.assertRaises(errors.HTTPBadRequest, helpers.validate_json_content_type, req)


class TestGetXTenantOrTenantId(base.BaseApiTestCase):
    def setUp(self):
        super(TestGetXTenantOrTenantId, self).setUp()
        rules = [
            os_policy.RuleDefault("example:allowed", "@"),
            os_policy.RuleDefault("example:denied", "!"),
            os_policy.RuleDefault("example:authorized",
                                  "role:role_1 or role:role_2")
        ]

        policy.reset()