132 lines
5.0 KiB
Python
132 lines
5.0 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
Test script for language switcher functionality
|
|
"""
|
|
import os
|
|
import sys
|
|
import django
|
|
|
|
# Setup Django
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.base')
|
|
sys.path.insert(0, os.path.dirname(__file__))
|
|
django.setup()
|
|
|
|
from django.test import Client
|
|
from django.urls import reverse
|
|
|
|
def test_language_switcher():
|
|
"""Test language switching on public pages"""
|
|
print("=" * 60)
|
|
print("Testing Language Switcher Functionality")
|
|
print("=" * 60)
|
|
|
|
from django.conf import settings
|
|
# Add testserver to ALLOWED_HOSTS for testing
|
|
original_allowed_hosts = settings.ALLOWED_HOSTS
|
|
if 'testserver' not in settings.ALLOWED_HOSTS:
|
|
settings.ALLOWED_HOSTS.append('testserver')
|
|
|
|
client = Client()
|
|
|
|
# Test 1: Access public submit landing page
|
|
print("\n1. Testing public submit landing page...")
|
|
response = client.get('/core/public/submit/')
|
|
print(f" Status Code: {response.status_code}")
|
|
assert response.status_code == 200, "Failed to load public submit page"
|
|
print(" ✓ Public submit page loads successfully")
|
|
|
|
# Test 2: Check if language switcher is present in the response
|
|
print("\n2. Checking for language switcher in page...")
|
|
content = response.content.decode('utf-8')
|
|
|
|
# Check for language buttons
|
|
has_en_button = 'lang-btn' in content
|
|
has_language_url = 'set-language' in content
|
|
has_flag_icons = '🇬🇧' in content or '🇸🇦' in content
|
|
|
|
print(f" Language buttons present: {has_en_button}")
|
|
print(f" Set language URL present: {has_language_url}")
|
|
print(f" Flag icons present: {has_flag_icons}")
|
|
|
|
if has_en_button and has_language_url:
|
|
print(" ✓ Language switcher UI is present")
|
|
else:
|
|
print(" ✗ Language switcher UI not fully present")
|
|
|
|
# Test 3: Test language switching to Arabic
|
|
print("\n3. Testing language switch to Arabic...")
|
|
response = client.get('/core/set-language/?language=ar')
|
|
|
|
# Check redirect
|
|
print(f" Status Code: {response.status_code}")
|
|
if response.status_code == 302:
|
|
print(" ✓ Redirect occurred as expected")
|
|
|
|
# Test 4: Test language switching to English
|
|
print("\n4. Testing language switch to English...")
|
|
response = client.get('/core/set-language/?language=en')
|
|
|
|
print(f" Status Code: {response.status_code}")
|
|
if response.status_code == 302:
|
|
print(" ✓ Redirect occurred as expected")
|
|
|
|
# Test 5: Test public complaint form
|
|
print("\n5. Testing public complaint form page...")
|
|
response = client.get('/complaints/public/submit/')
|
|
print(f" Status Code: {response.status_code}")
|
|
assert response.status_code == 200, "Failed to load complaint form"
|
|
print(" ✓ Public complaint form loads successfully")
|
|
|
|
# Test 6: Check complaint form has language switcher
|
|
print("\n6. Checking for language switcher in complaint form...")
|
|
content = response.content.decode('utf-8')
|
|
has_lang_switcher = 'lang-switcher' in content
|
|
print(f" Language switcher present: {has_lang_switcher}")
|
|
if has_lang_switcher:
|
|
print(" ✓ Complaint form has language switcher")
|
|
|
|
# Test 7: Verify RTL/LTR attributes
|
|
print("\n7. Checking for RTL/LTR support...")
|
|
has_lang_attr = 'lang="' in content or 'html lang=' in content
|
|
has_dir_attr = 'dir="' in content or 'dir=' in content
|
|
has_rtl_support = 'dir="rtl"' in content or 'dir="ltr"' in content
|
|
|
|
print(f" Language attribute present: {has_lang_attr}")
|
|
print(f" Direction attribute present: {has_dir_attr}")
|
|
print(f" RTL/LTR support detected: {has_rtl_support}")
|
|
|
|
if has_rtl_support:
|
|
print(" ✓ RTL/LTR dynamic switching is implemented")
|
|
|
|
# Test 8: Check for CSS styling
|
|
print("\n8. Checking for CSS styling...")
|
|
has_css_styles = '.lang-btn' in content or '.lang-switcher' in content
|
|
print(f" Language switcher CSS present: {has_css_styles}")
|
|
if has_css_styles:
|
|
print(" ✓ CSS styling for language switcher is present")
|
|
|
|
print("\n" + "=" * 60)
|
|
print("Test Summary")
|
|
print("=" * 60)
|
|
print("✓ All basic functionality tests passed!")
|
|
print("\nLanguage switcher features:")
|
|
print(" • Language buttons with flags (EN/AR)")
|
|
print(" • Language switching URL endpoint")
|
|
print(" • Dynamic RTL/LTR switching")
|
|
print(" • CSS styling for switcher")
|
|
print(" • Present in public pages")
|
|
print("\nTo test interactively:")
|
|
print(" 1. Start the development server: python manage.py runserver")
|
|
print(" 2. Visit: http://localhost:8000/core/public/submit/")
|
|
print(" 3. Click on English or Arabic flag to switch languages")
|
|
print(" 4. Observe page reloads in the selected language")
|
|
print("=" * 60)
|
|
|
|
if __name__ == '__main__':
|
|
try:
|
|
test_language_switcher()
|
|
except Exception as e:
|
|
print(f"\n✗ Error during testing: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
sys.exit(1) |