Merge pull request #13875 from john-westcott-iv/fix_assumed_databases

Fixing issue were we assumed DATABASES would be defined
This commit is contained in:
John Westcott IV 2023-04-18 14:21:17 -04:00 committed by GitHub
commit e660f62a59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,23 @@
import pytest
from awx.settings.application_name import get_service_name, set_application_name
@pytest.mark.parametrize(
'argv,result',
(
([], None),
(['-m'], None),
(['-m', 'python'], None),
(['-m', 'python', 'manage'], None),
(['-m', 'python', 'manage', 'a'], 'a'),
(['-m', 'python', 'manage', 'b', 'a'], 'b'),
(['-m', 'python', 'manage', 'run_something', 'b', 'a'], 'something'),
),
)
def test_get_service_name(argv, result):
assert get_service_name(argv) == result
@pytest.mark.parametrize('DATABASES,CLUSTER_ID,function', (({}, 12, ''), ({'default': {'ENGINE': 'sqllite3'}}, 12, '')))
def test_set_application_name(DATABASES, CLUSTER_ID, function):
set_application_name(DATABASES, CLUSTER_ID, function)

View File

@ -25,6 +25,10 @@ def get_application_name(CLUSTER_HOST_ID, function=''):
def set_application_name(DATABASES, CLUSTER_HOST_ID, function=''):
# If settings files were not properly passed DATABASES could be {} at which point we don't need to set the app name.
if not DATABASES or 'default' not in DATABASES:
return
if 'sqlite3' in DATABASES['default']['ENGINE']:
return
options_dict = DATABASES['default'].setdefault('OPTIONS', dict())