Spaces:
Sleeping
Sleeping
File size: 2,798 Bytes
e993e6d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
#!/usr/bin/env python3
"""
Test script to verify directory permissions are set correctly in app.py
"""
import os
import sys
from pathlib import Path
def test_directory_permissions():
"""Test that directories are created with correct permissions"""
print("π§ͺ Testing Directory Permission Setup in app.py")
print("=" * 50)
# Change to cache directory where the modified app.py is located
cache_dir = Path(".cache")
if not cache_dir.exists():
print("β .cache directory not found. Run 'python app.py' first.")
return False
# Import and test the function from the modified app in .cache
sys.path.insert(0, str(cache_dir.absolute()))
try:
import app
from app import create_directory_with_permissions
print("β
Successfully imported create_directory_with_permissions function")
except ImportError as e:
print(f"β Failed to import function: {e}")
return False
# Change to cache directory for testing
original_dir = Path.cwd()
os.chdir(cache_dir)
# Test directories
test_dirs = ["Generated", "static", "view_session", "test_session_123"]
print("\nπ Testing directory creation and permissions:")
print("-" * 40)
for dir_name in test_dirs:
try:
# Remove directory if it exists (for clean test)
if Path(dir_name).exists():
import shutil
shutil.rmtree(dir_name)
# Create directory using our function
create_directory_with_permissions(dir_name)
# Check if directory exists
if Path(dir_name).exists():
# Check permissions
stat_info = Path(dir_name).stat()
permissions = oct(stat_info.st_mode)[-3:]
expected_perm = "755"
if permissions == expected_perm:
print(f"β
{dir_name:15} - Created with correct permissions ({permissions})")
else:
print(f"β οΈ {dir_name:15} - Created with permissions ({permissions}), expected ({expected_perm})")
else:
print(f"β {dir_name:15} - Failed to create")
except Exception as e:
print(f"β {dir_name:15} - Error: {e}")
print("\n" + "=" * 50)
print("β
Permission test completed!")
print("π‘ The app.py now automatically sets correct permissions for:")
print(" - Generated/ (and all session subfolders)")
print(" - static/")
print(" - view_session/")
# Return to original directory
os.chdir(original_dir)
return True
if __name__ == "__main__":
test_directory_permissions() |