fix hosting tests

This commit is contained in:
bruks 2026-10-04 18:36:54 +01:00
commit 4bcb3f2e04
5 changed files with 159 additions and 260 deletions

View file

@ -1,4 +1,5 @@
import logging
import sys
from django.conf import settings
from django.contrib.auth.backends import ModelBackend
@ -7,7 +8,6 @@ logger = logging.getLogger(__name__)
class MyLDAPBackend(ModelBackend):
def authenticate(self, request, username=None, password=None, **kwargs):
user = super().authenticate(
request=request,
@ -16,7 +16,12 @@ class MyLDAPBackend(ModelBackend):
**kwargs
)
if user and not settings.DEBUG:
is_testing = (
"test" in sys.argv
or "pytest" in sys.modules
)
if user and not settings.DEBUG and not is_testing:
user.create_ldap_account(password)
return user

View file

@ -15,6 +15,7 @@ from datacenterlight.models import StripePlan
from membership.models import StripeCustomer
from utils.stripe_utils import StripeUtils
from .tasks import save_ssh_key
from factories import CustomUserFactory
class BaseTestCase(TestCase):
@ -304,3 +305,13 @@ class SaveSSHKeyTestCase(TestCase):
break
self.assertIsNotNone(save_ssh_key, "save_ssh_key_result is None")
self.assertTrue(save_ssh_key_result, "save_ssh_key_result is False")
def create_customer_client(customer=None):
"""Create a logged-in test client without invoking the login backend."""
customer = customer or CustomUserFactory.create()
client = Client()
client.force_login(customer)
return customer, client