You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

config.py 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/usr/bin/env python
  2. import os
  3. import django
  4. from django.conf import settings, global_settings
  5. import oscar
  6. def configure():
  7. if not settings.configured:
  8. from oscar.defaults import OSCAR_SETTINGS
  9. # Helper function to extract absolute path
  10. location = lambda x: os.path.join(
  11. os.path.dirname(os.path.realpath(__file__)), x)
  12. test_settings = OSCAR_SETTINGS.copy()
  13. test_settings.update({
  14. 'DATABASES': {
  15. 'default': {
  16. 'ENGINE': 'django.db.backends.sqlite3',
  17. 'NAME': ':memory:',
  18. },
  19. },
  20. 'INSTALLED_APPS': [
  21. 'django.contrib.auth',
  22. 'django.contrib.admin',
  23. 'django.contrib.contenttypes',
  24. 'django.contrib.sessions',
  25. 'django.contrib.sites',
  26. 'django.contrib.flatpages',
  27. 'django.contrib.staticfiles',
  28. 'compressor',
  29. 'tests._site.model_tests_app', # contains models we need for testing
  30. 'tests._site.myauth',
  31. # Use a custom partner app to test overriding models. I can't
  32. # find a way of doing this on a per-test basis, so I'm using a
  33. # global change.
  34. ] + oscar.get_core_apps([
  35. 'tests._site.apps.partner',
  36. 'tests._site.apps.customer']),
  37. 'AUTH_USER_MODEL': 'myauth.User',
  38. 'TEMPLATE_CONTEXT_PROCESSORS': (
  39. "django.contrib.auth.context_processors.auth",
  40. "django.core.context_processors.request",
  41. "django.core.context_processors.debug",
  42. "django.core.context_processors.i18n",
  43. "django.core.context_processors.media",
  44. "django.core.context_processors.static",
  45. "django.contrib.messages.context_processors.messages",
  46. 'oscar.apps.search.context_processors.search_form',
  47. 'oscar.apps.customer.notifications.context_processors.notifications',
  48. 'oscar.apps.promotions.context_processors.promotions',
  49. 'oscar.apps.checkout.context_processors.checkout',
  50. 'oscar.core.context_processors.metadata',
  51. ),
  52. 'TEMPLATE_DIRS': (
  53. location('templates'),
  54. oscar.OSCAR_MAIN_TEMPLATE_DIR,
  55. ),
  56. 'TEMPLATE_LOADERS': (
  57. ('django.template.loaders.cached.Loader',
  58. ['django.template.loaders.filesystem.Loader',
  59. 'django.template.loaders.app_directories.Loader',
  60. 'django.template.loaders.eggs.Loader']),),
  61. 'MIDDLEWARE_CLASSES': (
  62. 'django.middleware.common.CommonMiddleware',
  63. 'django.contrib.sessions.middleware.SessionMiddleware',
  64. 'django.middleware.csrf.CsrfViewMiddleware',
  65. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  66. 'django.contrib.messages.middleware.MessageMiddleware',
  67. 'oscar.apps.basket.middleware.BasketMiddleware',
  68. ),
  69. 'AUTHENTICATION_BACKENDS': (
  70. 'oscar.apps.customer.auth_backends.EmailBackend',
  71. 'django.contrib.auth.backends.ModelBackend',
  72. ),
  73. 'HAYSTACK_CONNECTIONS': {
  74. 'default': {
  75. 'ENGINE': 'haystack.backends.simple_backend.SimpleEngine',
  76. }
  77. },
  78. 'PASSWORD_HASHERS': ['django.contrib.auth.hashers.MD5PasswordHasher'],
  79. 'ROOT_URLCONF': 'tests._site.urls',
  80. 'LOGIN_REDIRECT_URL': '/accounts/',
  81. 'STATIC_URL': '/static/',
  82. 'COMPRESS_ENABLED': False,
  83. 'COMPRESS_ROOT': '', # needed to avoid issue #1214
  84. 'DEBUG': False,
  85. 'SITE_ID': 1,
  86. 'USE_TZ': 1,
  87. 'APPEND_SLASH': True,
  88. 'DDF_DEFAULT_DATA_FIXTURE': 'tests.dynamic_fixtures.OscarDynamicDataFixtureClass',
  89. 'SESSION_SERIALIZER': 'django.contrib.sessions.serializers.JSONSerializer',
  90. # temporary workaround for issue in sorl-thumbnail in Python 3
  91. # https://github.com/mariocesar/sorl-thumbnail/pull/254
  92. 'THUMBNAIL_DEBUG': False,
  93. 'OSCAR_INITIAL_ORDER_STATUS': 'A',
  94. 'OSCAR_ORDER_STATUS_PIPELINE': {'A': ('B',), 'B': ()},
  95. 'OSCAR_INITIAL_LINE_STATUS': 'a',
  96. 'OSCAR_LINE_STATUS_PIPELINE': {'a': ('b', ), 'b': ()},
  97. # Setting this explicitly prevents Django 1.7+ from showing a
  98. # warning regarding a changed default test runner. The Oscar test
  99. # suite is run with nose, so it does not matter.
  100. 'SILENCED_SYSTEM_CHECKS': ['1_6.W001'],
  101. })
  102. settings.configure(**test_settings)
  103. # It can sometimes be useful to be able to drop into the configured Django
  104. # environment of the test suite. It might e.g. be useful to drop into the
  105. # shell with ./config.py shell_plus or create missing migrations with
  106. # ./config.py makemigrations
  107. if __name__ == '__main__':
  108. import sys
  109. from django.core.management import call_command
  110. args = sys.argv[1:]
  111. if args:
  112. configure() # configure Django settings
  113. if hasattr(django, 'setup'):
  114. django.setup() # initialise app registry for Django 1.7+
  115. call_command(*args)