-
Notifications
You must be signed in to change notification settings - Fork 3
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
a5b4da6
commit 38ec8d8
Showing
7 changed files
with
61 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import sys | ||
import os | ||
import pytest | ||
import base64 | ||
import mimetypes | ||
from PIL import Image | ||
|
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 |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
|
||
|
||
class TestAppendToGoogleSheet(unittest.TestCase): | ||
@patch('mecsimcalc.quiz_utils.requests') | ||
@patch("mecsimcalc.quiz_utils.requests") | ||
def test_append_to_google_sheet(self, mock_post): | ||
# mock response | ||
mock_response = MagicMock() | ||
|
@@ -33,26 +33,28 @@ def test_append_to_google_sheet(self, mock_post): | |
"token_uri": "https://oauth2.googleapis.com/token", | ||
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", | ||
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/xxx.com", | ||
"universe_domain": "googleapis.com" | ||
"universe_domain": "googleapis.com", | ||
} | ||
spreadsheet_id = 'dummy_spreadsheet_id' | ||
spreadsheet_id = "dummy_spreadsheet_id" | ||
values = [["dummy_data"]] | ||
range_name = 'Sheet1!A1' | ||
range_name = "Sheet1!A1" | ||
|
||
# execute the function | ||
response = append_to_google_sheet(service_account_info, spreadsheet_id, values, range_name, False) | ||
response = append_to_google_sheet( | ||
service_account_info, spreadsheet_id, values, range_name, False | ||
) | ||
assert isinstance(response, dict) | ||
|
||
|
||
class TestSendEmail(unittest.TestCase): | ||
@patch('mecsimcalc.quiz_utils.smtplib.SMTP_SSL') | ||
@patch("mecsimcalc.quiz_utils.smtplib.SMTP_SSL") | ||
def test_send_email_success(self, mock_smtp_ssl): | ||
# Setup test data | ||
sender_email = '[email protected]' | ||
receiver_email = '[email protected]' | ||
subject = 'Test Subject' | ||
app_password = 'app-specific-password' | ||
values = [('Data1', 'Data2'), ('Data3', 'Data4')] | ||
sender_email = "[email protected]" | ||
receiver_email = "[email protected]" | ||
subject = "Test Subject" | ||
app_password = "app-specific-password" | ||
values = [("Data1", "Data2"), ("Data3", "Data4")] | ||
|
||
# Configure the mock SMTP server | ||
mock_server = MagicMock() | ||
|
@@ -63,7 +65,7 @@ def test_send_email_success(self, mock_smtp_ssl): | |
|
||
# Assertions | ||
assert res == True | ||
mock_smtp_ssl.assert_called_once_with('smtp.gmail.com', 465) | ||
mock_smtp_ssl.assert_called_once_with("smtp.gmail.com", 465) | ||
mock_server.login.assert_called_once_with(sender_email, app_password) | ||
mock_server.sendmail.assert_called_once() | ||
args, _ = mock_server.sendmail.call_args | ||
|
@@ -75,14 +77,14 @@ def test_send_email_success(self, mock_smtp_ssl): | |
for value in values: | ||
self.assertIn(", ".join(value), email_body) | ||
|
||
@patch('mecsimcalc.quiz_utils.smtplib.SMTP_SSL') | ||
@patch("mecsimcalc.quiz_utils.smtplib.SMTP_SSL") | ||
def test_send_email_failure(self, mock_smtp_ssl): | ||
# Setup test data with same parameters as success test | ||
sender_email = '[email protected]' | ||
receiver_email = '[email protected]' | ||
subject = 'Test Subject' | ||
app_password = 'app-specific-password' | ||
values = [('Data1', 'Data2'), ('Data3', 'Data4')] | ||
sender_email = "[email protected]" | ||
receiver_email = "[email protected]" | ||
subject = "Test Subject" | ||
app_password = "app-specific-password" | ||
values = [("Data1", "Data2"), ("Data3", "Data4")] | ||
|
||
# Configure the mock SMTP server to raise an exception | ||
mock_smtp_ssl.return_value.__enter__.side_effect = Exception("SMTP Error") | ||
|
@@ -92,4 +94,4 @@ def test_send_email_failure(self, mock_smtp_ssl): | |
|
||
# Assertions | ||
assert res == False | ||
mock_smtp_ssl.assert_called_once_with('smtp.gmail.com', 465) | ||
mock_smtp_ssl.assert_called_once_with("smtp.gmail.com", 465) |
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,6 +1,5 @@ | ||
import sys | ||
import os | ||
import pytest | ||
import base64 | ||
import mimetypes | ||
import io | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,5 +26,5 @@ | |
"metadata_to_filetype", | ||
"file_to_PIL", | ||
"append_to_google_sheet", | ||
"send_gmail" | ||
"send_gmail", | ||
] |
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