Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled
96 lines
3.2 KiB
Python
96 lines
3.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test the complete dose tracking flow: load -> display -> add -> save
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
from datetime import datetime
|
|
|
|
# Add the src directory to Python path
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
|
|
|
|
from init import logger
|
|
from ui_manager import UIManager
|
|
|
|
|
|
def test_dose_parsing():
|
|
"""Test dose parsing functions directly."""
|
|
|
|
# Mock a UI manager instance for testing
|
|
class MockManager:
|
|
def get_all_medicines(self):
|
|
return ["bupropion"]
|
|
|
|
def get_all_pathologies(self):
|
|
return []
|
|
|
|
ui_manager = UIManager(None, logger, MockManager(), MockManager(), None)
|
|
|
|
# Test 1: Parse storage format to display format
|
|
print("=== Test 1: Storage to Display Format ===")
|
|
storage_format = "2025-08-07 08:00:00:150mg|2025-08-07 12:00:00:150mg"
|
|
print(f"Input (storage): {storage_format}")
|
|
|
|
# This would normally be done by _populate_dose_history
|
|
formatted_doses = []
|
|
for dose_entry in storage_format.split("|"):
|
|
if ":" in dose_entry:
|
|
parts = dose_entry.rsplit(":", 1)
|
|
if len(parts) == 2:
|
|
timestamp, dose = parts
|
|
try:
|
|
dt = datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S")
|
|
time_str = dt.strftime("%I:%M %p")
|
|
formatted_doses.append(f"• {time_str} - {dose}")
|
|
except ValueError:
|
|
formatted_doses.append(f"• {dose_entry}")
|
|
else:
|
|
formatted_doses.append(f"• {dose_entry}")
|
|
else:
|
|
formatted_doses.append(f"• {dose_entry}")
|
|
|
|
display_format = "\n".join(formatted_doses)
|
|
print(f"Output (display): {display_format}")
|
|
|
|
# Test 2: Add new dose in display format
|
|
print("\n=== Test 2: Add New Dose ===")
|
|
new_timestamp = datetime.now().strftime("%I:%M %p")
|
|
new_dose = f"• {new_timestamp} - 150mg"
|
|
print(f"New dose to add: {new_dose}")
|
|
|
|
updated_display = display_format + f"\n{new_dose}"
|
|
print(f"Updated display: {updated_display}")
|
|
|
|
# Test 3: Parse display format back to storage format
|
|
print("\n=== Test 3: Display to Storage Format ===")
|
|
test_date = "2025-08-07"
|
|
parsed_storage = ui_manager._parse_dose_history_for_saving(
|
|
updated_display, test_date
|
|
)
|
|
print(f"Input (display): {updated_display}")
|
|
print(f"Output (storage): {parsed_storage}")
|
|
|
|
# Test 4: Verify round-trip integrity
|
|
print("\n=== Test 4: Round-trip Test ===")
|
|
print(f"Original storage: {storage_format}")
|
|
print(f"Final storage: {parsed_storage}")
|
|
|
|
# Check if we preserved the original doses
|
|
original_count = len(storage_format.split("|"))
|
|
final_count = len(parsed_storage.split("|")) if parsed_storage else 0
|
|
print(f"Dose count: {original_count} -> {final_count}")
|
|
|
|
if final_count == original_count + 1:
|
|
print("✅ SUCCESS: New dose was added without replacing existing ones")
|
|
elif final_count == original_count:
|
|
print("❌ FAILURE: No new dose was added")
|
|
elif final_count < original_count:
|
|
print("❌ FAILURE: Existing doses were lost")
|
|
else:
|
|
print(f"⚠️ UNEXPECTED: Dose count changed unexpectedly ({final_count})")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_dose_parsing()
|