First test!
This commit is contained in:
parent
111bdfef7b
commit
4fa042079f
4 changed files with 64 additions and 0 deletions
0
authens/tests/__init__.py
Normal file
0
authens/tests/__init__.py
Normal file
25
authens/tests/test_backend.py
Normal file
25
authens/tests/test_backend.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
from authens.backends import ENSCASBackend
|
||||||
|
|
||||||
|
UserModel = get_user_model()
|
||||||
|
|
||||||
|
|
||||||
|
class TestBackend(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
UserModel.objects.create(username="toto")
|
||||||
|
UserModel.objects.create(username="toto2")
|
||||||
|
|
||||||
|
def test_usernames_uniqueness(self):
|
||||||
|
backend = ENSCASBackend()
|
||||||
|
for _ in range(10):
|
||||||
|
username = backend.find_available_username("toto")
|
||||||
|
self.assertFalse(UserModel.objects.filter(username=username).exists())
|
||||||
|
UserModel.objects.create(username=username)
|
||||||
|
for _ in range(10):
|
||||||
|
username = backend.find_available_username("tutu")
|
||||||
|
self.assertFalse(UserModel.objects.filter(username=username).exists())
|
||||||
|
UserModel.objects.create(username=username)
|
||||||
|
|
||||||
|
# TODO: https://git.eleves.ens.fr/klub-dev-ens/authens/issues/4
|
17
runtests.py
Normal file
17
runtests.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
# Source:
|
||||||
|
# https://docs.djangoproject.com/en/3.0/topics/testing/advanced/#using-the-django-test-runner-to-test-reusable-applications
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import django
|
||||||
|
from django.conf import settings
|
||||||
|
from django.test.utils import get_runner
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
|
||||||
|
django.setup()
|
||||||
|
TestRunner = get_runner(settings)
|
||||||
|
test_runner = TestRunner()
|
||||||
|
failures = test_runner.run_tests(sys.argv[1:])
|
||||||
|
sys.exit(bool(failures))
|
22
tests/settings.py
Normal file
22
tests/settings.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
from django.urls import reverse_lazy # noqa
|
||||||
|
|
||||||
|
# Minimal settings to run a django app using authens.
|
||||||
|
|
||||||
|
|
||||||
|
SECRET_KEY = "dummy"
|
||||||
|
|
||||||
|
INSTALLED_APPS = [
|
||||||
|
"django.contrib.contenttypes",
|
||||||
|
"django.contrib.auth",
|
||||||
|
"authens",
|
||||||
|
"tests",
|
||||||
|
]
|
||||||
|
|
||||||
|
AUTHENTICATION_BACKENDS = [
|
||||||
|
"django.contrib.auth.backends.ModelBackend",
|
||||||
|
"authens.backends.ENSCASBackend",
|
||||||
|
]
|
||||||
|
|
||||||
|
DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3"}}
|
||||||
|
|
||||||
|
LOGIN_URL = reverse_lazy("authens:login")
|
Loading…
Reference in a new issue