test_gmail.py 1.2 KB

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