83 lines
2.6 KiB
Python
83 lines
2.6 KiB
Python
"""
|
|
Test script to upload a dummy file to S3 bucket
|
|
"""
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
|
|
from src.database.session import db_manager
|
|
from src.database.repositories import SiteDeploymentRepository
|
|
from src.deployment.storage_factory import create_storage_client
|
|
|
|
def test_upload():
|
|
"""Upload a test file to airconditionerfixer.com"""
|
|
print("Testing S3 upload to airconditionerfixer.com...")
|
|
|
|
db_manager.initialize()
|
|
session = db_manager.get_session()
|
|
site_repo = SiteDeploymentRepository(session)
|
|
|
|
try:
|
|
# Get the site
|
|
site = site_repo.get_by_hostname("airconditionerfixer.com")
|
|
if not site:
|
|
print("ERROR: Site 'airconditionerfixer.com' not found")
|
|
return
|
|
|
|
print(f"\nSite found:")
|
|
print(f" ID: {site.id}")
|
|
print(f" Name: {site.site_name}")
|
|
print(f" Storage Provider: {site.storage_provider}")
|
|
print(f" S3 Bucket: {site.s3_bucket_name}")
|
|
print(f" S3 Region: {site.s3_bucket_region}")
|
|
print(f" Custom Domain: {site.s3_custom_domain}")
|
|
|
|
if site.storage_provider != 's3':
|
|
print(f"\nERROR: Site is not an S3 site (storage_provider={site.storage_provider})")
|
|
return
|
|
|
|
# Create storage client
|
|
client = create_storage_client(site)
|
|
print(f"\nStorage client created: {type(client).__name__}")
|
|
|
|
# Test content
|
|
test_content = "This is a test file uploaded to verify S3 bucket configuration and permissions."
|
|
test_file_path = "test-upload.txt"
|
|
|
|
print(f"\nUploading test file: {test_file_path}")
|
|
print(f"Content: {test_content[:50]}...")
|
|
|
|
# Upload
|
|
result = client.upload_file(
|
|
site=site,
|
|
file_path=test_file_path,
|
|
content=test_content
|
|
)
|
|
|
|
print(f"\nUpload Result:")
|
|
print(f" Success: {result.success}")
|
|
print(f" File Path: {result.file_path}")
|
|
print(f" Message: {result.message}")
|
|
|
|
if result.success:
|
|
# Generate URL
|
|
from src.generation.url_generator import generate_public_url
|
|
url = generate_public_url(site, test_file_path)
|
|
print(f"\nPublic URL: {url}")
|
|
print(f"\nTest file should be accessible at: {url}")
|
|
else:
|
|
print(f"\nERROR: Upload failed - {result.message}")
|
|
|
|
except Exception as e:
|
|
print(f"\nERROR: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
finally:
|
|
session.close()
|
|
|
|
if __name__ == "__main__":
|
|
test_upload()
|
|
|