mirror of
https://github.com/pretix/pretix.git
synced 2026-08-08 10:27:49 +00:00
Refactored test utilities
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import atexit
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
from pretix.settings import * # NOQA
|
||||
|
||||
tmpdir = tempfile.TemporaryDirectory()
|
||||
DATA_DIR = tmpdir.name
|
||||
LOG_DIR = os.path.join(DATA_DIR, 'logs')
|
||||
MEDIA_ROOT = os.path.join(DATA_DIR, 'media')
|
||||
|
||||
atexit.register(tmpdir.cleanup)
|
||||
|
||||
EMAIL_BACKEND = 'django.core.mail.outbox'
|
||||
|
||||
COMPRESS_ENABLED = COMPRESS_OFFLINE = False
|
||||
|
||||
PASSWORD_HASHERS = ['django.contrib.auth.hashers.MD5PasswordHasher']
|
||||
|
||||
# Disable celery
|
||||
CELERY_ALWAYS_EAGER = True
|
||||
HAS_CELERY = False
|
||||
|
||||
# Don't use redis
|
||||
SESSION_ENGINE = "django.contrib.sessions.backends.db"
|
||||
HAS_REDIS = False
|
||||
CACHES = {
|
||||
'default': {
|
||||
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
|
||||
'LOCATION': 'unique-snowflake',
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,2 @@
|
||||
[pytest]
|
||||
DJANGO_SETTINGS_MODULE=tests.settings
|
||||
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
[flake8]
|
||||
ignore = N802,W503,E402
|
||||
max-line-length = 160
|
||||
exclude = migrations,.ropeproject,static,mt940.py,_static,build,make_testdata.py,tests/settings.py,pretix/base/models/__init__.py
|
||||
exclude = migrations,.ropeproject,static,mt940.py,_static,build,make_testdata.py,*/testutils/settings.py,tests/settings.py,pretix/base/models/__init__.py
|
||||
max-complexity = 11
|
||||
|
||||
[isort]
|
||||
|
||||
@@ -2,6 +2,7 @@ from datetime import date, datetime, time
|
||||
from decimal import Decimal
|
||||
|
||||
from django.core.files import File
|
||||
from django.core.files.storage import default_storage
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
from django.test import TestCase
|
||||
from django.utils.timezone import now
|
||||
@@ -161,6 +162,7 @@ class SettingsTestCase(TestCase):
|
||||
|
||||
def test_serialize_file(self):
|
||||
val = SimpleUploadedFile("sample_invalid_image.jpg", b"file_content", content_type="image/jpeg")
|
||||
default_storage.save(val.name, val)
|
||||
self.event.settings.set('test', val)
|
||||
self.event.settings._flush()
|
||||
self.assertIsInstance(self.event.settings.get('test', as_type=File), File)
|
||||
@@ -168,6 +170,7 @@ class SettingsTestCase(TestCase):
|
||||
|
||||
def test_detect_file_value(self):
|
||||
val = SimpleUploadedFile("sample_invalid_image.jpg", b"file_content", content_type="image/jpeg")
|
||||
default_storage.save(val.name, val)
|
||||
self.event.settings.set('test', val)
|
||||
self.event.settings._flush()
|
||||
self.assertIsInstance(self.event.settings.get('test'), File)
|
||||
|
||||
+1
-23
@@ -1,31 +1,9 @@
|
||||
import os
|
||||
from pretix.testutils.settings import * # NOQA
|
||||
|
||||
from pretix.settings import * # NOQA
|
||||
|
||||
TEST_DIR = os.path.dirname(__file__)
|
||||
|
||||
TEMPLATES[0]['DIRS'].append(os.path.join(TEST_DIR, 'templates')) # NOQA
|
||||
|
||||
INSTALLED_APPS.append('tests.testdummy') # NOQA
|
||||
|
||||
MEDIA_ROOT = os.path.join(TEST_DIR, 'media')
|
||||
|
||||
EMAIL_BACKEND = 'django.core.mail.outbox'
|
||||
|
||||
COMPRESS_ENABLED = COMPRESS_OFFLINE = False
|
||||
|
||||
PASSWORD_HASHERS = ['django.contrib.auth.hashers.MD5PasswordHasher']
|
||||
|
||||
# Disable celery
|
||||
CELERY_ALWAYS_EAGER = True
|
||||
HAS_CELERY = False
|
||||
|
||||
# Don't use redis
|
||||
SESSION_ENGINE = "django.contrib.sessions.backends.db"
|
||||
HAS_REDIS = False
|
||||
CACHES = {
|
||||
'default': {
|
||||
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
|
||||
'LOCATION': 'unique-snowflake',
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user