robust check for HA environment setup

This commit is contained in:
Chris Meyers
2015-06-23 11:21:00 -04:00
parent 0344a801fe
commit 4669c44af9
2 changed files with 67 additions and 8 deletions

View File

@@ -13,15 +13,38 @@ from awx.main.ha import * # noqa
__all__ = ['HAUnitTest',]
TEST_LOCALHOST = {
'HOST': 'localhost'
'default': {
'HOST': 'localhost'
}
}
TEST_127_0_0_1 = {
'HOST': '127.0.0.1'
'default': {
'HOST': '127.0.0.1'
}
}
TEST_FILE = {
'HOST': '/i/might/be/a/file',
'default': {
'HOST': '/i/might/be/a/file'
}
}
TEST_DOMAIN = {
'default': {
'HOST': 'postgres.mycompany.com'
}
}
TEST_REMOTE_IP = {
'default': {
'HOST': '8.8.8.8'
}
}
TEST_EMPTY = {
'default': {
}
}
class HAUnitTest(SimpleTestCase):
@@ -44,3 +67,18 @@ class HAUnitTest(SimpleTestCase):
@mock.patch.dict('django.conf.settings.DATABASES', TEST_FILE)
def test_db_file_socket(self, ignore):
self.assertFalse(is_ha_environment())
@mock.patch('awx.main.models.Instance.objects.count', return_value=1)
@mock.patch.dict('django.conf.settings.DATABASES', TEST_DOMAIN)
def test_db_domain(self, ignore):
self.assertTrue(is_ha_environment())
@mock.patch('awx.main.models.Instance.objects.count', return_value=1)
@mock.patch.dict('django.conf.settings.DATABASES', TEST_REMOTE_IP)
def test_db_remote_ip(self, ignore):
self.assertTrue(is_ha_environment())
@mock.patch('awx.main.models.Instance.objects.count', return_value=1)
@mock.patch.dict('django.conf.settings.DATABASES', TEST_EMPTY)
def test_db_empty(self, ignore):
self.assertFalse(is_ha_environment())