fix: notes are saved again
feat: Add test scripts for note saving and updating functionality
This commit is contained in:
102
scripts/test_update_entry.py
Normal file
102
scripts/test_update_entry.py
Normal file
@@ -0,0 +1,102 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test the update_entry functionality with notes
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
# Add src directory to path to import modules
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
|
||||
|
||||
from data_manager import DataManager
|
||||
from medicine_manager import MedicineManager
|
||||
from pathology_manager import PathologyManager
|
||||
|
||||
|
||||
def test_update_entry_with_note():
|
||||
"""Test updating an entry with a note"""
|
||||
print("Testing update_entry functionality with notes...")
|
||||
|
||||
# Initialize logger
|
||||
logger = logging.getLogger("test")
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
# Add console handler to see debug output
|
||||
handler = logging.StreamHandler()
|
||||
handler.setLevel(logging.DEBUG)
|
||||
formatter = logging.Formatter("%(levelname)s - %(message)s")
|
||||
handler.setFormatter(formatter)
|
||||
logger.addHandler(handler)
|
||||
|
||||
# Initialize managers
|
||||
medicine_manager = MedicineManager("medicines.json")
|
||||
pathology_manager = PathologyManager("pathologies.json")
|
||||
data_manager = DataManager(
|
||||
"thechart_data.csv", logger, medicine_manager, pathology_manager
|
||||
)
|
||||
|
||||
# Load current data
|
||||
df = data_manager.load_data()
|
||||
|
||||
if df.empty:
|
||||
print("No data found in CSV file")
|
||||
return
|
||||
|
||||
print(f"Found {len(df)} entries in the data file")
|
||||
|
||||
# Find the most recent entry to test with
|
||||
latest_entry = df.iloc[-1].copy()
|
||||
original_date = latest_entry["date"]
|
||||
|
||||
print(f"Testing with entry: {original_date}")
|
||||
print(f"Current note: '{latest_entry['note']}'")
|
||||
|
||||
# Create test values - keep everything the same but change the note
|
||||
test_note = "This is a test note to verify saving functionality!"
|
||||
|
||||
# Build values list (same format as the UI would send)
|
||||
values = [original_date] # date
|
||||
|
||||
# Add pathology values
|
||||
pathology_keys = pathology_manager.get_pathology_keys()
|
||||
for key in pathology_keys:
|
||||
values.append(latest_entry.get(key, 0))
|
||||
|
||||
# Add medicine values and doses
|
||||
medicine_keys = medicine_manager.get_medicine_keys()
|
||||
for key in medicine_keys:
|
||||
values.append(latest_entry.get(key, 0)) # medicine checkbox
|
||||
values.append(latest_entry.get(f"{key}_doses", "")) # medicine doses
|
||||
|
||||
# Add the test note
|
||||
values.append(test_note)
|
||||
|
||||
print(f"Values to save: {values}")
|
||||
print(f"Note in values: '{values[-1]}'")
|
||||
|
||||
# Test the update
|
||||
success = data_manager.update_entry(original_date, values)
|
||||
|
||||
if success:
|
||||
print("Update successful!")
|
||||
|
||||
# Reload and verify
|
||||
df_after = data_manager.load_data()
|
||||
updated_entry = df_after[df_after["date"] == original_date].iloc[0]
|
||||
|
||||
print(f"Note after update: '{updated_entry['note']}'")
|
||||
print(f"Note correctly saved: {updated_entry['note'] == test_note}")
|
||||
|
||||
# Reset the note back to original
|
||||
values[-1] = latest_entry["note"]
|
||||
data_manager.update_entry(original_date, values)
|
||||
print("Reverted note back to original")
|
||||
|
||||
else:
|
||||
print("Update failed!")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_update_entry_with_note()
|
||||
Reference in New Issue
Block a user