Unify test setup
Change make the tests follow the same approach for every possible case. This change is required to properly introduce configuration parsing from a single place. Change-Id: I14fbf71eddd0930ecaa6330955f74ebc8677912b
This commit is contained in:
parent
2742123297
commit
366c8886f9
|
@ -1,5 +1,5 @@
|
||||||
# Copyright 2015 kornicameister@gmail.com
|
# Copyright 2015 kornicameister@gmail.com
|
||||||
# Copyright 2015 FUJITSU LIMITED
|
# Copyright 2015-2017 FUJITSU LIMITED
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
# not use this file except in compliance with the License. You may obtain
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
@ -14,6 +14,11 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import falcon
|
import falcon
|
||||||
|
from falcon import testing
|
||||||
|
from oslo_config import cfg
|
||||||
|
from oslo_config import fixture as oo_cfg
|
||||||
|
from oslo_context import fixture as oo_ctx
|
||||||
|
from oslotest import base as oslotest_base
|
||||||
|
|
||||||
from monasca_api.api.core import request
|
from monasca_api.api.core import request
|
||||||
|
|
||||||
|
@ -34,3 +39,46 @@ class MockedAPI(falcon.API):
|
||||||
middleware=None,
|
middleware=None,
|
||||||
router=None
|
router=None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigFixture(oo_cfg.Config):
|
||||||
|
"""Mocks configuration"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super(ConfigFixture, self).__init__(cfg.CONF)
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(ConfigFixture, self).setUp()
|
||||||
|
|
||||||
|
|
||||||
|
class BaseTestCase(oslotest_base.BaseTestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(BaseTestCase, self).setUp()
|
||||||
|
self.useFixture(ConfigFixture())
|
||||||
|
self.useFixture(oo_ctx.ClearRequestContext())
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def conf_override(**kw):
|
||||||
|
"""Override flag variables for a test."""
|
||||||
|
group = kw.pop('group', None)
|
||||||
|
for k, v in kw.items():
|
||||||
|
cfg.CONF.set_override(k, v, group)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def conf_default(**kw):
|
||||||
|
"""Override flag variables for a test."""
|
||||||
|
group = kw.pop('group', None)
|
||||||
|
for k, v in kw.items():
|
||||||
|
cfg.CONF.set_default(k, v, group)
|
||||||
|
|
||||||
|
|
||||||
|
class BaseApiTestCase(BaseTestCase, testing.TestBase):
|
||||||
|
api_class = MockedAPI
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def create_environ(*args, **kwargs):
|
||||||
|
return testing.create_environ(
|
||||||
|
*args,
|
||||||
|
**kwargs
|
||||||
|
)
|
||||||
|
|
|
@ -19,17 +19,17 @@ import time
|
||||||
|
|
||||||
import fixtures
|
import fixtures
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_config import fixture as fixture_config
|
|
||||||
from oslo_db.sqlalchemy.engines import create_engine
|
from oslo_db.sqlalchemy.engines import create_engine
|
||||||
import testtools
|
|
||||||
|
|
||||||
|
from monasca_api.tests import base
|
||||||
from sqlalchemy import delete, MetaData, insert, bindparam
|
from sqlalchemy import delete, MetaData, insert, bindparam
|
||||||
from monasca_api.common.repositories.sqla import models
|
from monasca_api.common.repositories.sqla import models
|
||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
|
|
||||||
|
|
||||||
class TestAlarmRepoDB(testtools.TestCase, fixtures.TestWithFixtures):
|
class TestAlarmRepoDB(base.BaseTestCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
engine = create_engine('sqlite://')
|
engine = create_engine('sqlite://')
|
||||||
|
@ -171,10 +171,7 @@ class TestAlarmRepoDB(testtools.TestCase, fixtures.TestWithFixtures):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestAlarmRepoDB, self).setUp()
|
super(TestAlarmRepoDB, self).setUp()
|
||||||
|
|
||||||
self._fixture_config = self.useFixture(
|
self.conf_override(connection='sqlite://', group='database')
|
||||||
fixture_config.Config(cfg.CONF))
|
|
||||||
self._fixture_config.config(connection='sqlite://',
|
|
||||||
group='database')
|
|
||||||
|
|
||||||
from monasca_api.common.repositories.sqla import alarms_repository as ar
|
from monasca_api.common.repositories.sqla import alarms_repository as ar
|
||||||
self.repo = ar.AlarmsRepository()
|
self.repo = ar.AlarmsRepository()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# Copyright 2015 Cray
|
# Copyright 2015 Cray
|
||||||
# Copyright 2016 FUJITSU LIMITED
|
# Copyright 2016-2017 FUJITSU LIMITED
|
||||||
# (C) Copyright 2016-2017 Hewlett Packard Enterprise Development LP
|
# (C) Copyright 2016-2017 Hewlett Packard Enterprise Development LP
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
@ -18,15 +18,14 @@ import datetime
|
||||||
|
|
||||||
import fixtures
|
import fixtures
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_config import fixture as fixture_config
|
|
||||||
from oslo_db.sqlalchemy.engines import create_engine
|
from oslo_db.sqlalchemy.engines import create_engine
|
||||||
from sqlalchemy import delete, MetaData, insert, bindparam, select, func
|
from sqlalchemy import delete, MetaData, insert, bindparam, select, func
|
||||||
import testtools
|
|
||||||
|
|
||||||
from monasca_api.common.repositories import exceptions
|
from monasca_api.common.repositories import exceptions
|
||||||
from monasca_api.common.repositories.model import sub_alarm_definition
|
from monasca_api.common.repositories.model import sub_alarm_definition
|
||||||
from monasca_api.common.repositories.sqla import models
|
from monasca_api.common.repositories.sqla import models
|
||||||
from monasca_api.expression_parser import alarm_expr_parser
|
from monasca_api.expression_parser import alarm_expr_parser
|
||||||
|
from monasca_api.tests import base
|
||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
ALARM_DEF_123_FIELDS = {'actions_enabled': False,
|
ALARM_DEF_123_FIELDS = {'actions_enabled': False,
|
||||||
|
@ -43,12 +42,11 @@ ALARM_DEF_123_FIELDS = {'actions_enabled': False,
|
||||||
TENANT_ID = 'bob'
|
TENANT_ID = 'bob'
|
||||||
|
|
||||||
|
|
||||||
class TestAlarmDefinitionRepoDB(testtools.TestCase, fixtures.TestWithFixtures):
|
class TestAlarmDefinitionRepoDB(base.BaseTestCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
engine = create_engine('sqlite://')
|
engine = create_engine('sqlite://')
|
||||||
|
|
||||||
qry = open('monasca_api/tests/sqlite_alarm.sql', 'r').read()
|
qry = open('monasca_api/tests/sqlite_alarm.sql', 'r').read()
|
||||||
sconn = engine.raw_connection()
|
sconn = engine.raw_connection()
|
||||||
c = sconn.cursor()
|
c = sconn.cursor()
|
||||||
|
@ -59,69 +57,65 @@ class TestAlarmDefinitionRepoDB(testtools.TestCase, fixtures.TestWithFixtures):
|
||||||
|
|
||||||
def _fake_engine_from_config(*args, **kw):
|
def _fake_engine_from_config(*args, **kw):
|
||||||
return cls.engine
|
return cls.engine
|
||||||
|
|
||||||
cls.fixture = fixtures.MonkeyPatch(
|
cls.fixture = fixtures.MonkeyPatch(
|
||||||
'sqlalchemy.create_engine', _fake_engine_from_config)
|
'sqlalchemy.create_engine', _fake_engine_from_config)
|
||||||
cls.fixture.setUp()
|
cls.fixture.setUp()
|
||||||
|
|
||||||
metadata = MetaData()
|
metadata = MetaData()
|
||||||
|
|
||||||
cls.aa = models.create_aa_model(metadata)
|
cls.aa = models.create_aa_model(metadata)
|
||||||
cls._delete_aa_query = delete(cls.aa)
|
cls._delete_aa_query = delete(cls.aa)
|
||||||
cls._insert_aa_query = (insert(cls.aa)
|
cls._insert_aa_query = (insert(cls.aa).values(
|
||||||
.values(
|
alarm_definition_id=bindparam('alarm_definition_id'),
|
||||||
alarm_definition_id=bindparam('alarm_definition_id'),
|
alarm_state=bindparam('alarm_state'),
|
||||||
alarm_state=bindparam('alarm_state'),
|
action_id=bindparam('action_id')))
|
||||||
action_id=bindparam('action_id')))
|
|
||||||
|
|
||||||
cls.ad = models.create_ad_model(metadata)
|
cls.ad = models.create_ad_model(metadata)
|
||||||
cls._delete_ad_query = delete(cls.ad)
|
cls._delete_ad_query = delete(cls.ad)
|
||||||
cls._insert_ad_query = (insert(cls.ad)
|
cls._insert_ad_query = (insert(cls.ad).values(
|
||||||
.values(
|
id=bindparam('id'),
|
||||||
id=bindparam('id'),
|
tenant_id=bindparam('tenant_id'),
|
||||||
tenant_id=bindparam('tenant_id'),
|
name=bindparam('name'),
|
||||||
name=bindparam('name'),
|
severity=bindparam('severity'),
|
||||||
severity=bindparam('severity'),
|
expression=bindparam('expression'),
|
||||||
expression=bindparam('expression'),
|
match_by=bindparam('match_by'),
|
||||||
match_by=bindparam('match_by'),
|
actions_enabled=bindparam('actions_enabled'),
|
||||||
actions_enabled=bindparam('actions_enabled'),
|
created_at=bindparam('created_at'),
|
||||||
created_at=bindparam('created_at'),
|
updated_at=bindparam('updated_at'),
|
||||||
updated_at=bindparam('updated_at'),
|
deleted_at=bindparam('deleted_at')))
|
||||||
deleted_at=bindparam('deleted_at')))
|
|
||||||
cls.sad = models.create_sad_model(metadata)
|
cls.sad = models.create_sad_model(metadata)
|
||||||
cls._delete_sad_query = delete(cls.sad)
|
cls._delete_sad_query = delete(cls.sad)
|
||||||
cls._insert_sad_query = (insert(cls.sad)
|
cls._insert_sad_query = (insert(cls.sad).values(
|
||||||
.values(
|
id=bindparam('id'),
|
||||||
id=bindparam('id'),
|
alarm_definition_id=bindparam('alarm_definition_id'),
|
||||||
alarm_definition_id=bindparam('alarm_definition_id'),
|
function=bindparam('function'),
|
||||||
function=bindparam('function'),
|
metric_name=bindparam('metric_name'),
|
||||||
metric_name=bindparam('metric_name'),
|
operator=bindparam('operator'),
|
||||||
operator=bindparam('operator'),
|
threshold=bindparam('threshold'),
|
||||||
threshold=bindparam('threshold'),
|
period=bindparam('period'),
|
||||||
period=bindparam('period'),
|
periods=bindparam('periods'),
|
||||||
periods=bindparam('periods'),
|
is_deterministic=bindparam('is_deterministic'),
|
||||||
is_deterministic=bindparam('is_deterministic'),
|
created_at=bindparam('created_at'),
|
||||||
created_at=bindparam('created_at'),
|
updated_at=bindparam('updated_at')))
|
||||||
updated_at=bindparam('updated_at')))
|
|
||||||
|
|
||||||
cls.sadd = models.create_sadd_model(metadata)
|
cls.sadd = models.create_sadd_model(metadata)
|
||||||
cls._delete_sadd_query = delete(cls.sadd)
|
cls._delete_sadd_query = delete(cls.sadd)
|
||||||
cls._insert_sadd_query = (insert(cls.sadd)
|
cls._insert_sadd_query = (insert(cls.sadd).values(
|
||||||
.values(
|
sub_alarm_definition_id=bindparam('sub_alarm_definition_id'),
|
||||||
sub_alarm_definition_id=bindparam('sub_alarm_definition_id'),
|
dimension_name=bindparam('dimension_name'),
|
||||||
dimension_name=bindparam('dimension_name'),
|
value=bindparam('value')))
|
||||||
value=bindparam('value')))
|
|
||||||
|
|
||||||
cls.nm = models.create_nm_model(metadata)
|
cls.nm = models.create_nm_model(metadata)
|
||||||
cls._delete_nm_query = delete(cls.nm)
|
cls._delete_nm_query = delete(cls.nm)
|
||||||
cls._insert_nm_query = (insert(cls.nm)
|
cls._insert_nm_query = (insert(cls.nm).values(
|
||||||
.values(
|
id=bindparam('id'),
|
||||||
id=bindparam('id'),
|
tenant_id=bindparam('tenant_id'),
|
||||||
tenant_id=bindparam('tenant_id'),
|
name=bindparam('name'),
|
||||||
name=bindparam('name'),
|
type=bindparam('type'),
|
||||||
type=bindparam('type'),
|
address=bindparam('address'),
|
||||||
address=bindparam('address'),
|
created_at=bindparam('created_at'),
|
||||||
created_at=bindparam('created_at'),
|
updated_at=bindparam('updated_at')))
|
||||||
updated_at=bindparam('updated_at')))
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
|
@ -129,11 +123,7 @@ class TestAlarmDefinitionRepoDB(testtools.TestCase, fixtures.TestWithFixtures):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestAlarmDefinitionRepoDB, self).setUp()
|
super(TestAlarmDefinitionRepoDB, self).setUp()
|
||||||
|
self.conf_default(connection='sqlite://', group='database')
|
||||||
self._fixture_config = self.useFixture(
|
|
||||||
fixture_config.Config(cfg.CONF))
|
|
||||||
self._fixture_config.config(connection='sqlite://',
|
|
||||||
group='database')
|
|
||||||
|
|
||||||
from monasca_api.common.repositories.sqla import alarm_definitions_repository as adr
|
from monasca_api.common.repositories.sqla import alarm_definitions_repository as adr
|
||||||
self.repo = adr.AlarmDefinitionsRepository()
|
self.repo = adr.AlarmDefinitionsRepository()
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# (C) Copyright 2016-2017 Hewlett Packard Enterprise Development LP
|
# (C) Copyright 2016-2017 Hewlett Packard Enterprise Development LP
|
||||||
|
# Copyright 2017 Fujitsu LIMITED
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
# not use this file except in compliance with the License. You may obtain
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
@ -13,12 +14,12 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import pyparsing
|
import pyparsing
|
||||||
import unittest
|
|
||||||
|
|
||||||
from monasca_api.expression_parser import alarm_expr_parser
|
from monasca_api.expression_parser import alarm_expr_parser
|
||||||
|
from monasca_api.tests import base
|
||||||
|
|
||||||
|
|
||||||
class TestAlarmExpression(unittest.TestCase):
|
class TestAlarmExpression(base.BaseTestCase):
|
||||||
|
|
||||||
good_simple_expression = "max(cpu.idle_perc{hostname=fred}, 60) > 10 times 4"
|
good_simple_expression = "max(cpu.idle_perc{hostname=fred}, 60) > 10 times 4"
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright 2015 Cray Inc.
|
# Copyright 2015 Cray Inc.
|
||||||
# (C) Copyright 2015,2017 Hewlett Packard Enterprise Development LP
|
# (C) Copyright 2015,2017 Hewlett Packard Enterprise Development LP
|
||||||
# Copyright 2016 FUJITSU LIMITED
|
# Copyright 2016-2017 FUJITSU LIMITED
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
# not use this file except in compliance with the License. You may obtain
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
@ -25,15 +25,14 @@ import testtools.matchers as matchers
|
||||||
|
|
||||||
from mock import Mock
|
from mock import Mock
|
||||||
|
|
||||||
|
import oslo_config.fixture
|
||||||
|
import six
|
||||||
|
|
||||||
from monasca_api.common.repositories.model import sub_alarm_definition
|
from monasca_api.common.repositories.model import sub_alarm_definition
|
||||||
from monasca_api.tests import base
|
from monasca_api.tests import base
|
||||||
from monasca_api.v2.reference import alarm_definitions
|
from monasca_api.v2.reference import alarm_definitions
|
||||||
from monasca_api.v2.reference import alarms
|
from monasca_api.v2.reference import alarms
|
||||||
|
|
||||||
import oslo_config.fixture
|
|
||||||
import oslotest.base as oslotest
|
|
||||||
import six
|
|
||||||
|
|
||||||
CONF = oslo_config.cfg.CONF
|
CONF = oslo_config.cfg.CONF
|
||||||
|
|
||||||
TENANT_ID = u"fedcba9876543210fedcba9876543210"
|
TENANT_ID = u"fedcba9876543210fedcba9876543210"
|
||||||
|
@ -81,32 +80,6 @@ ALARM_HISTORY = OrderedDict((
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
class MonascaApiConfigFixture(oslo_config.fixture.Config):
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
super(MonascaApiConfigFixture, self).setUp()
|
|
||||||
|
|
||||||
# [messaging]
|
|
||||||
self.conf.set_override(
|
|
||||||
'driver',
|
|
||||||
'monasca_api.common.messaging.kafka_publisher:KafkaPublisher',
|
|
||||||
group='messaging')
|
|
||||||
|
|
||||||
# [repositories]
|
|
||||||
self.conf.set_override(
|
|
||||||
'alarms_driver',
|
|
||||||
'monasca_api.common.repositories.sqla.alarms_repository:AlarmsRepository',
|
|
||||||
group='repositories')
|
|
||||||
self.conf.set_override(
|
|
||||||
'alarm_definitions_driver',
|
|
||||||
'monasca_api.common.repositories.alarm_definitions_repository:AlarmDefinitionsRepository',
|
|
||||||
group='repositories')
|
|
||||||
self.conf.set_override(
|
|
||||||
'metrics_driver',
|
|
||||||
'monasca_api.common.repositories.influxdb.metrics_repository:MetricsRepository',
|
|
||||||
group='repositories')
|
|
||||||
|
|
||||||
|
|
||||||
class InfluxClientAlarmHistoryResponseFixture(fixtures.MockPatch):
|
class InfluxClientAlarmHistoryResponseFixture(fixtures.MockPatch):
|
||||||
|
|
||||||
def _build_series(self, name, column_dict):
|
def _build_series(self, name, column_dict):
|
||||||
|
@ -160,9 +133,7 @@ class RESTResponseEquals(object):
|
||||||
return matchers.Equals(self.expected_data).match(response_data)
|
return matchers.Equals(self.expected_data).match(response_data)
|
||||||
|
|
||||||
|
|
||||||
class AlarmTestBase(falcon.testing.TestBase, oslotest.BaseTestCase):
|
class AlarmTestBase(base.BaseApiTestCase):
|
||||||
|
|
||||||
api_class = base.MockedAPI
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(AlarmTestBase, self).setUp()
|
super(AlarmTestBase, self).setUp()
|
||||||
|
@ -170,7 +141,26 @@ class AlarmTestBase(falcon.testing.TestBase, oslotest.BaseTestCase):
|
||||||
self.useFixture(fixtures.MockPatch(
|
self.useFixture(fixtures.MockPatch(
|
||||||
'monasca_api.common.messaging.kafka_publisher.KafkaPublisher'))
|
'monasca_api.common.messaging.kafka_publisher.KafkaPublisher'))
|
||||||
|
|
||||||
self.CONF = self.useFixture(MonascaApiConfigFixture(CONF)).conf
|
# [messaging]
|
||||||
|
self.conf_override(
|
||||||
|
driver='monasca_api.common.messaging.'
|
||||||
|
'kafka_publisher:KafkaPublisher',
|
||||||
|
group='messaging')
|
||||||
|
|
||||||
|
# [repositories]
|
||||||
|
self.conf_override(
|
||||||
|
alarms_driver='monasca_api.common.repositories.sqla.'
|
||||||
|
'alarms_repository:AlarmsRepository',
|
||||||
|
group='repositories')
|
||||||
|
self.conf_override(
|
||||||
|
alarm_definitions_driver='monasca_api.common.repositories.'
|
||||||
|
'alarm_definitions_repository:'
|
||||||
|
'AlarmDefinitionsRepository',
|
||||||
|
group='repositories')
|
||||||
|
self.conf_override(
|
||||||
|
metrics_driver='monasca_api.common.repositories.influxdb.'
|
||||||
|
'metrics_repository:MetricsRepository',
|
||||||
|
group='repositories')
|
||||||
|
|
||||||
|
|
||||||
class TestAlarmsStateHistory(AlarmTestBase):
|
class TestAlarmsStateHistory(AlarmTestBase):
|
||||||
|
@ -179,9 +169,11 @@ class TestAlarmsStateHistory(AlarmTestBase):
|
||||||
super(TestAlarmsStateHistory, self).setUp()
|
super(TestAlarmsStateHistory, self).setUp()
|
||||||
|
|
||||||
self.useFixture(InfluxClientAlarmHistoryResponseFixture(
|
self.useFixture(InfluxClientAlarmHistoryResponseFixture(
|
||||||
'monasca_api.common.repositories.influxdb.metrics_repository.client.InfluxDBClient'))
|
'monasca_api.common.repositories.influxdb.'
|
||||||
|
'metrics_repository.client.InfluxDBClient'))
|
||||||
self.useFixture(fixtures.MockPatch(
|
self.useFixture(fixtures.MockPatch(
|
||||||
'monasca_api.common.repositories.sqla.alarms_repository.AlarmsRepository'))
|
'monasca_api.common.repositories.sqla.'
|
||||||
|
'alarms_repository.AlarmsRepository'))
|
||||||
|
|
||||||
self.alarms_resource = alarms.AlarmsStateHistory()
|
self.alarms_resource = alarms.AlarmsStateHistory()
|
||||||
self.api.add_route(
|
self.api.add_route(
|
||||||
|
@ -210,7 +202,8 @@ class TestAlarmDefinition(AlarmTestBase):
|
||||||
super(TestAlarmDefinition, self).setUp()
|
super(TestAlarmDefinition, self).setUp()
|
||||||
|
|
||||||
self.alarm_def_repo_mock = self.useFixture(fixtures.MockPatch(
|
self.alarm_def_repo_mock = self.useFixture(fixtures.MockPatch(
|
||||||
'monasca_api.common.repositories.alarm_definitions_repository.AlarmDefinitionsRepository'
|
'monasca_api.common.repositories.'
|
||||||
|
'alarm_definitions_repository.AlarmDefinitionsRepository'
|
||||||
)).mock
|
)).mock
|
||||||
|
|
||||||
self.alarm_definition_resource = alarm_definitions.AlarmDefinitions()
|
self.alarm_definition_resource = alarm_definitions.AlarmDefinitions()
|
||||||
|
|
|
@ -13,10 +13,9 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
from oslo_config import fixture as oo_cfg
|
|
||||||
from oslotest import base
|
|
||||||
|
|
||||||
from monasca_api.healthcheck import alarms_db_check as rdc
|
from monasca_api.healthcheck import alarms_db_check as rdc
|
||||||
|
from monasca_api.tests import base
|
||||||
from monasca_api.v2.reference import cfg
|
from monasca_api.v2.reference import cfg
|
||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
|
@ -29,14 +28,9 @@ class TestMetricsDbHealthCheckLogic(base.BaseTestCase):
|
||||||
'connection': db_connection
|
'connection': db_connection
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
super(TestMetricsDbHealthCheckLogic, self).__init__(*args, **kwargs)
|
|
||||||
self._conf = None
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestMetricsDbHealthCheckLogic, self).setUp()
|
super(TestMetricsDbHealthCheckLogic, self).setUp()
|
||||||
self._conf = self.useFixture(oo_cfg.Config(CONF))
|
self.conf_default(group='database', **self.mocked_config)
|
||||||
self._conf.config(group='database', **self.mocked_config)
|
|
||||||
|
|
||||||
@mock.patch('monasca_api.healthcheck.alarms_db_check.'
|
@mock.patch('monasca_api.healthcheck.alarms_db_check.'
|
||||||
'sql_repository.get_engine')
|
'sql_repository.get_engine')
|
||||||
|
|
|
@ -13,12 +13,11 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import falcon
|
import falcon
|
||||||
from falcon import testing
|
|
||||||
import mock
|
import mock
|
||||||
from oslo_config import fixture as oo_cfg
|
|
||||||
|
|
||||||
from monasca_api.healthcheck import base
|
from monasca_api.healthcheck import base
|
||||||
from monasca_api import healthchecks
|
from monasca_api import healthchecks
|
||||||
|
from monasca_api.tests import base as test_base
|
||||||
from monasca_api.v2.reference import cfg
|
from monasca_api.v2.reference import cfg
|
||||||
from monasca_common.rest import utils
|
from monasca_common.rest import utils
|
||||||
|
|
||||||
|
@ -26,10 +25,7 @@ CONF = cfg.CONF
|
||||||
ENDPOINT = '/healthcheck'
|
ENDPOINT = '/healthcheck'
|
||||||
|
|
||||||
|
|
||||||
class TestHealthChecks(testing.TestBase):
|
class TestHealthChecks(test_base.BaseApiTestCase):
|
||||||
def setUp(self):
|
|
||||||
super(TestHealthChecks, self).setUp()
|
|
||||||
self.conf = self.useFixture(oo_cfg.Config(CONF))
|
|
||||||
|
|
||||||
def set_route(self):
|
def set_route(self):
|
||||||
self.resources = healthchecks.HealthChecks()
|
self.resources = healthchecks.HealthChecks()
|
||||||
|
|
|
@ -13,12 +13,11 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
from oslo_config import fixture as oo_cfg
|
|
||||||
from oslotest import base
|
|
||||||
|
|
||||||
from monasca_common.kafka_lib import client
|
from monasca_common.kafka_lib import client
|
||||||
|
|
||||||
from monasca_api.healthcheck import kafka_check as kc
|
from monasca_api.healthcheck import kafka_check as kc
|
||||||
|
from monasca_api.tests import base
|
||||||
from monasca_api.v2.reference import cfg
|
from monasca_api.v2.reference import cfg
|
||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
|
@ -43,8 +42,7 @@ class TestKafkaHealthCheckLogic(base.BaseTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestKafkaHealthCheckLogic, self).setUp()
|
super(TestKafkaHealthCheckLogic, self).setUp()
|
||||||
self._conf = self.useFixture(oo_cfg.Config(CONF))
|
self.conf_default(group='kafka', **self.mocked_config)
|
||||||
self._conf.config(group='kafka', **self.mocked_config)
|
|
||||||
|
|
||||||
@mock.patch('monasca_api.healthcheck.kafka_check.client.KafkaClient')
|
@mock.patch('monasca_api.healthcheck.kafka_check.client.KafkaClient')
|
||||||
def test_should_fail_kafka_unavailable(self, kafka_client):
|
def test_should_fail_kafka_unavailable(self, kafka_client):
|
||||||
|
|
|
@ -13,9 +13,9 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
from oslotest import base
|
|
||||||
|
|
||||||
from monasca_api.healthcheck import keystone_protocol
|
from monasca_api.healthcheck import keystone_protocol
|
||||||
|
from monasca_api.tests import base
|
||||||
|
|
||||||
_CONF = {}
|
_CONF = {}
|
||||||
|
|
||||||
|
|
|
@ -17,11 +17,10 @@ from cassandra import cluster as cl
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
from oslo_config import fixture as oo_cfg
|
|
||||||
from oslotest import base
|
|
||||||
|
|
||||||
from monasca_api.common.repositories import exceptions
|
from monasca_api.common.repositories import exceptions
|
||||||
from monasca_api.healthcheck import metrics_db_check as tdc
|
from monasca_api.healthcheck import metrics_db_check as tdc
|
||||||
|
from monasca_api.tests import base
|
||||||
from monasca_api.v2.reference import cfg
|
from monasca_api.v2.reference import cfg
|
||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
|
@ -39,8 +38,7 @@ class TestMetricsDbHealthCheck(base.BaseTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestMetricsDbHealthCheck, self).setUp()
|
super(TestMetricsDbHealthCheck, self).setUp()
|
||||||
self._conf = self.useFixture(oo_cfg.Config(CONF))
|
self.conf_default(group='cassandra', **self.cassandra_conf)
|
||||||
self._conf.config(group='cassandra', **self.cassandra_conf)
|
|
||||||
|
|
||||||
def test_should_detect_influxdb_db(self):
|
def test_should_detect_influxdb_db(self):
|
||||||
db_health = tdc.MetricsDbCheck()
|
db_health = tdc.MetricsDbCheck()
|
||||||
|
@ -75,8 +73,8 @@ class TestMetricsDbHealthCheck(base.BaseTestCase):
|
||||||
messaging_conf = {
|
messaging_conf = {
|
||||||
'metrics_driver': 'influxdb.metrics_repository:MetricsRepository'
|
'metrics_driver': 'influxdb.metrics_repository:MetricsRepository'
|
||||||
}
|
}
|
||||||
self._conf.config(group='repositories', **messaging_conf)
|
self.conf_override(group='repositories', **messaging_conf)
|
||||||
self._conf.config(group='influxdb', **influxdb_conf)
|
self.conf_override(group='influxdb', **influxdb_conf)
|
||||||
|
|
||||||
db_health = tdc.MetricsDbCheck()
|
db_health = tdc.MetricsDbCheck()
|
||||||
result = db_health.health_check()
|
result = db_health.health_check()
|
||||||
|
@ -97,8 +95,8 @@ class TestMetricsDbHealthCheck(base.BaseTestCase):
|
||||||
messaging_conf = {
|
messaging_conf = {
|
||||||
'metrics_driver': 'influxdb.metrics_repository:MetricsRepository'
|
'metrics_driver': 'influxdb.metrics_repository:MetricsRepository'
|
||||||
}
|
}
|
||||||
self._conf.config(group='repositories', **messaging_conf)
|
self.conf_override(group='repositories', **messaging_conf)
|
||||||
self._conf.config(group='influxdb', **influxdb_conf)
|
self.conf_override(group='influxdb', **influxdb_conf)
|
||||||
|
|
||||||
db_health = tdc.MetricsDbCheck()
|
db_health = tdc.MetricsDbCheck()
|
||||||
result = db_health.health_check()
|
result = db_health.health_check()
|
||||||
|
@ -118,8 +116,8 @@ class TestMetricsDbHealthCheck(base.BaseTestCase):
|
||||||
messaging_conf = {
|
messaging_conf = {
|
||||||
'metrics_driver': 'influxdb.metrics_repository:MetricsRepository'
|
'metrics_driver': 'influxdb.metrics_repository:MetricsRepository'
|
||||||
}
|
}
|
||||||
self._conf.config(group='repositories', **messaging_conf)
|
self.conf_override(group='repositories', **messaging_conf)
|
||||||
self._conf.config(group='influxdb', **influxdb_conf)
|
self.conf_override(group='influxdb', **influxdb_conf)
|
||||||
|
|
||||||
db_health = tdc.MetricsDbCheck()
|
db_health = tdc.MetricsDbCheck()
|
||||||
result = db_health.health_check()
|
result = db_health.health_check()
|
||||||
|
@ -139,8 +137,8 @@ class TestMetricsDbHealthCheck(base.BaseTestCase):
|
||||||
messaging_conf = {
|
messaging_conf = {
|
||||||
'metrics_driver': 'influxdb.metrics_repository:MetricsRepository'
|
'metrics_driver': 'influxdb.metrics_repository:MetricsRepository'
|
||||||
}
|
}
|
||||||
self._conf.config(group='repositories', **messaging_conf)
|
self.conf_override(group='repositories', **messaging_conf)
|
||||||
self._conf.config(group='influxdb', **influxdb_conf)
|
self.conf_override(group='influxdb', **influxdb_conf)
|
||||||
|
|
||||||
db_health = tdc.MetricsDbCheck()
|
db_health = tdc.MetricsDbCheck()
|
||||||
result = db_health.health_check()
|
result = db_health.health_check()
|
||||||
|
@ -157,8 +155,8 @@ class TestMetricsDbHealthCheck(base.BaseTestCase):
|
||||||
'cluster_ip_addresses': 'localhost',
|
'cluster_ip_addresses': 'localhost',
|
||||||
'keyspace': 'test'
|
'keyspace': 'test'
|
||||||
}
|
}
|
||||||
self._conf.config(group='repositories', **messaging_conf)
|
self.conf_override(group='repositories', **messaging_conf)
|
||||||
self._conf.config(group='cassandra', **cassandra_conf)
|
self.conf_override(group='cassandra', **cassandra_conf)
|
||||||
|
|
||||||
cluster = mock.Mock()
|
cluster = mock.Mock()
|
||||||
cas_mock = mock.Mock()
|
cas_mock = mock.Mock()
|
||||||
|
@ -181,8 +179,8 @@ class TestMetricsDbHealthCheck(base.BaseTestCase):
|
||||||
'cluster_ip_addresses': 'localhost',
|
'cluster_ip_addresses': 'localhost',
|
||||||
'keyspace': 'test'
|
'keyspace': 'test'
|
||||||
}
|
}
|
||||||
self._conf.config(group='repositories', **messaging_conf)
|
self.conf_override(group='repositories', **messaging_conf)
|
||||||
self._conf.config(group='cassandra', **cassandra_conf)
|
self.conf_override(group='cassandra', **cassandra_conf)
|
||||||
|
|
||||||
# Simulate cassandra driver not available
|
# Simulate cassandra driver not available
|
||||||
try_import.return_value = None
|
try_import.return_value = None
|
||||||
|
@ -202,8 +200,8 @@ class TestMetricsDbHealthCheck(base.BaseTestCase):
|
||||||
'cluster_ip_addresses': 'localhost',
|
'cluster_ip_addresses': 'localhost',
|
||||||
'keyspace': 'test'
|
'keyspace': 'test'
|
||||||
}
|
}
|
||||||
self._conf.config(group='repositories', **messaging_conf)
|
self.conf_override(group='repositories', **messaging_conf)
|
||||||
self._conf.config(group='cassandra', **cassandra_conf)
|
self.conf_override(group='cassandra', **cassandra_conf)
|
||||||
|
|
||||||
db_health = tdc.MetricsDbCheck()
|
db_health = tdc.MetricsDbCheck()
|
||||||
result = db_health.health_check()
|
result = db_health.health_check()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# Copyright 2015 Cray
|
# Copyright 2015 Cray
|
||||||
# Copyright 2016 FUJITSU LIMITED
|
# Copyright 2016-2017 FUJITSU LIMITED
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
# not use this file except in compliance with the License. You may obtain
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
@ -13,37 +13,37 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import fixtures
|
|
||||||
import testtools
|
|
||||||
|
|
||||||
from sqlalchemy import select, MetaData, text, asc
|
from sqlalchemy import select, MetaData, text, asc
|
||||||
|
|
||||||
from monasca_api.common.repositories.sqla import models
|
from monasca_api.common.repositories.sqla import models
|
||||||
|
from monasca_api.tests import base
|
||||||
|
|
||||||
|
|
||||||
class TestModelsDB(testtools.TestCase, fixtures.TestWithFixtures):
|
class TestModelsDB(base.BaseTestCase):
|
||||||
@classmethod
|
|
||||||
def setUpClass(cls):
|
def setUp(self):
|
||||||
|
super(TestModelsDB, self).setUp()
|
||||||
metadata = MetaData()
|
metadata = MetaData()
|
||||||
|
|
||||||
md = models.create_md_model(metadata)
|
md = models.create_md_model(metadata)
|
||||||
gc_columns = [md.c.name + text("'='") + md.c.value]
|
gc_columns = [md.c.name + text("'='") + md.c.value]
|
||||||
cls.group_concat_md = (select([md.c.dimension_set_id,
|
self.group_concat_md = (select([md.c.dimension_set_id,
|
||||||
models.group_concat(gc_columns).label('dimensions')])
|
models.group_concat(gc_columns).label('dimensions')])
|
||||||
.select_from(md)
|
.select_from(md)
|
||||||
.group_by(md.c.dimension_set_id))
|
.group_by(md.c.dimension_set_id))
|
||||||
|
|
||||||
cls.group_concat_md_order = (select([md.c.dimension_set_id,
|
self.group_concat_md_order = (select([md.c.dimension_set_id,
|
||||||
models.group_concat(gc_columns,
|
models.group_concat(gc_columns,
|
||||||
order_by=[md.c.name.asc()]).label('dimensions')])
|
order_by=[md.c.name.asc()]).label('dimensions')])
|
||||||
.select_from(md)
|
.select_from(md)
|
||||||
.group_by(md.c.dimension_set_id))
|
.group_by(md.c.dimension_set_id))
|
||||||
|
|
||||||
cls.order_by_field = (select([md.c.dimension_set_id])
|
self.order_by_field = (select([md.c.dimension_set_id])
|
||||||
.select_from(md)
|
.select_from(md)
|
||||||
.order_by(asc(models.field_sort(md.c.dimension_set_id, map(text,
|
.order_by(asc(models.field_sort(md.c.dimension_set_id, map(text,
|
||||||
["'A'",
|
["'A'",
|
||||||
"'B'",
|
"'B'",
|
||||||
"'C'"])))))
|
"'C'"])))))
|
||||||
|
|
||||||
def test_oracle(self):
|
def test_oracle(self):
|
||||||
from sqlalchemy.dialects import oracle
|
from sqlalchemy.dialects import oracle
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# Copyright 2015 Cray
|
# Copyright 2015 Cray
|
||||||
# Copyright 2016 FUJITSU LIMITED
|
# Copyright 2016-2017 FUJITSU LIMITED
|
||||||
# (C) Copyright 2016 Hewlett Packard Enterprise Development Company LP
|
# (C) Copyright 2016 Hewlett Packard Enterprise Development Company LP
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
@ -21,14 +21,14 @@ from oslo_config import cfg
|
||||||
from oslo_config import fixture as fixture_config
|
from oslo_config import fixture as fixture_config
|
||||||
from oslo_db.sqlalchemy.engines import create_engine
|
from oslo_db.sqlalchemy.engines import create_engine
|
||||||
from sqlalchemy import delete, MetaData, insert, bindparam
|
from sqlalchemy import delete, MetaData, insert, bindparam
|
||||||
import testtools
|
|
||||||
|
|
||||||
from monasca_api.common.repositories.sqla import models
|
from monasca_api.common.repositories.sqla import models
|
||||||
|
from monasca_api.tests import base
|
||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
|
|
||||||
|
|
||||||
class TestNotificationMethodRepoDB(testtools.TestCase, fixtures.TestWithFixtures):
|
class TestNotificationMethodRepoDB(base.BaseTestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
engine = create_engine('sqlite://')
|
engine = create_engine('sqlite://')
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# Copyright 2015 Cray Inc. All Rights Reserved.
|
# Copyright 2015 Cray Inc. All Rights Reserved.
|
||||||
# Copyright 2016 Hewlett Packard Enterprise Development Company, L.P.
|
# Copyright 2016 Hewlett Packard Enterprise Development Company, L.P.
|
||||||
|
# Copyright 2017 Fujitsu LIMITED
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
# not use this file except in compliance with the License. You may obtain
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
@ -13,14 +14,13 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
from mock import Mock
|
from mock import Mock
|
||||||
|
|
||||||
import monasca_api.v2.reference.helpers as helpers
|
from monasca_api.tests import base
|
||||||
|
from monasca_api.v2.reference import helpers
|
||||||
|
|
||||||
|
|
||||||
class TestGetQueryDimension(unittest.TestCase):
|
class TestGetQueryDimension(base.BaseTestCase):
|
||||||
|
|
||||||
def test_no_dimensions(self):
|
def test_no_dimensions(self):
|
||||||
req = Mock()
|
req = Mock()
|
||||||
|
@ -110,7 +110,7 @@ class TestGetQueryDimension(unittest.TestCase):
|
||||||
self.assertEqual(result, {})
|
self.assertEqual(result, {})
|
||||||
|
|
||||||
|
|
||||||
class TestGetOldQueryParams(unittest.TestCase):
|
class TestGetOldQueryParams(base.BaseTestCase):
|
||||||
|
|
||||||
def test_old_query_params(self):
|
def test_old_query_params(self):
|
||||||
uri = Mock()
|
uri = Mock()
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# Copyright 2015 Cray Inc. All Rights Reserved.
|
# Copyright 2015 Cray Inc. All Rights Reserved.
|
||||||
# (C) Copyright 2016-2017 Hewlett Packard Enterprise Development LP
|
# (C) Copyright 2016-2017 Hewlett Packard Enterprise Development LP
|
||||||
|
# Copyright 2017 Fujitsu LIMITED
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
# not use this file except in compliance with the License. You may obtain
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
@ -16,27 +17,25 @@
|
||||||
import binascii
|
import binascii
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import unittest
|
|
||||||
|
|
||||||
from mock import patch
|
from mock import patch
|
||||||
|
|
||||||
import monasca_api.common.repositories.cassandra.metrics_repository as cassandra_repo
|
|
||||||
import monasca_api.common.repositories.influxdb.metrics_repository as influxdb_repo
|
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_config import fixture as fixture_config
|
|
||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
import testtools
|
|
||||||
|
from monasca_api.common.repositories.cassandra import metrics_repository \
|
||||||
|
as cassandra_repo
|
||||||
|
from monasca_api.common.repositories.influxdb import metrics_repository \
|
||||||
|
as influxdb_repo
|
||||||
|
from monasca_api.tests import base
|
||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
|
|
||||||
|
|
||||||
class TestRepoMetricsInfluxDB(unittest.TestCase):
|
class TestRepoMetricsInfluxDB(base.BaseTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
@patch("monasca_api.common.repositories.influxdb."
|
||||||
super(TestRepoMetricsInfluxDB, self).setUp()
|
"metrics_repository.client.InfluxDBClient")
|
||||||
|
|
||||||
@patch("monasca_api.common.repositories.influxdb.metrics_repository.client.InfluxDBClient")
|
|
||||||
def test_measurement_list(self, influxdb_client_mock):
|
def test_measurement_list(self, influxdb_client_mock):
|
||||||
mock_client = influxdb_client_mock.return_value
|
mock_client = influxdb_client_mock.return_value
|
||||||
mock_client.query.return_value.raw = {
|
mock_client.query.return_value.raw = {
|
||||||
|
@ -82,7 +81,8 @@ class TestRepoMetricsInfluxDB(unittest.TestCase):
|
||||||
measurements
|
measurements
|
||||||
)
|
)
|
||||||
|
|
||||||
@patch("monasca_api.common.repositories.influxdb.metrics_repository.client.InfluxDBClient")
|
@patch("monasca_api.common.repositories.influxdb."
|
||||||
|
"metrics_repository.client.InfluxDBClient")
|
||||||
def test_list_metrics(self, influxdb_client_mock):
|
def test_list_metrics(self, influxdb_client_mock):
|
||||||
mock_client = influxdb_client_mock.return_value
|
mock_client = influxdb_client_mock.return_value
|
||||||
mock_client.query.return_value.raw = {
|
mock_client.query.return_value.raw = {
|
||||||
|
@ -130,7 +130,8 @@ class TestRepoMetricsInfluxDB(unittest.TestCase):
|
||||||
},
|
},
|
||||||
}])
|
}])
|
||||||
|
|
||||||
@patch("monasca_api.common.repositories.influxdb.metrics_repository.client.InfluxDBClient")
|
@patch("monasca_api.common.repositories.influxdb."
|
||||||
|
"metrics_repository.client.InfluxDBClient")
|
||||||
def test_list_dimension_values(self, influxdb_client_mock):
|
def test_list_dimension_values(self, influxdb_client_mock):
|
||||||
mock_client = influxdb_client_mock.return_value
|
mock_client = influxdb_client_mock.return_value
|
||||||
mock_client.query.return_value.raw = {
|
mock_client.query.return_value.raw = {
|
||||||
|
@ -158,7 +159,8 @@ class TestRepoMetricsInfluxDB(unittest.TestCase):
|
||||||
' where _tenant_id = \'38dc2a2549f94d2e9a4fa1cc45a4970c\''
|
' where _tenant_id = \'38dc2a2549f94d2e9a4fa1cc45a4970c\''
|
||||||
' and _region = \'useast\' ')
|
' and _region = \'useast\' ')
|
||||||
|
|
||||||
@patch("monasca_api.common.repositories.influxdb.metrics_repository.client.InfluxDBClient")
|
@patch("monasca_api.common.repositories.influxdb."
|
||||||
|
"metrics_repository.client.InfluxDBClient")
|
||||||
def test_list_dimension_names(self, influxdb_client_mock):
|
def test_list_dimension_names(self, influxdb_client_mock):
|
||||||
mock_client = influxdb_client_mock.return_value
|
mock_client = influxdb_client_mock.return_value
|
||||||
mock_client.query.return_value.raw = {
|
mock_client.query.return_value.raw = {
|
||||||
|
@ -184,17 +186,15 @@ class TestRepoMetricsInfluxDB(unittest.TestCase):
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
class TestRepoMetricsCassandra(testtools.TestCase):
|
class TestRepoMetricsCassandra(base.BaseTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestRepoMetricsCassandra, self).setUp()
|
super(TestRepoMetricsCassandra, self).setUp()
|
||||||
|
self.conf_default(cluster_ip_addresses='127.0.0.1',
|
||||||
|
group='cassandra')
|
||||||
|
|
||||||
self._fixture_config = self.useFixture(
|
@patch("monasca_api.common.repositories.cassandra."
|
||||||
fixture_config.Config(cfg.CONF))
|
"metrics_repository.Cluster.connect")
|
||||||
self._fixture_config.config(cluster_ip_addresses='127.0.0.1',
|
|
||||||
group='cassandra')
|
|
||||||
|
|
||||||
@patch("monasca_api.common.repositories.cassandra.metrics_repository.Cluster.connect")
|
|
||||||
def test_list_metrics(self, cassandra_connect_mock):
|
def test_list_metrics(self, cassandra_connect_mock):
|
||||||
cassandra_session_mock = cassandra_connect_mock.return_value
|
cassandra_session_mock = cassandra_connect_mock.return_value
|
||||||
cassandra_session_mock.execute.return_value = [[
|
cassandra_session_mock.execute.return_value = [[
|
||||||
|
@ -234,7 +234,8 @@ class TestRepoMetricsCassandra(testtools.TestCase):
|
||||||
u'hosttype': u'native'
|
u'hosttype': u'native'
|
||||||
}}], result)
|
}}], result)
|
||||||
|
|
||||||
@patch("monasca_api.common.repositories.cassandra.metrics_repository.Cluster.connect")
|
@patch("monasca_api.common.repositories.cassandra."
|
||||||
|
"metrics_repository.Cluster.connect")
|
||||||
def test_list_metric_names(self, cassandra_connect_mock):
|
def test_list_metric_names(self, cassandra_connect_mock):
|
||||||
|
|
||||||
Metric_map = namedtuple('Metric_map', 'metric_map')
|
Metric_map = namedtuple('Metric_map', 'metric_map')
|
||||||
|
@ -278,7 +279,8 @@ class TestRepoMetricsCassandra(testtools.TestCase):
|
||||||
}
|
}
|
||||||
], result)
|
], result)
|
||||||
|
|
||||||
@patch("monasca_api.common.repositories.cassandra.metrics_repository.Cluster.connect")
|
@patch("monasca_api.common.repositories.cassandra."
|
||||||
|
"metrics_repository.Cluster.connect")
|
||||||
def test_measurement_list(self, cassandra_connect_mock):
|
def test_measurement_list(self, cassandra_connect_mock):
|
||||||
|
|
||||||
Measurement = namedtuple('Measurement', 'time_stamp value value_meta')
|
Measurement = namedtuple('Measurement', 'time_stamp value value_meta')
|
||||||
|
@ -335,7 +337,8 @@ class TestRepoMetricsCassandra(testtools.TestCase):
|
||||||
measurements
|
measurements
|
||||||
)
|
)
|
||||||
|
|
||||||
@patch("monasca_api.common.repositories.cassandra.metrics_repository.Cluster.connect")
|
@patch("monasca_api.common.repositories.cassandra."
|
||||||
|
"metrics_repository.Cluster.connect")
|
||||||
def test_metrics_statistics(self, cassandra_connect_mock):
|
def test_metrics_statistics(self, cassandra_connect_mock):
|
||||||
|
|
||||||
Measurement = namedtuple('Measurement', 'time_stamp value value_meta')
|
Measurement = namedtuple('Measurement', 'time_stamp value value_meta')
|
||||||
|
@ -390,7 +393,8 @@ class TestRepoMetricsCassandra(testtools.TestCase):
|
||||||
}
|
}
|
||||||
], result)
|
], result)
|
||||||
|
|
||||||
@patch("monasca_api.common.repositories.cassandra.metrics_repository.Cluster.connect")
|
@patch("monasca_api.common.repositories.cassandra."
|
||||||
|
"metrics_repository.Cluster.connect")
|
||||||
def test_alarm_history(self, cassandra_connect_mock):
|
def test_alarm_history(self, cassandra_connect_mock):
|
||||||
|
|
||||||
AlarmHistory = namedtuple('AlarmHistory', 'alarm_id, time_stamp, metrics, '
|
AlarmHistory = namedtuple('AlarmHistory', 'alarm_id, time_stamp, metrics, '
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Copyright 2016 FUJITSU LIMITED
|
# Copyright 2016-2017 FUJITSU LIMITED
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
# not use this file except in compliance with the License. You may obtain
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
@ -13,20 +13,17 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from mock import mock
|
from mock import mock
|
||||||
from oslo_config import fixture as oo_cfg
|
|
||||||
from oslo_context import fixture as oo_ctx
|
|
||||||
|
|
||||||
from falcon import testing
|
|
||||||
|
|
||||||
from monasca_api.api.core import request
|
from monasca_api.api.core import request
|
||||||
|
from monasca_api.tests import base
|
||||||
from monasca_api.v2.common import exceptions
|
from monasca_api.v2.common import exceptions
|
||||||
|
|
||||||
|
|
||||||
class TestRequest(testing.TestBase):
|
class TestRequest(base.BaseApiTestCase):
|
||||||
|
|
||||||
def test_use_context_from_request(self):
|
def test_use_context_from_request(self):
|
||||||
req = request.Request(
|
req = request.Request(
|
||||||
testing.create_environ(
|
self.create_environ(
|
||||||
path='/',
|
path='/',
|
||||||
headers={
|
headers={
|
||||||
'X_AUTH_TOKEN': '111',
|
'X_AUTH_TOKEN': '111',
|
||||||
|
@ -43,16 +40,12 @@ class TestRequest(testing.TestBase):
|
||||||
self.assertEqual(['terminator', 'predator'], req.roles)
|
self.assertEqual(['terminator', 'predator'], req.roles)
|
||||||
|
|
||||||
|
|
||||||
class TestRequestLimit(testing.TestBase):
|
class TestRequestLimit(base.BaseApiTestCase):
|
||||||
def setUp(self):
|
|
||||||
super(TestRequestLimit, self).setUp()
|
|
||||||
self.useFixture(oo_cfg.Config())
|
|
||||||
self.useFixture(oo_ctx.ClearRequestContext())
|
|
||||||
|
|
||||||
def test_valid_limit(self):
|
def test_valid_limit(self):
|
||||||
expected_limit = 10
|
expected_limit = 10
|
||||||
req = request.Request(
|
req = request.Request(
|
||||||
testing.create_environ(
|
self.create_environ(
|
||||||
path='/',
|
path='/',
|
||||||
query_string='limit=%d' % expected_limit,
|
query_string='limit=%d' % expected_limit,
|
||||||
headers={
|
headers={
|
||||||
|
@ -67,7 +60,7 @@ class TestRequestLimit(testing.TestBase):
|
||||||
|
|
||||||
def test_invalid_limit(self):
|
def test_invalid_limit(self):
|
||||||
req = request.Request(
|
req = request.Request(
|
||||||
testing.create_environ(
|
self.create_environ(
|
||||||
path='/',
|
path='/',
|
||||||
query_string='limit=abc',
|
query_string='limit=abc',
|
||||||
headers={
|
headers={
|
||||||
|
@ -92,7 +85,7 @@ class TestRequestLimit(testing.TestBase):
|
||||||
@mock.patch('monasca_api.common.repositories.constants.PAGE_LIMIT')
|
@mock.patch('monasca_api.common.repositories.constants.PAGE_LIMIT')
|
||||||
def test_default_limit(self, page_limit):
|
def test_default_limit(self, page_limit):
|
||||||
req = request.Request(
|
req = request.Request(
|
||||||
testing.create_environ(
|
self.create_environ(
|
||||||
path='/',
|
path='/',
|
||||||
headers={
|
headers={
|
||||||
'X_AUTH_TOKEN': '111',
|
'X_AUTH_TOKEN': '111',
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# (C) Copyright 2015-2017 Hewlett Packard Enterprise Development LP
|
# (C) Copyright 2015-2017 Hewlett Packard Enterprise Development LP
|
||||||
# Copyright 2015 Cray Inc. All Rights Reserved.
|
# Copyright 2015 Cray Inc. All Rights Reserved.
|
||||||
|
# Copyright 2017 Fujitsu LIMITED
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
# not use this file except in compliance with the License. You may obtain
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
@ -13,11 +14,10 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
import falcon
|
import falcon
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
|
from monasca_api.tests import base
|
||||||
import monasca_api.v2.common.exceptions as common_exceptions
|
import monasca_api.v2.common.exceptions as common_exceptions
|
||||||
import monasca_api.v2.common.schemas.alarm_definition_request_body_schema as schemas_alarm_defs
|
import monasca_api.v2.common.schemas.alarm_definition_request_body_schema as schemas_alarm_defs
|
||||||
import monasca_api.v2.common.schemas.exceptions as schemas_exceptions
|
import monasca_api.v2.common.schemas.exceptions as schemas_exceptions
|
||||||
|
@ -26,7 +26,7 @@ import monasca_api.v2.common.validation as validation
|
||||||
import monasca_api.v2.reference.helpers as helpers
|
import monasca_api.v2.reference.helpers as helpers
|
||||||
|
|
||||||
|
|
||||||
class TestStateValidation(unittest.TestCase):
|
class TestStateValidation(base.BaseTestCase):
|
||||||
|
|
||||||
VALID_STATES = "OK", "ALARM", "UNDETERMINED"
|
VALID_STATES = "OK", "ALARM", "UNDETERMINED"
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ class TestStateValidation(unittest.TestCase):
|
||||||
validation.validate_alarm_state, 'BOGUS')
|
validation.validate_alarm_state, 'BOGUS')
|
||||||
|
|
||||||
|
|
||||||
class TestSeverityValidation(unittest.TestCase):
|
class TestSeverityValidation(base.BaseTestCase):
|
||||||
|
|
||||||
VALID_SEVERITIES = "LOW", "MEDIUM", "HIGH", "CRITICAL"
|
VALID_SEVERITIES = "LOW", "MEDIUM", "HIGH", "CRITICAL"
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ class TestSeverityValidation(unittest.TestCase):
|
||||||
'|'.join([self.VALID_SEVERITIES[0], 'BOGUS']))
|
'|'.join([self.VALID_SEVERITIES[0], 'BOGUS']))
|
||||||
|
|
||||||
|
|
||||||
class TestRoleValidation(unittest.TestCase):
|
class TestRoleValidation(base.BaseTestCase):
|
||||||
|
|
||||||
def test_role_valid(self):
|
def test_role_valid(self):
|
||||||
req_roles = 'role0', 'rOlE1'
|
req_roles = 'role0', 'rOlE1'
|
||||||
|
@ -116,7 +116,7 @@ class TestRoleValidation(unittest.TestCase):
|
||||||
helpers.validate_authorization, req, authorized_roles)
|
helpers.validate_authorization, req, authorized_roles)
|
||||||
|
|
||||||
|
|
||||||
class TestTimestampsValidation(unittest.TestCase):
|
class TestTimestampsValidation(base.BaseTestCase):
|
||||||
|
|
||||||
def test_valid_timestamps(self):
|
def test_valid_timestamps(self):
|
||||||
start_time = '2015-01-01T00:00:00Z'
|
start_time = '2015-01-01T00:00:00Z'
|
||||||
|
@ -153,7 +153,7 @@ class TestTimestampsValidation(unittest.TestCase):
|
||||||
start_timestamp, end_timestamp)
|
start_timestamp, end_timestamp)
|
||||||
|
|
||||||
|
|
||||||
class TestConvertTimeString(unittest.TestCase):
|
class TestConvertTimeString(base.BaseTestCase):
|
||||||
|
|
||||||
def test_valid_date_time_string(self):
|
def test_valid_date_time_string(self):
|
||||||
date_time_string = '2015-01-01T00:00:00Z'
|
date_time_string = '2015-01-01T00:00:00Z'
|
||||||
|
@ -183,7 +183,7 @@ class TestConvertTimeString(unittest.TestCase):
|
||||||
valid_periods = [0, 60]
|
valid_periods = [0, 60]
|
||||||
|
|
||||||
|
|
||||||
class TestNotificationValidation(unittest.TestCase):
|
class TestNotificationValidation(base.BaseTestCase):
|
||||||
|
|
||||||
def test_validation_for_email(self):
|
def test_validation_for_email(self):
|
||||||
notification = {"name": "MyEmail", "type": "EMAIL", "address": "name@domain.com"}
|
notification = {"name": "MyEmail", "type": "EMAIL", "address": "name@domain.com"}
|
||||||
|
@ -194,16 +194,16 @@ class TestNotificationValidation(unittest.TestCase):
|
||||||
|
|
||||||
def test_validation_exception_for_invalid_email_address(self):
|
def test_validation_exception_for_invalid_email_address(self):
|
||||||
notification = {"name": "MyEmail", "type": "EMAIL", "address": "name@"}
|
notification = {"name": "MyEmail", "type": "EMAIL", "address": "name@"}
|
||||||
with self.assertRaises(schemas_exceptions.ValidationException) as ve:
|
ex = self.assertRaises(schemas_exceptions.ValidationException,
|
||||||
schemas_notifications.parse_and_validate(notification, valid_periods)
|
schemas_notifications.parse_and_validate,
|
||||||
ex = ve.exception
|
notification, valid_periods)
|
||||||
self.assertEqual("Address name@ is not of correct format", ex.message)
|
self.assertEqual("Address name@ is not of correct format", str(ex))
|
||||||
|
|
||||||
def test_validation_exception_for_invalid_period_for_email(self):
|
def test_validation_exception_for_invalid_period_for_email(self):
|
||||||
notification = {"name": "MyEmail", "type": "EMAIL", "address": "name@domain.com", "period": "60"}
|
notification = {"name": "MyEmail", "type": "EMAIL", "address": "name@domain.com", "period": "60"}
|
||||||
with self.assertRaises(schemas_exceptions.ValidationException) as ve:
|
ex = self.assertRaises(schemas_exceptions.ValidationException,
|
||||||
schemas_notifications.parse_and_validate(notification, valid_periods)
|
schemas_notifications.parse_and_validate,
|
||||||
ex = ve.exception
|
notification, valid_periods)
|
||||||
self.assertEqual("Period can only be set with webhooks", ex.message)
|
self.assertEqual("Period can only be set with webhooks", ex.message)
|
||||||
|
|
||||||
def test_validation_for_webhook(self):
|
def test_validation_for_webhook(self):
|
||||||
|
@ -223,31 +223,31 @@ class TestNotificationValidation(unittest.TestCase):
|
||||||
|
|
||||||
def test_validation_exception_for_webhook_no_scheme(self):
|
def test_validation_exception_for_webhook_no_scheme(self):
|
||||||
notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "//somedomain.com"}
|
notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "//somedomain.com"}
|
||||||
with self.assertRaises(schemas_exceptions.ValidationException) as ve:
|
ex = self.assertRaises(schemas_exceptions.ValidationException,
|
||||||
schemas_notifications.parse_and_validate(notification, valid_periods)
|
schemas_notifications.parse_and_validate,
|
||||||
ex = ve.exception
|
notification, valid_periods)
|
||||||
self.assertEqual("Address //somedomain.com does not have URL scheme", ex.message)
|
self.assertEqual("Address //somedomain.com does not have URL scheme", ex.message)
|
||||||
|
|
||||||
def test_validation_exception_for_webhook_no_netloc(self):
|
def test_validation_exception_for_webhook_no_netloc(self):
|
||||||
notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "http://"}
|
notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "http://"}
|
||||||
with self.assertRaises(schemas_exceptions.ValidationException) as ve:
|
ex = self.assertRaises(schemas_exceptions.ValidationException,
|
||||||
schemas_notifications.parse_and_validate(notification, valid_periods)
|
schemas_notifications.parse_and_validate,
|
||||||
ex = ve.exception
|
notification, valid_periods)
|
||||||
self.assertEqual("Address http:// does not have network location", ex.message)
|
self.assertEqual("Address http:// does not have network location", ex.message)
|
||||||
|
|
||||||
def test_validation_exception_for_webhook_invalid_scheme(self):
|
def test_validation_exception_for_webhook_invalid_scheme(self):
|
||||||
notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "ftp://somedomain.com"}
|
notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "ftp://somedomain.com"}
|
||||||
with self.assertRaises(schemas_exceptions.ValidationException) as ve:
|
ex = self.assertRaises(schemas_exceptions.ValidationException,
|
||||||
schemas_notifications.parse_and_validate(notification, valid_periods)
|
schemas_notifications.parse_and_validate,
|
||||||
ex = ve.exception
|
notification, valid_periods)
|
||||||
self.assertEqual("Address ftp://somedomain.com scheme is not in ['http', 'https']", ex.message)
|
self.assertEqual("Address ftp://somedomain.com scheme is not in ['http', 'https']", ex.message)
|
||||||
|
|
||||||
def test_validation_exception_for_webhook_invalid_period(self):
|
def test_validation_exception_for_webhook_invalid_period(self):
|
||||||
notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "//somedomain.com",
|
notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "//somedomain.com",
|
||||||
"period": "10"}
|
"period": "10"}
|
||||||
with self.assertRaises(schemas_exceptions.ValidationException) as ve:
|
ex = self.assertRaises(schemas_exceptions.ValidationException,
|
||||||
schemas_notifications.parse_and_validate(notification, valid_periods)
|
schemas_notifications.parse_and_validate,
|
||||||
ex = ve.exception
|
notification, valid_periods)
|
||||||
self.assertEqual("10 is not a valid period, not in [0, 60]", ex.message)
|
self.assertEqual("10 is not a valid period, not in [0, 60]", ex.message)
|
||||||
|
|
||||||
def test_validation_for_pagerduty(self):
|
def test_validation_for_pagerduty(self):
|
||||||
|
@ -261,9 +261,9 @@ class TestNotificationValidation(unittest.TestCase):
|
||||||
def test_validation_exception_for_invalid_period_for_pagerduty(self):
|
def test_validation_exception_for_invalid_period_for_pagerduty(self):
|
||||||
notification = {"name": "MyPagerduty", "type": "PAGERDUTY",
|
notification = {"name": "MyPagerduty", "type": "PAGERDUTY",
|
||||||
"address": "nzH2LVRdMzun11HNC2oD", "period": 60}
|
"address": "nzH2LVRdMzun11HNC2oD", "period": 60}
|
||||||
with self.assertRaises(schemas_exceptions.ValidationException) as ve:
|
ex = self.assertRaises(schemas_exceptions.ValidationException,
|
||||||
schemas_notifications.parse_and_validate(notification, valid_periods)
|
schemas_notifications.parse_and_validate,
|
||||||
ex = ve.exception
|
notification, valid_periods)
|
||||||
self.assertEqual("Period can only be set with webhooks", ex.message)
|
self.assertEqual("Period can only be set with webhooks", ex.message)
|
||||||
|
|
||||||
def test_validation_for_max_name_address(self):
|
def test_validation_for_max_name_address(self):
|
||||||
|
@ -283,7 +283,8 @@ class TestNotificationValidation(unittest.TestCase):
|
||||||
notification = {"name": name, "type": "WEBHOOK", "address": "http://somedomain.com"}
|
notification = {"name": name, "type": "WEBHOOK", "address": "http://somedomain.com"}
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
schemas_exceptions.ValidationException,
|
schemas_exceptions.ValidationException,
|
||||||
schemas_notifications.parse_and_validate, notification, valid_periods)
|
schemas_notifications.parse_and_validate,
|
||||||
|
notification, valid_periods)
|
||||||
|
|
||||||
def test_validation_exception_for_exceeded_address_length(self):
|
def test_validation_exception_for_exceeded_address_length(self):
|
||||||
address = "http://" + "A" * 503 + ".io"
|
address = "http://" + "A" * 503 + ".io"
|
||||||
|
@ -296,30 +297,31 @@ class TestNotificationValidation(unittest.TestCase):
|
||||||
def test_validation_exception_for_invalid_period_float(self):
|
def test_validation_exception_for_invalid_period_float(self):
|
||||||
notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "//somedomain.com",
|
notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "//somedomain.com",
|
||||||
"period": 1.2}
|
"period": 1.2}
|
||||||
with self.assertRaises(schemas_exceptions.ValidationException) as ve:
|
ex = self.assertRaises(schemas_exceptions.ValidationException,
|
||||||
schemas_notifications.parse_and_validate(notification, valid_periods)
|
schemas_notifications.parse_and_validate,
|
||||||
ex = ve.exception
|
notification, valid_periods)
|
||||||
self.assertEqual("expected int for dictionary value @ data['period']", ex.message)
|
self.assertEqual("expected int for dictionary value @ data['period']", ex.message)
|
||||||
|
|
||||||
def test_validation_exception_for_invalid_period_non_int(self):
|
def test_validation_exception_for_invalid_period_non_int(self):
|
||||||
notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "//somedomain.com",
|
notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "//somedomain.com",
|
||||||
"period": "zero"}
|
"period": "zero"}
|
||||||
with self.assertRaises(schemas_exceptions.ValidationException) as ve:
|
ex = self.assertRaises(schemas_exceptions.ValidationException,
|
||||||
schemas_notifications.parse_and_validate(notification, valid_periods)
|
schemas_notifications.parse_and_validate,
|
||||||
ex = ve.exception
|
notification, valid_periods)
|
||||||
self.assertEqual("Period zero must be a valid integer", ex.message)
|
self.assertEqual("Period zero must be a valid integer", ex.message)
|
||||||
|
|
||||||
def test_validation_exception_for_missing_period(self):
|
def test_validation_exception_for_missing_period(self):
|
||||||
notification = {"name": "MyEmail", "type": "EMAIL", "address": "name@domain."}
|
notification = {"name": "MyEmail", "type": "EMAIL", "address": "name@domain."}
|
||||||
with self.assertRaises(schemas_exceptions.ValidationException) as ve:
|
ex = self.assertRaises(schemas_exceptions.ValidationException,
|
||||||
schemas_notifications.parse_and_validate(notification, valid_periods, require_all=True)
|
schemas_notifications.parse_and_validate,
|
||||||
ex = ve.exception
|
notification, valid_periods, require_all=True)
|
||||||
self.assertEqual("Period is required", ex.message)
|
self.assertEqual("Period is required", ex.message)
|
||||||
|
|
||||||
|
|
||||||
class TestAlarmDefinitionValidation(unittest.TestCase):
|
class TestAlarmDefinitionValidation(base.BaseTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
super(TestAlarmDefinitionValidation, self).setUp()
|
||||||
self.full_alarm_definition = (
|
self.full_alarm_definition = (
|
||||||
{"name": self._create_string_of_length(255),
|
{"name": self._create_string_of_length(255),
|
||||||
"expression": "min(cpu.idle_perc) < 10",
|
"expression": "min(cpu.idle_perc) < 10",
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# Copyright 2015 Hewlett-Packard
|
# Copyright 2015 Hewlett-Packard
|
||||||
|
# Copyright 2017 Fujitsu LIMITED
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
# not use this file except in compliance with the License. You may obtain
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
@ -16,12 +17,12 @@ import datetime
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import falcon
|
import falcon
|
||||||
import falcon.testing as testing
|
|
||||||
|
|
||||||
|
from monasca_api.tests import base
|
||||||
from monasca_api.v2.reference import versions
|
from monasca_api.v2.reference import versions
|
||||||
|
|
||||||
|
|
||||||
class TestVersions(testing.TestBase):
|
class TestVersions(base.BaseApiTestCase):
|
||||||
|
|
||||||
def before(self):
|
def before(self):
|
||||||
self.versions_resource = versions.Versions()
|
self.versions_resource = versions.Versions()
|
||||||
|
|
2
tox.ini
2
tox.ini
|
@ -50,7 +50,7 @@ skip_install = True
|
||||||
usedevelop = False
|
usedevelop = False
|
||||||
commands =
|
commands =
|
||||||
{[testenv]commands}
|
{[testenv]commands}
|
||||||
flake8 monasca_api monasca_tempest_tests --statistics
|
flake8 monasca_api monasca_tempest_tests
|
||||||
|
|
||||||
[testenv:bandit]
|
[testenv:bandit]
|
||||||
skip_install = True
|
skip_install = True
|
||||||
|
|
Loading…
Reference in New Issue