# Path: nowtrade/notification.py
# class SMTPNotification(Notification):
#     """
#     SMTP-based email notifications.
#     """
#     def __init__(self, username, password, recipient, server='smtp.gmail.com', port=587):
#         self.username = username
#         self.password = password
#         self.recipient = recipient
#         self.server = server
#         self.port = port
#         self.session = self._get_session()
#         self.headers = None
#         self.body = None
#         self.logger = logger.Logger(self.__class__.__name__)
#         self.logger.info('username: %s  password: *  recipient: %s  server: %s  port: %s'
#                          %(username, recipient, server, port))
# 
#     def send(self, subject, body):
#         """
#         Sends the email out with the specified subject and body.
#         """
#         self.logger.info('Sending email to %s' %self.recipient)
#         self.headers = self._get_headers(subject)
#         self.body = body
#         self.logger.debug('Headers: %s' %self.headers)
#         self.logger.debug('Body: %s' %self.body)
#         self._send(self.headers, self.body)
#         self.logger.debug('Email sent')
# 
#     def _get_headers(self, subject):
#         """
#         Helper method to generate the email headers.
#         """
#         headers = ['From: ' + self.username,
#                    'Subject: ' + subject,
#                    'To: ' + self.recipient,
#                    'MIME-Version: 1.0',
#                    'Content-Type: text/html']
#         return '\r\n'.join(headers)
# 
#     def _get_session(self):
#         """
#         Simple method to retrieve the email session.
#         """
#         return smtplib.SMTP(self.server, self.port)
# 
#     def _send(self, headers, body):
#         """
#         Low level method that actually does the sending of the email.
#         Should use send() instead.
#         """
#         self.session.ehlo()
#         self.session.starttls()
#         self.session.ehlo()
#         self.session.login(self.username, self.password)
#         self.session.sendmail(self.username, self.recipient, headers + '\r\n\r\n' + body)
#         self.session.quit()


from nowtrade.notification import SMTPNotification
import unittest

class MockSMTPNotification(SMTPNotification):
    def __init__(self, username, password, recipient):
        SMTPNotification.__init__(self, username, password, recipient)
        self.session = MockSMTPSession()

    def _get_session(self):
        pass

class MockSMTPSession:
    def ehlo(self): pass
    def starttls(self): pass
    def login(self, username, password): pass
    def sendmail(self, username, recipient, content): pass
    def quit(self): pass

class TestSMTPNotification(unittest.TestCase):
    def test_initialization(self):

# Path: nowtrade/notification.py
# class SMTPNotification(Notification):
#     """
#     SMTP-based email notifications.
#     """
#     def __init__(self, username, password, recipient, server='smtp.gmail.com', port=587):
#         self.username = username
#         self.password = password
#         self.recipient = recipient
#         self.server = server
#         self.port = port
#         self.session = self._get_session()
#         self.headers = None
#         self.body = None
#         self.logger = logger.Logger(self.__class__.__name__)
#         self.logger.info('username: %s  password: *  recipient: %s  server: %s  port: %s'
#                          %(username, recipient, server, port))
# 
#     def send(self, subject, body):
#         """
#         Sends the email out with the specified subject and body.
#         """
#         self.logger.info('Sending email to %s' %self.recipient)
#         self.headers = self._get_headers(subject)
#         self.body = body
#         self.logger.debug('Headers: %s' %self.headers)
#         self.logger.debug('Body: %s' %self.body)
#         self._send(self.headers, self.body)
#         self.logger.debug('Email sent')
# 
#     def _get_headers(self, subject):
#         """
#         Helper method to generate the email headers.
#         """
#         headers = ['From: ' + self.username,
#                    'Subject: ' + subject,
#                    'To: ' + self.recipient,
#                    'MIME-Version: 1.0',
#                    'Content-Type: text/html']
#         return '\r\n'.join(headers)
# 
#     def _get_session(self):
#         """
#         Simple method to retrieve the email session.
#         """
#         return smtplib.SMTP(self.server, self.port)
# 
#     def _send(self, headers, body):
#         """
#         Low level method that actually does the sending of the email.
#         Should use send() instead.
#         """
#         self.session.ehlo()
#         self.session.starttls()
#         self.session.ehlo()
#         self.session.login(self.username, self.password)
#         self.session.sendmail(self.username, self.recipient, headers + '\r\n\r\n' + body)
#         self.session.quit()


# Path: tests/test_notification.py
from nowtrade.notification import SMTPNotification
import unittest


class MockSMTPNotification(SMTPNotification):
    def __init__(self, username, password, recipient):
        SMTPNotification.__init__(self, username, password, recipient)
        self.session = MockSMTPSession()

    def _get_session(self):
        pass

class MockSMTPSession:
    def ehlo(self): pass
    def starttls(self): pass
    def login(self, username, password): pass
    def sendmail(self, username, recipient, content): pass
    def quit(self): pass

class TestSMTPNotification(unittest.TestCase):
    def test_initialization(self):

        mock_notification = MockSMTPNotification('USERNAME', 'PASSWORD', 'RECIPIENT@EMAIL.COM')