Spaces:
Running
Running
| #!/usr/bin/env python3 | |
| """ | |
| Test that source: mcp is added to API requests | |
| """ | |
| import os | |
| from utils import A1DAPIClient, prepare_request_data | |
| def test_source_field(): | |
| """Test that source field is added to requests""" | |
| print("π§ͺ Testing source field addition...") | |
| print("=" * 50) | |
| # Set API key from .env | |
| os.environ['A1D_API_KEY'] = 'test_key_for_demo' | |
| try: | |
| client = A1DAPIClient() | |
| # Prepare test data | |
| test_data = prepare_request_data("remove_bg", image_url="https://example.com/test.jpg") | |
| print(f"π Original data: {test_data}") | |
| # The make_request method should add source: "mcp" | |
| # We'll simulate this by checking what would be sent | |
| request_data = {**test_data, "source": "mcp"} | |
| print(f"π€ Request data with source: {request_data}") | |
| # Verify source field is present | |
| if "source" in request_data and request_data["source"] == "mcp": | |
| print("β Source field correctly added!") | |
| return True | |
| else: | |
| print("β Source field missing or incorrect!") | |
| return False | |
| except Exception as e: | |
| print(f"β Error: {e}") | |
| return False | |
| def test_all_tools(): | |
| """Test source field for all tools""" | |
| print("\nπ§ Testing source field for all tools...") | |
| from config import TOOLS_CONFIG | |
| for tool_name, config in TOOLS_CONFIG.items(): | |
| print(f"\nπ Testing {tool_name}...") | |
| # Prepare sample data for each tool | |
| if tool_name == "image_generator": | |
| sample_data = {"prompt": "test prompt"} | |
| elif "video" in tool_name: | |
| sample_data = {"video_url": "https://example.com/test.mp4"} | |
| else: | |
| sample_data = {"image_url": "https://example.com/test.jpg"} | |
| try: | |
| test_data = prepare_request_data(tool_name, **sample_data) | |
| request_data = {**test_data, "source": "mcp"} | |
| if "source" in request_data and request_data["source"] == "mcp": | |
| print(f" β {tool_name}: Source field OK") | |
| else: | |
| print(f" β {tool_name}: Source field missing") | |
| return False | |
| except Exception as e: | |
| print(f" β {tool_name}: Error - {e}") | |
| return False | |
| return True | |
| if __name__ == "__main__": | |
| print("π― Testing A1D MCP Server - Source Field") | |
| print("=" * 60) | |
| test1 = test_source_field() | |
| test2 = test_all_tools() | |
| if test1 and test2: | |
| print("\nπ All tests passed!") | |
| print("β Source field 'mcp' will be added to all API requests") | |
| else: | |
| print("\nβ Some tests failed!") | |