test_gmail.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import pytest
  2. from llama_hub.readwise.base import Document
  3. from embedchain.loaders.gmail import GmailLoader
  4. @pytest.fixture
  5. def mock_quopri(mocker):
  6. return mocker.patch("embedchain.loaders.gmail.quopri.decodestring", return_value=b"your_test_decoded_string")
  7. @pytest.fixture
  8. def mock_beautifulsoup(mocker):
  9. return mocker.patch("embedchain.loaders.gmail.BeautifulSoup", return_value=mocker.MagicMock())
  10. @pytest.fixture
  11. def gmail_loader(mock_quopri, mock_beautifulsoup):
  12. return GmailLoader()
  13. def test_load_data_file_not_found(gmail_loader, mocker):
  14. with pytest.raises(FileNotFoundError):
  15. with mocker.patch("os.path.isfile", return_value=False):
  16. gmail_loader.load_data("your_query")
  17. @pytest.mark.skip(reason="TODO: Fix this test. Failing due to some googleapiclient import issue.")
  18. def test_load_data(gmail_loader, mocker):
  19. mock_gmail_reader_instance = mocker.MagicMock()
  20. text = "your_test_email_text"
  21. metadata = {
  22. "id": "your_test_id",
  23. "snippet": "your_test_snippet",
  24. }
  25. mock_gmail_reader_instance.load_data.return_value = [Document(text=text, extra_info=metadata)]
  26. with mocker.patch("os.path.isfile", return_value=True):
  27. response_data = gmail_loader.load_data("your_query")
  28. assert "doc_id" in response_data
  29. assert "data" in response_data
  30. assert isinstance(response_data["doc_id"], str)
  31. assert isinstance(response_data["data"], list)