Spaces:
Runtime error
Runtime error
Download tests/verify_fix.py from Darshankumarr03/Swift-Query: direct link, hf CLI and curl.
- Browser
- Download file 2.58 kB
-
https://huggingface.co/spaces/Darshankumarr03/Swift-Query/resolve/main/tests/verify_fix.py
- Command line
-
hf download hf://spaces/Darshankumarr03/Swift-Query/tests/verify_fix.py
-
curl -L -o verify_fix.py https://huggingface.co/spaces/Darshankumarr03/Swift-Query/resolve/main/tests/verify_fix.py
2.58 kB
| import sys | |
| import os | |
| sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| from flask import Flask, session, request | |
| from utils.blueprints.assistant import assistant_bp | |
| import mongomock | |
| # Patch mongo with mock | |
| from utils.blueprints import assistant | |
| assistant.mongo.db = mongomock.MongoClient().db | |
| app = Flask(__name__, template_folder='templates') | |
| app.secret_key = 'test' | |
| app.register_blueprint(assistant_bp) | |
| def test_search_and_entry(): | |
| with app.test_request_context(): | |
| # Setup session | |
| session['user_type'] = 'assistant' | |
| session['role'] = 'data_entry' | |
| session['user_name'] = 'Test Assistant' | |
| # 1. Create a patient | |
| assistant.mongo.db.patient.insert_one({ | |
| "id": 101, "sql_id": 101, "name": "John Doe", "phone": "1234567890", "email": "john@example.com" | |
| }) | |
| # 2. Test Search by Phone | |
| with app.test_client() as client: | |
| with client.session_transaction() as sess: | |
| sess['user_type'] = 'assistant' | |
| sess['role'] = 'data_entry' | |
| resp = client.get('/assistant/dashboard/data_entry?q=1234567890') | |
| if b"John Doe" in resp.data: | |
| print("SUCCESS: Search by phone found patient.") | |
| else: | |
| print("FAILURE: Search by phone did not find patient.") | |
| # 3. Test Data Entry with String ID (Legacy Fix) | |
| with app.test_client() as client: | |
| with client.session_transaction() as sess: | |
| sess['user_type'] = 'assistant' | |
| sess['role'] = 'data_entry' | |
| sess['user_name'] = 'Test Assistant' | |
| # Simulate posting to a "string" ID url that matches the int ID in DB | |
| # The route is /add_record/<record_type>/<patient_id> | |
| # We pass "101" as string, backend should convert to int 101 and save. | |
| data = { | |
| "diagnosis_date": "2023-01-01", | |
| "condition": "Flu", | |
| "notes": "Test Note" | |
| } | |
| resp = client.post('/assistant/add_record/summary/101', data=data, follow_redirects=True) | |
| # Check DB | |
| record = assistant.mongo.db.medicalhistory.find_one({"patient_id": 101}) | |
| if record and record['condition'] == 'Flu': | |
| print("SUCCESS: Data entry saved with ID resolution.") | |
| else: | |
| print("FAILURE: Data entry NOT saved.") | |
| if __name__ == "__main__": | |
| test_search_and_entry() | |