- Implemented MedicineManagementWindow for adding, editing, and removing medicines. - Created MedicineManager to handle medicine configurations, including loading and saving to JSON. - Updated UIManager to dynamically generate medicine-related UI components based on the MedicineManager. - Enhanced test suite with mock objects for MedicineManager to ensure proper functionality in DataManager tests. - Added validation for medicine input fields in the UI. - Introduced default medicine configurations for initial setup.
89 lines
2.8 KiB
Python
89 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script to validate the modular medicine system.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
|
|
# Add src to path
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src"))
|
|
|
|
from init import logger
|
|
from medicine_manager import Medicine, MedicineManager
|
|
|
|
|
|
def test_medicine_system():
|
|
"""Test the complete medicine system."""
|
|
print("🧪 Testing Medicine System...")
|
|
|
|
# Test 1: Initialize medicine manager
|
|
print("\n1. Testing MedicineManager initialization...")
|
|
medicine_manager = MedicineManager(logger=logger)
|
|
medicines = medicine_manager.get_all_medicines()
|
|
print(f" ✅ Loaded {len(medicines)} medicines")
|
|
|
|
# Test 2: List current medicines
|
|
print("\n2. Current medicines:")
|
|
for key, medicine in medicines.items():
|
|
status = "🟢" if medicine.default_enabled else "⚫"
|
|
print(f" {status} {key}: {medicine.display_name} ({medicine.dosage_info})")
|
|
print(f" Quick doses: {medicine.quick_doses}")
|
|
print(f" Color: {medicine.color}")
|
|
|
|
# Test 3: Add a new medicine
|
|
print("\n3. Testing adding new medicine...")
|
|
new_medicine = Medicine(
|
|
key="sertraline",
|
|
display_name="Sertraline",
|
|
dosage_info="50mg",
|
|
quick_doses=["25", "50", "100"],
|
|
color="#9B59B6",
|
|
default_enabled=False,
|
|
)
|
|
|
|
if medicine_manager.add_medicine(new_medicine):
|
|
print(" ✅ Successfully added Sertraline")
|
|
updated_medicines = medicine_manager.get_all_medicines()
|
|
print(f" Now have {len(updated_medicines)} medicines")
|
|
else:
|
|
print(" ❌ Failed to add Sertraline")
|
|
|
|
# Test 4: Test CSV headers
|
|
print("\n4. Testing CSV headers generation...")
|
|
from data_manager import DataManager
|
|
|
|
DataManager("test_medicines.csv", logger, medicine_manager)
|
|
|
|
if os.path.exists("test_medicines.csv"):
|
|
with open("test_medicines.csv") as f:
|
|
headers = f.readline().strip()
|
|
print(f" CSV headers: {headers}")
|
|
os.remove("test_medicines.csv") # Clean up
|
|
print(" ✅ CSV headers generated successfully")
|
|
|
|
# Test 5: Test graph colors
|
|
print("\n5. Testing graph colors...")
|
|
colors = medicine_manager.get_graph_colors()
|
|
for key, color in colors.items():
|
|
print(f" {key}: {color}")
|
|
print(" ✅ Graph colors retrieved successfully")
|
|
|
|
# Clean up - remove test medicine
|
|
print("\n6. Cleaning up...")
|
|
if medicine_manager.remove_medicine("sertraline"):
|
|
print(" ✅ Test medicine removed successfully")
|
|
|
|
print("\n🎉 All tests passed! Medicine system is working correctly.")
|
|
return True
|
|
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
test_medicine_system()
|
|
except Exception as e:
|
|
print(f"❌ Test failed with error: {e}")
|
|
import traceback
|
|
|
|
traceback.print_exc()
|