1from __future__ import print_function 2import atexit 3import os 4import shutil 5import tempfile 6 7from django import VERSION 8from django.conf import settings, global_settings 9 10# Silence the warning about an insecure SECRET_KEY 11global_settings.SECRET_KEY = 'SUPER_SAFE_TESTING_KEY' 12 13settings.configure(default_settings=global_settings) 14from graphite.settings import * # noqa 15 16# support testing with mysql & postgres via tox 17if os.environ.get('TEST_MYSQL'): 18 DATABASES = { 19 'default': { 20 'NAME': 'graphite', 21 'ENGINE': 'django.db.backends.mysql', 22 'USER': os.environ.get('TEST_MYSQL_USER') or 'graphite', 23 'PASSWORD': os.environ.get('TEST_MYSQL_PASSWORD') or '', 24 'HOST': os.environ.get('TEST_MYSQL_HOST') or 'localhost', 25 'PORT': os.environ.get('TEST_MYSQL_PORT') or '3306', 26 'TEST': { 27 'NAME': os.environ.get('TEST_MYSQL_NAME') or 'test_graphite', 28 }, 29 }, 30 } 31elif os.environ.get('TEST_POSTGRESQL'): 32 DATABASES = { 33 'default': { 34 'NAME': 'graphite', 35 'ENGINE': 'django.db.backends.postgresql', 36 'USER': os.environ.get('TEST_POSTGRESQL_USER') or 'graphite', 37 'PASSWORD': os.environ.get('TEST_POSTGRESQL_PASSWORD') or '', 38 'HOST': os.environ.get('TEST_POSTGRESQL_HOST') or 'localhost', 39 'PORT': os.environ.get('TEST_POSTGRESQL_PORT') or '5432', 40 'TEST': { 41 'NAME': os.environ.get('TEST_POSTGRESQL_NAME') or 'test_graphite', 42 }, 43 }, 44 } 45 46if VERSION < (1, 6): 47 TEST_RUNNER = 'discover_runner.DiscoverRunner' 48 49CACHES = { 50 'default': { 51 'BACKEND': 'django.core.cache.backends.dummy.DummyCache', 52 }, 53} 54 55# Temporaray directories 56 57 58def atexit_tmpremover(dirname): 59 """ Utility to remove a temporary directory during program exit. """ 60 try: 61 shutil.rmtree(dirname) 62 print("Removed temporary directory: %s" % dirname) 63 except OSError: 64 # if the temp dir was removed already by other means 65 pass 66 67 68# create a temporary directory 69TEMP_GRAPHITE_DIR = tempfile.mkdtemp(prefix='graphite-test-') 70atexit.register(atexit_tmpremover, TEMP_GRAPHITE_DIR) 71 72LOG_DIR = os.path.join(TEMP_GRAPHITE_DIR, 'log') 73os.mkdir(LOG_DIR) 74 75WHISPER_DIR = os.path.join(TEMP_GRAPHITE_DIR, 'whisper/') 76os.mkdir(WHISPER_DIR) 77 78# Manually add WHISPER_DIR to STANDARD_DIRS 79# STANDARD_DIRS is generated programtically in settings.py, the modification of 80# WHISPER_DIR above does not change the value in STANDARD_DIRS. 81STANDARD_DIRS = [WHISPER_DIR] 82 83INDEX_FILE = os.path.join(TEMP_GRAPHITE_DIR, 'index') 84 85URL_PREFIX = '/graphite' 86