# 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
        name = alarm_definitions.get_query_alarm_definition_name(alarm_def)
        self.assertEqual(alarm_def['name'], name)

        alarm_def.pop('name')

        self.assertRaises(HTTPUnprocessableEntityError,
                          alarm_definitions.get_query_alarm_definition_name,
                          alarm_def)

        name = alarm_definitions.get_query_alarm_definition_name(alarm_def, return_none=True)
        self.assertIsNone(name)

    def test_alarm_definition_get_query_alarm_definition_expression(self):
        alarm_def = {
            u'alarm_actions': [],
            u'ok_actions': [],
            u'description': u'',
            u'match_by': [u'hostname'],
            u'name': u'Test Alarm',
            u'actions_enabled': True,
            u'undetermined_actions': [],
            u'deterministic': False,
            u'expression': u'max(test.metric{hostname=host}) gte 1',
            u'severity': u'LOW',
        }
        expression = alarm_definitions.get_query_alarm_definition_expression(alarm_def)
        self.assertEqual(alarm_def['expression'], expression)

        alarm_def.pop('expression')


# 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

        name = alarm_definitions.get_query_alarm_definition_name(alarm_def)
        self.assertEqual(alarm_def['name'], name)

        alarm_def.pop('name')

        self.assertRaises(HTTPUnprocessableEntityError,
                          alarm_definitions.get_query_alarm_definition_name,
                          alarm_def)

        name = alarm_definitions.get_query_alarm_definition_name(alarm_def, return_none=True)
        self.assertIsNone(name)

    def test_alarm_definition_get_query_alarm_definition_expression(self):
        alarm_def = {
            u'alarm_actions': [],
            u'ok_actions': [],
            u'description': u'',
            u'match_by': [u'hostname'],
            u'name': u'Test Alarm',
            u'actions_enabled': True,
            u'undetermined_actions': [],
            u'deterministic': False,
            u'expression': u'max(test.metric{hostname=host}) gte 1',
            u'severity': u'LOW',
        }
        expression = alarm_definitions.get_query_alarm_definition_expression(alarm_def)
        self.assertEqual(alarm_def['expression'], expression)

        alarm_def.pop('expression')


        self.assertRaises(HTTPUnprocessableEntityError,