Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled
92 lines
3.1 KiB
Python
92 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script to verify date uniqueness functionality in TheChart app.
|
|
"""
|
|
|
|
import logging
|
|
import os
|
|
import sys
|
|
|
|
# Add the src directory to the Python path
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src"))
|
|
|
|
from src.data_manager import DataManager
|
|
|
|
# Set up simple logging
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
logger = logging.getLogger("test")
|
|
|
|
|
|
def test_date_uniqueness():
|
|
"""Test the date uniqueness validation."""
|
|
print("Testing date uniqueness functionality...")
|
|
|
|
# Create a test data manager with a test file
|
|
test_filename = "test_data.csv"
|
|
dm = DataManager(test_filename, logger)
|
|
|
|
# Test 1: Add first entry (should succeed)
|
|
print("\n1. Adding first entry...")
|
|
entry1 = ["2025-07-28", 5, 5, 5, 5, 0, 0, 0, 0, "First entry"]
|
|
result1 = dm.add_entry(entry1)
|
|
print(f"Result: {result1} (Expected: True)")
|
|
|
|
# Test 2: Try to add duplicate date (should fail)
|
|
print("\n2. Trying to add duplicate date...")
|
|
entry2 = ["2025-07-28", 3, 3, 3, 3, 1, 1, 1, 1, "Duplicate entry"]
|
|
result2 = dm.add_entry(entry2)
|
|
print(f"Result: {result2} (Expected: False)")
|
|
|
|
# Test 3: Add different date (should succeed)
|
|
print("\n3. Adding different date...")
|
|
entry3 = ["2025-07-29", 4, 4, 4, 4, 0, 0, 0, 0, "Second entry"]
|
|
result3 = dm.add_entry(entry3)
|
|
print(f"Result: {result3} (Expected: True)")
|
|
|
|
# Test 4: Update entry with same date (should succeed)
|
|
print("\n4. Updating entry with same date...")
|
|
updated_entry = ["2025-07-28", 6, 6, 6, 6, 1, 1, 1, 1, "Updated entry"]
|
|
result4 = dm.update_entry("2025-07-28", updated_entry)
|
|
print(f"Result: {result4} (Expected: True)")
|
|
|
|
# Test 5: Try to update entry to existing date (should fail)
|
|
print("\n5. Trying to update entry to existing date...")
|
|
conflicting_entry = ["2025-07-29", 7, 7, 7, 7, 1, 1, 1, 1, "Conflicting entry"]
|
|
result5 = dm.update_entry("2025-07-28", conflicting_entry)
|
|
print(f"Result: {result5} (Expected: False)")
|
|
|
|
# Test 6: Update entry to new date (should succeed)
|
|
print("\n6. Updating entry to new date...")
|
|
new_date_entry = ["2025-07-30", 8, 8, 8, 8, 1, 1, 1, 1, "New date entry"]
|
|
result6 = dm.update_entry("2025-07-28", new_date_entry)
|
|
print(f"Result: {result6} (Expected: True)")
|
|
|
|
# Cleanup
|
|
if os.path.exists(test_filename):
|
|
os.remove(test_filename)
|
|
|
|
# Summary
|
|
expected_results = [True, False, True, True, False, True]
|
|
actual_results = [result1, result2, result3, result4, result5, result6]
|
|
|
|
print("\n" + "=" * 50)
|
|
print("TEST SUMMARY:")
|
|
print("=" * 50)
|
|
|
|
all_passed = True
|
|
for i, (expected, actual) in enumerate(
|
|
zip(expected_results, actual_results, strict=True), 1
|
|
):
|
|
status = "PASS" if expected == actual else "FAIL"
|
|
if expected != actual:
|
|
all_passed = False
|
|
print(f"Test {i}: {status} (Expected: {expected}, Got: {actual})")
|
|
|
|
overall_result = "ALL TESTS PASSED" if all_passed else "SOME TESTS FAILED"
|
|
print(f"\nOverall result: {overall_result}")
|
|
return all_passed
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_date_uniqueness()
|