dav_auth: small refactorings and improvements under the hood
Run tests / Execute tox to run the test suite (push) Successful in 3m38s

This commit is contained in:
2026-05-28 16:50:44 +02:00
parent d9cfffb8c2
commit 50a33a9f47
7 changed files with 102 additions and 27 deletions
+19 -1
View File
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from django.apps import apps
from django.contrib.auth import get_user_model
from django.contrib.auth.password_validation import validate_password
from django.contrib.messages import get_messages
from django.core import mail as django_mail
from django.shortcuts import resolve_url
@@ -115,7 +116,7 @@ class ViewsTestCase(TestCase):
with self.assertLogs('dav_auth.views', level='WARNING') as cm:
response = self.client.post(self.login_url, {'username': username, 'password': password})
self.assertStartsWith(cm.output[0], 'WARNING:dav_auth.views:Weak password')
self.assertStartsWith(cm.output[0], 'WARNING:dav_auth.views:Detected weak password for user id')
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, self.login_redirect_url)
@@ -248,6 +249,7 @@ class ViewsTestCase(TestCase):
location = self.recreate_password_url
response = self.client.post(location, {'username': self.user.username})
new_password = response.context['password']
messages = list(get_messages(response.wsgi_request))
self.assertEqual(len(messages), 1)
self.assertEqual(messages[0].message, self.new_password_sent_message)
@@ -259,6 +261,7 @@ class ViewsTestCase(TestCase):
recipients = mail.recipients()
self.assertIn(recipient, recipients)
self.assertEqual(len(recipients), 1)
self.assertIn(new_password, mail.body)
response = self.client.get(location)
self.assertFalse(response.context['user'].is_authenticated, 'User is logged in')
@@ -276,3 +279,18 @@ class ViewsTestCase(TestCase):
self.assertRedirects(response, self.login_url)
self.assertEqual(len(django_mail.outbox), 0)
def test_new_password_length(self):
location = self.recreate_password_url
default_password_length = 32
response = self.client.post(location, {'username': self.user.username})
new_password = response.context['password']
self.assertEqual(len(new_password), default_password_length)
def test_new_password_is_valid(self):
location = self.recreate_password_url
response = self.client.post(location, {'username': self.user.username})
new_password = response.context['password']
validate_password(new_password)