test: modify for axes

See jazzband/django-axes#998
This commit is contained in:
Ethan Nguyen 2023-04-12 22:31:17 -05:00
parent 22ac5bc4ba
commit a255234173
No known key found for this signature in database
GPG Key ID: B4CA5339AF911920
2 changed files with 12 additions and 1 deletions

View File

@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/3.2/ref/settings/
"""
import logging
import os
import sys
from pathlib import Path
from typing import List, Optional
@ -46,6 +47,7 @@ INSTALLED_APPS = [
"social_django",
"django_extensions",
"bootstrap_pagination",
"axes",
"tjdests.apps.authentication",
"tjdests.apps.destinations",
"tjdests.apps.profile",
@ -60,6 +62,7 @@ MIDDLEWARE = [
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"axes.middleware.AxesMiddleware",
]
ROOT_URLCONF = "tjdests.urls"
@ -116,6 +119,7 @@ AUTH_PASSWORD_VALIDATORS = [
AUTH_USER_MODEL = "authentication.User"
AUTHENTICATION_BACKENDS = (
"axes.backends.AxesStandaloneBackend",
"tjdests.apps.authentication.oauth.IonOauth2",
"django.contrib.auth.backends.ModelBackend",
)
@ -163,6 +167,10 @@ MESSAGE_TAGS = {
messages.ERROR: "danger",
}
TESTING = any("test" in arg for arg in sys.argv)
if TESTING:
AXES_ENABLED = False
# Override the following in secret.py
SENIOR_GRAD_YEAR: int = -1
BRANDING_NAME: str = "UNDEFINED"

View File

@ -1,3 +1,4 @@
from django.http import HttpRequest
from django.test import TestCase
from tjdests.apps.authentication.models import User
@ -40,5 +41,7 @@ class TJDestsTestCase(TestCase):
"publish_data": publish_data,
},
)[0]
self.client.force_login(user)
user.set_password("hello123")
user.save()
self.client.login(username=username, password="hello123", request=HttpRequest())
return user