Download test_app.py from dxdoan/WC: direct link, hf CLI and curl.
- Browser
- Download file 2.04 kB
-
https://huggingface.co/spaces/dxdoan/WC/resolve/main/test_app.py
- Command line
-
hf download hf://spaces/dxdoan/WC/test_app.py
-
curl -L -o test_app.py https://huggingface.co/spaces/dxdoan/WC/resolve/main/test_app.py
2.04 kB
| import pytest | |
| import os | |
| from unittest.mock import patch, MagicMock | |
| import streamlit as st | |
| # Test the API key handling in the UI app | |
| def test_api_key_handling_with_key(): | |
| """Test UI app behavior when API key is configured""" | |
| with patch.dict(os.environ, {"AGENT_API_KEY": "test-key-123"}, clear=True): | |
| # Import the app after setting environment | |
| from app import AGENT_URL | |
| # The app should have access to the API key | |
| api_key = os.getenv("AGENT_API_KEY") | |
| assert api_key == "test-key-123" | |
| def test_api_key_handling_without_key(): | |
| """Test UI app behavior when no API key is configured""" | |
| with patch.dict(os.environ, {}, clear=True): | |
| # Import the app after clearing environment | |
| from app import AGENT_URL | |
| # The app should handle missing API key gracefully | |
| api_key = os.getenv("AGENT_API_KEY") | |
| assert api_key is None | |
| def test_environment_variable_loading(): | |
| """Test that environment variables are properly loaded""" | |
| # Mock the dotenv loading BEFORE importing the app | |
| with patch('dotenv.load_dotenv'): | |
| # Clear any existing environment and set our test values | |
| with patch.dict(os.environ, { | |
| "ENVIRONMENT": "dev", | |
| "AGENT_URL": "http://test-agent:8001", | |
| "MCP_SERVER_URL": "http://test-mcp:8000" | |
| }, clear=True): | |
| # Force reload the app module to get fresh environment | |
| import sys | |
| if 'app' in sys.modules: | |
| del sys.modules['app'] | |
| from app import ENVIRONMENT, AGENT_URL, MCP_SERVER_URL | |
| # App should use the environment variable we set | |
| assert ENVIRONMENT == "dev" | |
| # App should use the mapped URLs from ENV_URLS | |
| assert AGENT_URL == "http://35.91.47.182:8001" # dev environment URL | |
| assert MCP_SERVER_URL == "http://34.220.95.49:8000" # dev environment URL | |
| if __name__ == "__main__": | |
| pytest.main([__file__, "-v"]) | |