mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 10:00:01 -03:30
do not run tests if mongodb connect fails
This commit is contained in:
parent
c03cef022d
commit
35e1c19fc2
@ -26,7 +26,7 @@ from django.test.client import Client
|
||||
from django.test.utils import override_settings
|
||||
|
||||
# MongoEngine
|
||||
from mongoengine.connection import get_db
|
||||
from mongoengine.connection import get_db, ConnectionError
|
||||
|
||||
# AWX
|
||||
from awx.main.models import * # noqa
|
||||
@ -43,6 +43,15 @@ TEST_PLAYBOOK = '''- hosts: mygroup
|
||||
command: test 1 = 1
|
||||
'''
|
||||
|
||||
class MongoDBRequired(django.test.TestCase):
|
||||
def setUp(self):
|
||||
# Drop mongo database
|
||||
try:
|
||||
self.db = get_db()
|
||||
self.db.connection.drop_database(settings.MONGO_DB)
|
||||
except ConnectionError as e:
|
||||
self.skipTest('MongoDB connection failed')
|
||||
|
||||
class QueueTestMixin(object):
|
||||
def start_queue(self):
|
||||
self.start_redis()
|
||||
@ -88,10 +97,6 @@ class BaseTestMixin(QueueTestMixin):
|
||||
def setUp(self):
|
||||
super(BaseTestMixin, self).setUp()
|
||||
|
||||
# Drop mongo database
|
||||
self.db = get_db()
|
||||
self.db.connection.drop_database(settings.MONGO_DB)
|
||||
|
||||
self.object_ctr = 0
|
||||
# Save sys.path before tests.
|
||||
self._sys_path = [x for x in sys.path]
|
||||
|
||||
@ -11,7 +11,7 @@ from copy import deepcopy
|
||||
from mock import Mock, MagicMock
|
||||
|
||||
# AWX
|
||||
from awx.main.tests.base import BaseTest
|
||||
from awx.main.tests.base import BaseTest, MongoDBRequired
|
||||
from awx.main.tests.commands.base import BaseCommandMixin
|
||||
from awx.main.management.commands.run_fact_cache_receiver import FactCacheReceiver, _MODULES
|
||||
from awx.main.models.fact import *
|
||||
@ -98,7 +98,7 @@ def copy_only_module(data, module):
|
||||
return data
|
||||
|
||||
|
||||
class RunFactCacheReceiverFunctionalTest(BaseCommandMixin, BaseTest):
|
||||
class RunFactCacheReceiverFunctionalTest(BaseCommandMixin, BaseTest, MongoDBRequired):
|
||||
@unittest.skip('''\
|
||||
TODO: run_fact_cache_receiver enters a while True loop that never exists. \
|
||||
This differs from most other commands that we test for. More logic and work \
|
||||
@ -108,7 +108,8 @@ in terms of increase coverage and confidence.''')
|
||||
result, stdout, stderr = self.run_command('run_fact_cache_receiver')
|
||||
self.assertEqual(result, None)
|
||||
|
||||
class RunFactCacheReceiverUnitTest(BaseTest):
|
||||
class RunFactCacheReceiverUnitTest(BaseTest, MongoDBRequired):
|
||||
|
||||
# TODO: Check that timestamp and other attributes are as expected
|
||||
def check_process_fact_message_module(self, data, module):
|
||||
fact_found = None
|
||||
|
||||
@ -10,12 +10,12 @@ from mongoengine import connect
|
||||
from django.conf import settings
|
||||
|
||||
# AWX
|
||||
from awx.main.tests.base import BaseTest
|
||||
from awx.main.tests.base import BaseTest, MongoDBRequired
|
||||
from awx.main.models.fact import *
|
||||
|
||||
__all__ = ['DBTransformTest']
|
||||
|
||||
class DBTransformTest(BaseTest):
|
||||
class DBTransformTest(BaseTest, MongoDBRequired):
|
||||
def setUp(self):
|
||||
super(DBTransformTest, self).setUp()
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@ from datetime import datetime
|
||||
|
||||
# AWX
|
||||
from awx.main.models.fact import *
|
||||
from awx.main.tests.base import BaseTest
|
||||
from awx.main.tests.base import BaseTest, MongoDBRequired
|
||||
|
||||
__all__ = ['FactHostTest', 'FactTest']
|
||||
|
||||
@ -49,7 +49,7 @@ TEST_FACT_DATA = {
|
||||
# Strip off microseconds because mongo has less precision
|
||||
TEST_FACT_DATA['add_fact_data']['timestamp'] = TEST_FACT_DATA['add_fact_data']['timestamp'].replace(microsecond=0)
|
||||
|
||||
class FactHostTest(BaseTest):
|
||||
class FactHostTest(BaseTest, MongoDBRequired):
|
||||
def test_create_host(self):
|
||||
host = FactHost(hostname=TEST_FACT_DATA['hostname'])
|
||||
host.save()
|
||||
@ -59,7 +59,7 @@ class FactHostTest(BaseTest):
|
||||
self.assertEqual(TEST_FACT_DATA['hostname'], host.hostname, "Gotten record hostname does not match expected hostname")
|
||||
|
||||
|
||||
class FactTest(BaseTest):
|
||||
class FactTest(BaseTest, MongoDBRequired):
|
||||
def setUp(self):
|
||||
super(FactTest, self).setUp()
|
||||
TEST_FACT_DATA['add_fact_data']['host'] = FactHost(hostname=TEST_FACT_DATA['hostname']).save()
|
||||
|
||||
@ -3,8 +3,14 @@
|
||||
|
||||
from django.conf import settings
|
||||
from mongoengine import connect
|
||||
from mongoengine.connection import get_db
|
||||
from mongoengine.connection import get_db, ConnectionError
|
||||
from awx.main.dbtransform import register_key_transform
|
||||
import logging
|
||||
|
||||
connect(settings.MONGO_DB)
|
||||
register_key_transform(get_db())
|
||||
logger = logging.getLogger('awx.settings.__init__')
|
||||
|
||||
try:
|
||||
connect(settings.MONGO_DB)
|
||||
register_key_transform(get_db())
|
||||
except ConnectionError:
|
||||
logger.warn('Failed to establish connect to MongDB "%s"' % (settings.MONGO_DB))
|
||||
|
||||
@ -42,6 +42,8 @@ if len(sys.argv) >= 2 and sys.argv[1] == 'test':
|
||||
'TEST_NAME': os.path.join(BASE_DIR, 'awx_test.sqlite3'),
|
||||
}
|
||||
}
|
||||
|
||||
MONGO_DB = 'system_tracking_test'
|
||||
|
||||
# Celery AMQP configuration.
|
||||
BROKER_URL = 'redis://localhost/'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user