Mehdi Abaakouk 9f37e22c47 Remove the mongo auth warning during tests
pymongo print a warning on each mongodb connection because the url used
in tests don't have credentials, since all mongodb tests are running in
a different mongodb databases, this print many annoying line like this one:

UserWarning: database name or authSource in URI is being ignored. If you
wish to authenticate to ceilometer_90d94586954643e8811d5ecc6bacf912, you
must provide a username and password.

This change suppress this line during testing.

Fixes bug #1210674

Change-Id: Iecabca621c2fbaf15e644f2fca66b4e3b5bd04e7
2013-08-14 11:45:27 +02:00

75 lines
2.3 KiB
Python

# -*- encoding: utf-8 -*-
#
# Copyright © 2012 New Dream Network, LLC (DreamHost)
# Copyright © 2013 eNovance
#
# Author: Doug Hellmann <doug.hellmann@dreamhost.com>
# Julien Danjou <julien@danjou.info>
#
# 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
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Base classes for API tests."""
import os
import uuid
import warnings
from oslo.config import cfg
from ceilometer import storage
from ceilometer.tests import base as test_base
class TestBase(test_base.TestCase):
def setUp(self):
super(TestBase, self).setUp()
cfg.CONF.set_override('connection', str(self.database_connection),
group='database')
with warnings.catch_warnings():
warnings.filterwarnings(
action='ignore',
message='.*you must provide a username and password.*')
try:
self.conn = storage.get_connection(cfg.CONF)
except storage.StorageBadVersion as e:
self.skipTest(str(e))
self.conn.upgrade()
def tearDown(self):
self.conn.clear()
self.conn = None
super(TestBase, self).tearDown()
class MongoDBFakeConnectionUrl(object):
def __init__(self):
self.url = os.environ.get('CEILOMETER_TEST_MONGODB_URL')
if not self.url:
raise RuntimeError(
"No MongoDB test URL set,"
"export CEILOMETER_TEST_MONGODB_URL environment variable")
def __str__(self):
return '%(url)s_%(db)s' % dict(url=self.url, db=uuid.uuid4().hex)
class MixinTestsWithBackendScenarios(object):
__metaclass__ = test_base.SkipNotImplementedMeta
scenarios = [
('sqlalchemy', dict(database_connection='sqlite://')),
('mongodb', dict(database_connection=MongoDBFakeConnectionUrl())),
('hbase', dict(database_connection='hbase://__test__')),
]