#!/usr/bin/env python3 """ Simple test execution script for API tests. Run this from the command line to execute all API tests. """ import subprocess import sys import os def main(): """Main execution function.""" print("๐Ÿš€ Aniworld API Test Executor") print("=" * 40) # Get the directory of this script script_dir = os.path.dirname(os.path.abspath(__file__)) project_root = os.path.join(script_dir, '..', '..') # Change to project root os.chdir(project_root) print(f"๐Ÿ“ Working directory: {os.getcwd()}") print(f"๐Ÿ Python version: {sys.version}") # Try to run the comprehensive test runner test_runner = os.path.join('tests', 'unit', 'web', 'run_api_tests.py') if os.path.exists(test_runner): print(f"\n๐Ÿงช Running comprehensive test suite...") try: result = subprocess.run([sys.executable, test_runner], capture_output=False) return result.returncode except Exception as e: print(f"โŒ Error running comprehensive tests: {e}") # Fallback to individual test files print(f"\n๐Ÿ”„ Falling back to individual test execution...") test_files = [ os.path.join('tests', 'unit', 'web', 'test_api_endpoints.py'), os.path.join('tests', 'integration', 'test_api_integration.py') ] total_failures = 0 for test_file in test_files: if os.path.exists(test_file): print(f"\n๐Ÿ“‹ Running {test_file}...") try: result = subprocess.run([ sys.executable, '-m', 'unittest', test_file.replace('/', '.').replace('\\', '.').replace('.py', ''), '-v' ], capture_output=False, cwd=project_root) if result.returncode != 0: total_failures += 1 print(f"โŒ Test file {test_file} had failures") else: print(f"โœ… Test file {test_file} passed") except Exception as e: print(f"โŒ Error running {test_file}: {e}") total_failures += 1 else: print(f"โš ๏ธ Test file not found: {test_file}") # Final summary print(f"\n{'='*40}") if total_failures == 0: print("๐ŸŽ‰ All tests completed successfully!") return 0 else: print(f"โŒ {total_failures} test file(s) had issues") return 1 if __name__ == '__main__': exit_code = main() sys.exit(exit_code)