# Path: monasca_api/common/repositories/model/sub_alarm_definition.py
# class SubAlarmDefinition(object):
#     def __init__(self, row=None, sub_expr=None):
#     def _init_dimensions(self, dimensions_str):
#     def expression(self):
#     def __hash__(self):
#     def __repr__(self):
#     def __eq__(self, other):
#     def same_key_fields(self, other):
# 
# Path: monasca_api/v2/common/exceptions.py
# class HTTPUnprocessableEntityError(HTTPError):
#     def __init__(self, title, description, **kwargs):
#         HTTPError.__init__(self, '422 Unprocessable Entity', title, description, **kwargs)
# 
# Path: monasca_api/v2/reference/alarms.py
# LOG = log.getLogger(__name__)
# class Alarms(alarms_api_v2.AlarmsV2API,
#              alarming.Alarming):
# class AlarmsCount(alarms_api_v2.AlarmsCountV2API, alarming.Alarming):
# class AlarmsStateHistory(alarms_api_v2.AlarmsStateHistoryV2API,
#                          alarming.Alarming):
#     def __init__(self):
#     def on_put(self, req, res, alarm_id):
#     def on_patch(self, req, res, alarm_id):
#     def on_delete(self, req, res, alarm_id):
#     def on_get(self, req, res, alarm_id=None):
#     def _alarm_update(self, tenant_id, alarm_id, new_state, lifecycle_state,
#                       link):
#     def _alarm_patch(self, tenant_id, alarm_id, new_state, lifecycle_state,
#                      link):
#     def _alarm_delete(self, tenant_id, id):
#     def _alarm_show(self, req_uri, tenant_id, alarm_id):
#     def _alarm_list(self, req_uri, tenant_id, query_parms, offset, limit):
#     def __init__(self):
#     def on_get(self, req, res):
#     def _alarms_count(self, req_uri, tenant_id, query_parms, offset, limit):
#     def _validate_group_by(self, group_by):
#     def __init__(self):
#     def on_get(self, req, res, alarm_id=None):
#     def _alarm_history_list(self, tenant_id, start_timestamp,
#                             end_timestamp, dimensions, req_uri, offset,
#                             limit):
#     def _alarm_history(self, tenant_id, alarm_id, req_uri, offset, limit):


