-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
673c071
commit cc11fd1
Showing
6 changed files
with
64 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,64 @@ | ||
import base64 | ||
import logging | ||
import os | ||
from unittest.mock import MagicMock, patch | ||
import pytest | ||
|
||
import pandas as pd | ||
import pytest | ||
from google.oauth2.credentials import Credentials | ||
from googleapiclient.http import HttpRequestMock | ||
from unittest.mock import MagicMock, patch | ||
|
||
|
||
HttpRequestMock = pytest.importorskip('googleapiclient.http.HttpRequestMock') | ||
from google.oauth2.credentials import Credentials | ||
from melusine.connectors.gmail import GmailConnector | ||
|
||
|
||
def return_value(resp, content): | ||
return content | ||
|
||
|
||
@pytest.fixture | ||
def mocked_gc(): | ||
with patch("melusine.connectors.gmail.build") as mock_build: | ||
with patch("melusine.connectors.gmail.Credentials.from_authorized_user_file") as mock_creds_from_file: | ||
with patch("melusine.connectors.gmail.os.path.exists") as mock_exists: | ||
mock_exists.return_value = True | ||
mock_service = MagicMock() | ||
mock_service.users().getProfile.return_value = HttpRequestMock( | ||
None, {"emailAddress": "[email protected]"}, return_value | ||
) | ||
mock_service.users().labels().list.return_value = HttpRequestMock( | ||
None, | ||
{ | ||
"labels": [ | ||
{"id": "INBOX", "name": "INBOX", "type": "system"}, | ||
{ | ||
"id": "TRASH", | ||
"name": "TRASH", | ||
"messageListVisibility": "hide", | ||
"labelListVisibility": "labelHide", | ||
"type": "system", | ||
}, | ||
{"id": "UNREAD", "name": "UNREAD", "type": "system"}, | ||
] | ||
}, | ||
return_value, | ||
) | ||
mock_build.return_value = mock_service | ||
mock_creds_from_file.return_value = Credentials("dummy") | ||
|
||
return GmailConnector(token_json_path="token.json", done_label="TRASH", target_column="target") | ||
|
||
|
||
@pytest.fixture | ||
def fake_image(): | ||
image_data = b"" | ||
width = height = 100 | ||
for _ in range(height): | ||
row_data = b"\xff" * (width * 3) | ||
image_data += row_data | ||
|
||
return image_data | ||
|
||
|
||
def return_value(resp, content): | ||
return content | ||
|
||
|
@@ -266,4 +314,4 @@ def test_gc_send_email(mocked_gc, fake_image, caplog): | |
{"attachment.jpg": fake_image}, | ||
) | ||
|
||
assert "Email sent to [email protected], Message Id: 12456" | ||
assert "Email sent to [email protected], Message Id: 12456" in caplog.text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters