conftest.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. from django.conf import settings
  2. import base64
  3. import os
  4. import os.path
  5. def pytest_configure(config):
  6. import warnings
  7. warnings.filterwarnings('error', '', Warning, r'(sentry|raven)')
  8. if not settings.configured:
  9. os.environ['DJANGO_SETTINGS_MODULE'] = 'sentry.conf.server'
  10. test_db = os.environ.get('DB', 'sqlite')
  11. if test_db == 'mysql':
  12. settings.DATABASES['default'].update({
  13. 'ENGINE': 'django.db.backends.mysql',
  14. 'NAME': 'sentry',
  15. 'USER': 'root',
  16. })
  17. elif test_db == 'postgres':
  18. settings.DATABASES['default'].update({
  19. 'ENGINE': 'django.db.backends.postgresql_psycopg2',
  20. 'USER': 'postgres',
  21. 'NAME': 'sentry',
  22. 'OPTIONS': {
  23. 'autocommit': True,
  24. }
  25. })
  26. elif test_db == 'sqlite':
  27. settings.DATABASES['default'].update({
  28. 'ENGINE': 'django.db.backends.sqlite3',
  29. 'NAME': ':memory:',
  30. })
  31. # http://djangosnippets.org/snippets/646/
  32. class InvalidVarException(object):
  33. def __mod__(self, missing):
  34. try:
  35. missing_str = unicode(missing)
  36. except:
  37. missing_str = 'Failed to create string representation'
  38. raise Exception('Unknown template variable %r %s' % (missing, missing_str))
  39. def __contains__(self, search):
  40. if search == '%s':
  41. return True
  42. return False
  43. settings.TEMPLATE_DEBUG = True
  44. # settings.TEMPLATE_STRING_IF_INVALID = InvalidVarException()
  45. # Disable static compiling in tests
  46. settings.STATIC_BUNDLES = {}
  47. # override a few things with our test specifics
  48. settings.INSTALLED_APPS = tuple(settings.INSTALLED_APPS) + (
  49. 'tests',
  50. )
  51. settings.SENTRY_KEY = base64.b64encode(os.urandom(40))
  52. settings.SENTRY_PUBLIC = False
  53. # This speeds up the tests considerably, pbkdf2 is by design, slow.
  54. settings.PASSWORD_HASHERS = [
  55. 'django.contrib.auth.hashers.MD5PasswordHasher',
  56. ]
  57. # enable draft features
  58. settings.SENTRY_ENABLE_EXPLORE_CODE = True
  59. settings.SENTRY_ENABLE_EXPLORE_USERS = True