# 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
        u"current_values": [50.1],
    }]),
    # Only present in data returned from InfluxDB:
    (u"tenant_id", TENANT_ID),
    # Only present in data returned from API:
    (u"id", u"1420070400000"),
))


class InfluxClientAlarmHistoryResponseFixture(fixtures.MockPatch):
    def _build_series(self, name, column_dict):
        return {
            "name": name,
            "columns": column_dict.keys(),
            "values": [column_dict.values(), ],
        }

    def _setUp(self):
        super(InfluxClientAlarmHistoryResponseFixture, self)._setUp()

        mock_data = copy.deepcopy(ALARM_HISTORY)

        del mock_data[u"id"]
        del mock_data[u"timestamp"]
        del mock_data[u"sub_alarms"][0][u"sub_alarm_expression"][u"metric_name"]
        del mock_data[u"sub_alarms"][0][u"sub_alarm_expression"][u"dimensions"]
        mock_data[u"sub_alarms"] = json.dumps(mock_data[u"sub_alarms"])
        mock_data[u"metrics"] = json.dumps(mock_data[u"metrics"])

        self.mock.return_value.query.return_value.raw = {

# 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

        u"current_values": [50.1],
    }]),
    # Only present in data returned from InfluxDB:
    (u"tenant_id", TENANT_ID),
    # Only present in data returned from API:
    (u"id", u"1420070400000"),
))


class InfluxClientAlarmHistoryResponseFixture(fixtures.MockPatch):
    def _build_series(self, name, column_dict):
        return {
            "name": name,
            "columns": column_dict.keys(),
            "values": [column_dict.values(), ],
        }

    def _setUp(self):
        super(InfluxClientAlarmHistoryResponseFixture, self)._setUp()

        mock_data = copy.deepcopy(ALARM_HISTORY)

        del mock_data[u"id"]
        del mock_data[u"timestamp"]
        del mock_data[u"sub_alarms"][0][u"sub_alarm_expression"][u"metric_name"]
        del mock_data[u"sub_alarms"][0][u"sub_alarm_expression"][u"dimensions"]
        mock_data[u"sub_alarms"] = json.dumps(mock_data[u"sub_alarms"])
        mock_data[u"metrics"] = json.dumps(mock_data[u"metrics"])

        self.mock.return_value.query.return_value.raw = {

            "series": [self._build_series("alarm_state_history", mock_data)]