File size: 6,324 Bytes
32e4bbf |
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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
#!/usr/bin/env python3
"""
Test script for Cloudflare Manager
Tests all major functionality without making actual API calls
"""
import os
import sys
from pathlib import Path
def test_imports():
"""Test that all imports work"""
print("Testing imports...")
try:
from cloudflare_manager import (
CloudflareAccount,
CloudflareManager,
MultiAccountManager
)
print("β All imports successful")
return True
except ImportError as e:
print(f"β Import failed: {e}")
return False
def test_account_creation():
"""Test account creation"""
print("\nTesting account creation...")
try:
from cloudflare_manager import CloudflareAccount
account = CloudflareAccount(
email="test@example.com",
token="test-token",
account_id="test-account-id"
)
assert account.email == "test@example.com"
assert account.token == "test-token"
assert account.account_id == "test-account-id"
print("β Account creation successful")
return True
except Exception as e:
print(f"β Account creation failed: {e}")
return False
def test_multi_account_manager():
"""Test multi-account manager"""
print("\nTesting multi-account manager...")
try:
from cloudflare_manager import MultiAccountManager
manager = MultiAccountManager()
# Test adding accounts
accounts_data = [
("account1", "user1@example.com", "token1"),
("account2", "user2@example.com", "token2"),
]
for name, email, token in accounts_data:
# Note: This will fail without valid credentials, but tests the structure
try:
manager.add_account(name, email, token)
except:
pass # Expected to fail with invalid credentials
print("β Multi-account manager structure validated")
return True
except Exception as e:
print(f"β Multi-account manager failed: {e}")
return False
def test_file_structure():
"""Test that all required files exist"""
print("\nTesting file structure...")
required_files = [
"cloudflare_manager.py",
"README.md",
"requirements.txt",
"example_usage.py",
"quickstart.py",
"index.html"
]
all_exist = True
for filename in required_files:
filepath = Path(filename)
if filepath.exists():
print(f"β {filename} exists")
else:
print(f"β {filename} missing")
all_exist = False
return all_exist
def test_index_html():
"""Test that index.html is valid for deployment"""
print("\nTesting index.html...")
try:
with open("index.html", "r", encoding="utf-8") as f:
content = f.read()
# Basic validation
assert "<!DOCTYPE html>" in content or "<html" in content
assert "</html>" in content
print("β index.html is valid")
return True
except Exception as e:
print(f"β index.html validation failed: {e}")
return False
def test_api_methods():
"""Test that all required API methods exist"""
print("\nTesting API methods...")
try:
from cloudflare_manager import CloudflareManager
required_methods = [
# Pages methods
"create_pages_project",
"list_pages_projects",
"get_pages_project",
"deploy_pages_project",
"list_pages_deployments",
# Domain methods
"add_pages_domain",
"list_pages_domains",
"get_pages_domain",
# Zone methods
"create_zone",
"list_zones",
"get_zone",
"get_zone_by_name",
"get_nameservers",
# Worker methods
"create_worker_route",
"list_worker_routes",
"delete_worker_route",
"add_worker_domain",
"list_worker_domains",
]
all_exist = True
for method_name in required_methods:
if hasattr(CloudflareManager, method_name):
print(f"β Method '{method_name}' exists")
else:
print(f"β Method '{method_name}' missing")
all_exist = False
return all_exist
except Exception as e:
print(f"β API methods test failed: {e}")
return False
def run_all_tests():
"""Run all tests"""
print("""
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Cloudflare Manager - Test Suite β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
""")
tests = [
("File Structure", test_file_structure),
("Imports", test_imports),
("Account Creation", test_account_creation),
("Multi-Account Manager", test_multi_account_manager),
("API Methods", test_api_methods),
("index.html", test_index_html),
]
results = []
for test_name, test_func in tests:
print(f"\n{'='*60}")
print(f"Test: {test_name}")
print(f"{'='*60}")
result = test_func()
results.append((test_name, result))
# Summary
print(f"\n\n{'='*60}")
print("Test Summary")
print(f"{'='*60}")
passed = sum(1 for _, result in results if result)
total = len(results)
for test_name, result in results:
status = "β PASS" if result else "β FAIL"
print(f"{status}: {test_name}")
print(f"\nTotal: {passed}/{total} tests passed")
if passed == total:
print("\nπ All tests passed!")
return 0
else:
print(f"\nβ οΈ {total - passed} test(s) failed")
return 1
if __name__ == "__main__":
sys.exit(run_all_tests())
|