fix: notes are saved again
feat: Add test scripts for note saving and updating functionality
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test script to verify note field saving functionality
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
import pandas as pd
|
||||
|
||||
# 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_note_saving():
|
||||
"""Test note saving functionality by checking current data"""
|
||||
print("Testing note saving functionality...")
|
||||
|
||||
# Initialize logger
|
||||
logger = logging.getLogger("test")
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
# 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")
|
||||
|
||||
# Check if we have any entries with notes
|
||||
entries_with_notes = df[df["note"].notna() & (df["note"] != "")].copy()
|
||||
|
||||
print(f"Entries with notes: {len(entries_with_notes)}")
|
||||
|
||||
if len(entries_with_notes) > 0:
|
||||
print("\nEntries with notes:")
|
||||
for _, row in entries_with_notes.iterrows():
|
||||
note_preview = (
|
||||
row["note"][:50] + "..." if len(str(row["note"])) > 50 else row["note"]
|
||||
)
|
||||
print(f" Date: {row['date']}, Note: {note_preview}")
|
||||
|
||||
# Show the most recent entry
|
||||
if len(df) > 0:
|
||||
latest_entry = df.iloc[-1]
|
||||
print("\nMost recent entry:")
|
||||
print(f" Date: {latest_entry['date']}")
|
||||
print(f" Note: '{latest_entry['note']}'")
|
||||
print(f" Note length: {len(str(latest_entry['note']))}")
|
||||
is_empty = pd.isna(latest_entry["note"]) or latest_entry["note"] == ""
|
||||
print(f" Note is empty/null: {is_empty}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_note_saving()
|
||||
@@ -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