mirror of
https://github.com/ansible/awx.git
synced 2026-02-26 23:46:05 -03:30
refactor awxkit import code
* Move awxkit import code into a pytest fixture to better control when the import happens * Ensure /awx_devel/awxkit is added to sys path before awxkit import runs
This commit is contained in:
committed by
Chris Meyers
parent
6119b33a50
commit
2a6cf032f8
@@ -35,26 +35,38 @@ from awx.main.models import (
|
|||||||
|
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
|
|
||||||
try:
|
|
||||||
import tower_cli # noqa
|
|
||||||
|
|
||||||
HAS_TOWER_CLI = True
|
|
||||||
except ImportError:
|
|
||||||
HAS_TOWER_CLI = False
|
|
||||||
|
|
||||||
try:
|
|
||||||
# Because awxkit will be a directory at the root of this makefile and we are using python3, import awxkit will work even if its not installed.
|
|
||||||
# However, awxkit will not contain api whih causes a stack failure down on line 170 when we try to mock it.
|
|
||||||
# So here we are importing awxkit.api to prevent that. Then you only get an error on tests for awxkit functionality.
|
|
||||||
import awxkit.api # noqa
|
|
||||||
|
|
||||||
HAS_AWX_KIT = True
|
|
||||||
except ImportError:
|
|
||||||
HAS_AWX_KIT = False
|
|
||||||
|
|
||||||
|
HAS_TOWER_CLI = False
|
||||||
|
HAS_AWX_KIT = False
|
||||||
logger = logging.getLogger('awx.main.tests')
|
logger = logging.getLogger('awx.main.tests')
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def awxkit_path_set(monkeypatch):
|
||||||
|
"""Monkey patch sys.path, insert awxkit source code so that
|
||||||
|
the package does not need to be installed.
|
||||||
|
"""
|
||||||
|
base_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, 'awxkit'))
|
||||||
|
monkeypatch.syspath_prepend(base_folder)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def import_awxkit():
|
||||||
|
global HAS_TOWER_CLI
|
||||||
|
global HAS_AWX_KIT
|
||||||
|
try:
|
||||||
|
import tower_cli # noqa
|
||||||
|
HAS_TOWER_CLI = True
|
||||||
|
except ImportError:
|
||||||
|
HAS_TOWER_CLI = False
|
||||||
|
|
||||||
|
try:
|
||||||
|
import awxkit # noqa
|
||||||
|
HAS_AWX_KIT = True
|
||||||
|
except ImportError:
|
||||||
|
HAS_AWX_KIT = False
|
||||||
|
|
||||||
|
|
||||||
def sanitize_dict(din):
|
def sanitize_dict(din):
|
||||||
"""Sanitize Django response data to purge it of internal types
|
"""Sanitize Django response data to purge it of internal types
|
||||||
so it may be used to cast a requests response object
|
so it may be used to cast a requests response object
|
||||||
|
|||||||
Reference in New Issue
Block a user