Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Use dummy password hasher in tests

Maciej Korycinski61cc7d787409
diff --git a/tests/dummy_password_hasher.py b/tests/dummy_password_hasher.py
new file mode 100644
index 0000000000..98cdd20c01
--- /dev/null
+++ b/tests/dummy_password_hasher.py
@@ -0,0 +1,29 @@
+from collections import OrderedDict
+
+from django.contrib.auth.hashers import BasePasswordHasher
+
+
+class DummyHasher(BasePasswordHasher):
+ """Dummy password hasher used only for unit tests purpose. Overwriting
+ default Django password hasher significantly reduces the time of tests
+ execution."""
+
+ algorithm = "dummy"
+
+ def encode(self, password, *args):
+ assert password is not None
+ return "%s$%s" % (self.algorithm, password)
+
+ def verify(self, password, encoded):
+ algorithm, dummy_password = encoded.split('$')
+ assert algorithm == self.algorithm
+ return password == dummy_password
+
+ def safe_summary(self, encoded):
+ algorithm, dummy_password = encoded.split('$')
+ return OrderedDict([
+ (_('algorithm'), algorithm),
+ (_('hash'), dummy_password)])
+
+ def harden_runtime(self, password, encoded):
+ pass
diff --git a/tests/settings.py b/tests/settings.py
index 4d67c8e29b..31276e72d0 100644
--- a/tests/settings.py
+++ b/tests/settings.py
@@ -35,3 +35,8 @@ COUNTRIES_ONLY = None
MEDIA_ROOT = None
MAX_CHECKOUT_LINE_QUANTITY = 50
+
+
+PASSWORD_HASHERS = [
+ 'tests.dummy_password_hasher.DummyHasher',
+]