-
Notifications
You must be signed in to change notification settings - Fork 60
/
testing_settings.py
47 lines (30 loc) · 1.47 KB
/
testing_settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from django.contrib.auth.hashers import BasePasswordHasher
from .settings import * # noqa
# An in-memory database should be good enough for now.
DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}}
# Migrations are slow to run for tests. Disable them.
class DisableMigrations(object):
def __contains__(self, item):
return True
def __getitem__(self, item):
return None
MIGRATION_MODULES = DisableMigrations()
# The password hasher is deliberately slow on the real site. Use a dumb and fast one.
class SimplePasswordHasher(BasePasswordHasher):
"""A simple hasher inspired by django-plainpasswordhasher"""
algorithm = "dumb" # This attribute is needed by the base class.
def salt(self):
return ""
def encode(self, password, salt):
return "dumb$$%s" % password
def verify(self, password, encoded):
algorithm, hash = encoded.split("$$", 1)
assert algorithm == "dumb"
return password == hash
def safe_summary(self, encoded):
"""This is a decidedly unsafe version. The password is returned in the clear."""
return {"algorithm": "dumb", "hash": encoded.split("$", 2)[2]}
PASSWORD_HASHERS = ("project.testing_settings.SimplePasswordHasher",)
# Whitenoise does not play well with tz_detect because tests don't run collectstatic.
# Override back to the default storage for testing.
STATICFILES_STORAGE = "django.contrib.staticfiles.storage.StaticFilesStorage"