from collections import OrderedDict
from unittest.mock import Mock
from monasca_api.common.repositories.model import sub_alarm_definition
from monasca_api.tests import base
from monasca_api.v2.common.exceptions import HTTPUnprocessableEntityError
from monasca_api.v2.reference import alarm_definitions
from monasca_api.v2.reference import alarms
import copy
import datetime
import json
import falcon.testing
import fixtures
import testtools.matchers as matchers
import oslo_config.fixture
import six
        response = self.simulate_request(
            path="/v2.0/alarm-definitions/",
            headers={
                'X-Roles': CONF.security.default_authorized_roles[0],
                'X-Tenant-Id': TENANT_ID},
            method="DELETE")

        self.assertEqual(response.status, falcon.HTTP_400)

    def test_alarm_definition_patch(self):
        self.alarm_def_repo_mock.return_value.get_alarm_definitions.return_value = []
        description = u'Non-ASCII character: \u2603'
        new_name = u'Test Alarm Updated'
        actions_enabled = True
        alarm_def_id = u'00000001-0001-0001-0001-000000000001'
        alarm_expression = u'max(test.metric{hostname=host}) gte 1'
        severity = u'LOW'
        match_by = u'hostname'
        self.alarm_def_repo_mock.return_value.update_or_patch_alarm_definition.return_value = (
            {u'alarm_actions': [],
             u'ok_actions': [],
             u'description': description,
             u'match_by': match_by,
             u'name': new_name,
             u'actions_enabled': actions_enabled,
             u'undetermined_actions': [],
             u'is_deterministic': False,
             u'expression': alarm_expression,
             u'id': alarm_def_id,
             u'severity': severity},

# Path: monasca_api/common/repositories/model/sub_alarm_definition.py
# class SubAlarmDefinition(object):
#     def __init__(self, row=None, sub_expr=None):
#     def _init_dimensions(self, dimensions_str):
#     def expression(self):
#     def __hash__(self):
#     def __repr__(self):
#     def __eq__(self, other):
#     def same_key_fields(self, other):
# 
# Path: monasca_api/v2/common/exceptions.py
# class HTTPUnprocessableEntityError(HTTPError):
#     def __init__(self, title, description, **kwargs):
#         HTTPError.__init__(self, '422 Unprocessable Entity', title, description, **kwargs)
# 
# Path: monasca_api/v2/reference/alarms.py
# LOG = log.getLogger(__name__)
# class Alarms(alarms_api_v2.AlarmsV2API,
#              alarming.Alarming):
# class AlarmsCount(alarms_api_v2.AlarmsCountV2API, alarming.Alarming):
# class AlarmsStateHistory(alarms_api_v2.AlarmsStateHistoryV2API,
#                          alarming.Alarming):
#     def __init__(self):
#     def on_put(self, req, res, alarm_id):
#     def on_patch(self, req, res, alarm_id):
#     def on_delete(self, req, res, alarm_id):
#     def on_get(self, req, res, alarm_id=None):
#     def _alarm_update(self, tenant_id, alarm_id, new_state, lifecycle_state,
#                       link):
#     def _alarm_patch(self, tenant_id, alarm_id, new_state, lifecycle_state,
#                      link):
#     def _alarm_delete(self, tenant_id, id):
#     def _alarm_show(self, req_uri, tenant_id, alarm_id):
#     def _alarm_list(self, req_uri, tenant_id, query_parms, offset, limit):
#     def __init__(self):
#     def on_get(self, req, res):
#     def _alarms_count(self, req_uri, tenant_id, query_parms, offset, limit):
#     def _validate_group_by(self, group_by):
#     def __init__(self):
#     def on_get(self, req, res, alarm_id=None):
#     def _alarm_history_list(self, tenant_id, start_timestamp,
#                             end_timestamp, dimensions, req_uri, offset,
#                             limit):
#     def _alarm_history(self, tenant_id, alarm_id, req_uri, offset, limit):


# Path: monasca_api/tests/test_alarms.py
from collections import OrderedDict
from unittest.mock import Mock
from monasca_api.common.repositories.model import sub_alarm_definition
from monasca_api.tests import base
from monasca_api.v2.common.exceptions import HTTPUnprocessableEntityError
from monasca_api.v2.reference import alarm_definitions
from monasca_api.v2.reference import alarms
import copy
import datetime
import json
import falcon.testing
import fixtures
import testtools.matchers as matchers
import oslo_config.fixture
import six

        response = self.simulate_request(
            path="/v2.0/alarm-definitions/",
            headers={
                'X-Roles': CONF.security.default_authorized_roles[0],
                'X-Tenant-Id': TENANT_ID},
            method="DELETE")

        self.assertEqual(response.status, falcon.HTTP_400)

    def test_alarm_definition_patch(self):
        self.alarm_def_repo_mock.return_value.get_alarm_definitions.return_value = []
        description = u'Non-ASCII character: \u2603'
        new_name = u'Test Alarm Updated'
        actions_enabled = True
        alarm_def_id = u'00000001-0001-0001-0001-000000000001'
        alarm_expression = u'max(test.metric{hostname=host}) gte 1'
        severity = u'LOW'
        match_by = u'hostname'
        self.alarm_def_repo_mock.return_value.update_or_patch_alarm_definition.return_value = (
            {u'alarm_actions': [],
             u'ok_actions': [],
             u'description': description,
             u'match_by': match_by,
             u'name': new_name,
             u'actions_enabled': actions_enabled,
             u'undetermined_actions': [],
             u'is_deterministic': False,
             u'expression': alarm_expression,
             u'id': alarm_def_id,
             u'severity': severity},

            {'old': {'11111': sub_alarm_definition.SubAlarmDefinition(