mirror of
https://git.linux-kernel.at/oliver/ivatar.git
synced 2025-11-20 23:18:03 +00:00
Conditional django setup for local testing vs. remote testing
This commit is contained in:
@@ -16,15 +16,14 @@ import hashlib
|
||||
# Add project root to path
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
# Django setup
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ivatar.settings")
|
||||
import django
|
||||
|
||||
django.setup()
|
||||
# Django setup - only for local testing
|
||||
def setup_django():
|
||||
"""Setup Django for local testing"""
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ivatar.settings")
|
||||
import django
|
||||
|
||||
from django.test import Client
|
||||
from django.contrib.auth.models import User
|
||||
from ivatar.ivataraccount.models import ConfirmedEmail, Photo
|
||||
django.setup()
|
||||
|
||||
|
||||
class PerformanceTestRunner:
|
||||
@@ -41,7 +40,7 @@ class PerformanceTestRunner:
|
||||
self.concurrent_users = concurrent_users
|
||||
self.test_cache = test_cache
|
||||
self.remote_testing = remote_testing
|
||||
self.client = Client() if not remote_testing else None
|
||||
self.client = None
|
||||
self.results = {}
|
||||
|
||||
# Determine if we're testing locally or remotely
|
||||
@@ -50,11 +49,20 @@ class PerformanceTestRunner:
|
||||
print(f"🌐 Remote testing mode: {base_url}")
|
||||
else:
|
||||
print(f"🏠 Local testing mode: {base_url}")
|
||||
# Only setup Django and create client for local testing
|
||||
setup_django()
|
||||
from django.test import Client
|
||||
|
||||
self.client = Client()
|
||||
|
||||
def setup_test_data(self):
|
||||
"""Create test data for performance tests"""
|
||||
print("Setting up test data...")
|
||||
|
||||
# Import Django models only when needed
|
||||
from django.contrib.auth.models import User
|
||||
from ivatar.ivataraccount.models import ConfirmedEmail
|
||||
|
||||
# Create test users and emails
|
||||
test_emails = [f"perftest{i}@example.com" for i in range(100)]
|
||||
|
||||
@@ -326,6 +334,8 @@ class PerformanceTestRunner:
|
||||
print("\n=== Database Performance Test ===")
|
||||
|
||||
from django.db import connection
|
||||
from django.contrib.auth.models import User
|
||||
from ivatar.ivataraccount.models import ConfirmedEmail, Photo
|
||||
|
||||
# Reset query log
|
||||
connection.queries_log.clear()
|
||||
|
||||
Reference in New Issue
Block a user