Spaces:
Runtime error
Runtime error
Download tests/verify_search_mode.py from Darshankumarr03/Swift-Query: direct link, hf CLI and curl.
- Browser
- Download file 3.23 kB
-
https://huggingface.co/spaces/Darshankumarr03/Swift-Query/resolve/main/tests/verify_search_mode.py
- Command line
-
hf download hf://spaces/Darshankumarr03/Swift-Query/tests/verify_search_mode.py
-
curl -L -o verify_search_mode.py https://huggingface.co/spaces/Darshankumarr03/Swift-Query/resolve/main/tests/verify_search_mode.py
3.23 kB
| import sys | |
| import os | |
| sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../'))) | |
| from main import app | |
| from flask import session | |
| def verify_patient_search(): | |
| with app.test_client() as client: | |
| # 1. Default State: Send number, expect generic response | |
| print("\n--- Test 1: Default State (Search OFF) ---") | |
| response = client.post('/api/chat', json={'message': '1'}, follow_redirects=True) | |
| resp_json = response.get_json() | |
| print(f"User: '1'\nAI: {resp_json['response']}") | |
| if "Patient Record" not in resp_json['response']: | |
| print("PASS: Did not trigger patient search in default state.") | |
| else: | |
| print("FAIL: Triggered patient search unexpectedly.") | |
| # 2. Enable Mode | |
| print("\n--- Test 2: Enable Search Mode ---") | |
| with client.session_transaction() as sess: | |
| # Simulate previous session state if needed, but test_client handles cookies | |
| pass | |
| response = client.post('/api/chat', json={'message': 'patient search on'}, follow_redirects=True) | |
| resp_json = response.get_json() | |
| print(f"User: 'patient search on'\nAI: {resp_json['response']}") | |
| if "Activated" in resp_json['response']: | |
| print("PASS: Mode activated.") | |
| else: | |
| print("FAIL: Mode activation failed.") | |
| # 3. Search Active: Send number, expect Patient Record (assuming ID 1 exists) | |
| # Note: We need to maintain the session cookie. test_client does this automatically. | |
| print("\n--- Test 3: Search Active (Send '1') ---") | |
| response = client.post('/api/chat', json={'message': '1'}, follow_redirects=True) | |
| resp_json = response.get_json() | |
| # Truncate long response for display | |
| snippet = resp_json['response'][:100].replace('\n', ' ') | |
| print(f"User: '1'\nAI: {snippet}...") | |
| if "Patient Record" in resp_json['response'] or "No patient found" in resp_json['response']: | |
| print("PASS: Patient search triggered.") | |
| else: | |
| print("FAIL: Patient search NOT triggered when active.") | |
| # 4. Disable Mode | |
| print("\n--- Test 4: Disable Mode ---") | |
| response = client.post('/api/chat', json={'message': 'patient search off'}, follow_redirects=True) | |
| resp_json = response.get_json() | |
| print(f"User: 'patient search off'\nAI: {resp_json['response']}") | |
| if "Deactivated" in resp_json['response']: | |
| print("PASS: Mode deactivated.") | |
| else: | |
| print("FAIL: Mode deactivation failed.") | |
| # 5. Verify Off | |
| print("\n--- Test 5: Verify OFF State ---") | |
| response = client.post('/api/chat', json={'message': '1'}, follow_redirects=True) | |
| resp_json = response.get_json() | |
| snippet = resp_json['response'][:100].replace('\n', ' ') | |
| print(f"User: '1'\nAI: {snippet}...") | |
| if "Patient Record" not in resp_json['response']: | |
| print("PASS: Correctly ignored number in OFF state.") | |
| else: | |
| print("FAIL: Triggered search in OFF state.") | |
| if __name__ == "__main__": | |
| verify_patient_search() | |