test_notion.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import hashlib
  2. import os
  3. from unittest.mock import Mock, patch
  4. import pytest
  5. from embedchain.loaders.notion import NotionLoader
  6. @pytest.fixture
  7. def notion_loader():
  8. with patch.dict(os.environ, {"NOTION_INTEGRATION_TOKEN": "test_notion_token"}):
  9. yield NotionLoader()
  10. def test_load_data(notion_loader):
  11. source = "https://www.notion.so/Test-Page-1234567890abcdef1234567890abcdef"
  12. mock_text = "This is a test page."
  13. expected_doc_id = hashlib.sha256((mock_text + source).encode()).hexdigest()
  14. expected_data = [
  15. {
  16. "content": mock_text,
  17. "meta_data": {"url": "notion-12345678-90ab-cdef-1234-567890abcdef"}, # formatted_id
  18. }
  19. ]
  20. mock_page = Mock()
  21. mock_page.text = mock_text
  22. mock_documents = [mock_page]
  23. with patch("embedchain.loaders.notion.NotionPageLoader") as mock_reader:
  24. mock_reader.return_value.load_data.return_value = mock_documents
  25. result = notion_loader.load_data(source)
  26. assert result["doc_id"] == expected_doc_id
  27. assert result["data"] == expected_data