from userausfall.models import User class UserMixin: user: User password: str username: str def create_user(self): self.username = f"test{User.objects.count()}" self.password = "test12345" self.user = User.objects.create_user(self.username, self.password) return self.user def ensure_user_exists(self): if not hasattr(self, "user"): self.create_user() def authenticate_user(self): self.ensure_user_exists() if hasattr(self.client, "force_authentication"): self.client.force_authenticate(user=self.user) else: self.client.force_login(user=self.user)