Update settings template to use SQLite test database when running acom_inventory script in tests, initial stub for callback event logger.

This commit is contained in:
Chris Church
2013-04-02 14:53:52 -04:00
parent 63ef048d73
commit 0155f0acea
7 changed files with 116 additions and 25 deletions

View File

@@ -75,7 +75,10 @@ class Command(NoArgsCommand):
try:
from lib.main.models import Inventory
try:
inventory_id = int(os.getenv('ACOM_INVENTORY_ID', options.get('inventory', 0)))
# Command line argument takes precedence over environment
# variable.
inventory_id = int(options.get('inventory', 0) or \
os.getenv('ACOM_INVENTORY_ID', 0))
except ValueError:
raise CommandError('Inventory ID must be an integer')
if not inventory_id:
@@ -101,23 +104,6 @@ class Command(NoArgsCommand):
raise
if __name__ == '__main__':
# FIXME: The DJANGO_SETTINGS_MODULE environment variable *should* already
# be set if this script is called from a celery task.
settings_module_name = os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'lib.settings')
# FIXME: Not particularly fond of this sys.path hack, but it is needed
# when a celery task calls ansible-playbook and needs to execute this
# script directly.
try:
settings_parent_module = __import__(settings_module_name)
except ImportError:
top_dir = os.path.join(os.path.dirname(__file__), '..', '..', '..', '..')
sys.path.insert(0, os.path.abspath(top_dir))
settings_parent_module = __import__(settings_module_name)
settings_module = getattr(settings_parent_module, settings_module_name.split('.')[-1])
# Use the ACOM_TEST_DATABASE_NAME environment variable to specify the test
# database name when called from unit tests.
if os.environ.get('ACOM_TEST_DATABASE_NAME', None):
settings_module.DATABASES['default']['NAME'] = os.environ['ACOM_TEST_DATABASE_NAME']
from django.core.management import execute_from_command_line
argv = [sys.argv[0], 'acom_inventory'] + sys.argv[1:]
execute_from_command_line(argv)
from __init__ import run_command_as_script
command_name = os.path.splitext(os.path.basename(__file__))[0]
run_command_as_script(command_name)