conftest.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from django.conf import settings
  2. import base64
  3. import os
  4. import os.path
  5. def pytest_configure(config):
  6. if not settings.configured:
  7. os.environ['DJANGO_SETTINGS_MODULE'] = 'sentry.conf.server'
  8. test_db = os.environ.get('DB', 'sqlite')
  9. if test_db == 'mysql':
  10. settings.DATABASES['default'].update({
  11. 'ENGINE': 'django.db.backends.mysql',
  12. 'NAME': 'sentry',
  13. 'USER': 'root',
  14. })
  15. elif test_db == 'postgres':
  16. settings.DATABASES['default'].update({
  17. 'ENGINE': 'django.db.backends.postgresql_psycopg2',
  18. 'USER': 'postgres',
  19. 'NAME': 'sentry',
  20. 'OPTIONS': {
  21. 'autocommit': True,
  22. }
  23. })
  24. elif test_db == 'sqlite':
  25. settings.DATABASES['default'].update({
  26. 'ENGINE': 'django.db.backends.sqlite3',
  27. 'NAME': ':memory:',
  28. })
  29. # Compressors is not fast, disable it in tests.
  30. settings.COMPRESS_ENABLED = False
  31. # override a few things with our test specifics
  32. settings.INSTALLED_APPS = tuple(settings.INSTALLED_APPS) + (
  33. 'tests',
  34. )
  35. settings.SENTRY_KEY = base64.b64encode(os.urandom(40))
  36. settings.SENTRY_PUBLIC = False
  37. # This speeds up the tests considerably, pbkdf2 is by design, slow.
  38. settings.PASSWORD_HASHERS = [
  39. 'django.contrib.auth.hashers.MD5PasswordHasher',
  40. ]