Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
Add reading environment variables test.
Browse files Browse the repository at this point in the history
  • Loading branch information
lfir committed Mar 27, 2021
1 parent 761cd51 commit 9b87fd8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tests/test_mail_error_notifs.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import io
import os
import unittest
from unittest.mock import patch
from unittest.mock import Mock, patch

from dotenv import load_dotenv
from mail_error_notifs.mail_error_notifs import SendGridAPIClient, send_email


class TestScripts(unittest.TestCase):

def test_when_env_file_present_environment_variables_can_be_read(self):
load_dotenv('./.env')
self.assertIsNotNone(os.getenv('LOGDIR'))

@patch('sys.stdout', new_callable=io.StringIO)
def test_when_email_sent_then_statuscode_printed_is_202(self, mock_stdout):
def test_when_email_sent_then_statuscode_printed_is_the_one_returned_by_sendgridclient(self, mock_stdout):
SendGridAPIClient.send = Mock()
send_email('TestCase subject', 'TestCase body')
self.assertIn('status code: 202', mock_stdout.getvalue())
self.assertIn('SendGrid response status', mock_stdout.getvalue())

def test_when_email_not_sent_then_error_is_logged(self):
err_msg = 'Send mail error'
Expand Down

0 comments on commit 9b87fd8

Please sign in to comment.