test_utils.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. """Unit tests for utility functions."""
  2. from src.utils import format_timestamp, generate_text_hash, get_timestamp
  3. def test_generate_text_hash() -> None:
  4. """Test text hash generation."""
  5. text = "This is a test memory"
  6. hash1 = generate_text_hash(text)
  7. hash2 = generate_text_hash(text)
  8. # Same text should produce same hash
  9. assert hash1 == hash2
  10. assert len(hash1) == 64 # SHA256 produces 64 character hex
  11. # Different text should produce different hash
  12. hash3 = generate_text_hash("Different text")
  13. assert hash1 != hash3
  14. def test_get_timestamp() -> None:
  15. """Test timestamp generation."""
  16. ts = get_timestamp()
  17. assert isinstance(ts, int)
  18. assert ts > 0
  19. def test_format_timestamp() -> None:
  20. """Test timestamp formatting."""
  21. ts = 1609459200 # 2021-01-01 00:00:00 UTC
  22. formatted = format_timestamp(ts)
  23. assert "2021-01-01" in formatted
  24. assert formatted.endswith("+00:00")
  25. def test_format_timestamp_is_utc() -> None:
  26. """Test timestamp formatting is explicitly UTC."""
  27. ts = 1609459200 # 2021-01-01 00:00:00 UTC
  28. formatted = format_timestamp(ts)
  29. assert formatted == "2021-01-01T00:00:00+00:00"