<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
test_lethe
----------------------------------

Tests for `lethe` module.
"""


import sys
import unittest
from datetime import datetime
import os
from mock import patch, MagicMock, call
from lethe.email_utils import send_basic_email, calculate_birthday

fixtures_dir = os.path.join(os.path.dirname(__file__), 'fixtures')

class TestEmailUtils(unittest.TestCase):

    def setUp(self):
        pass

    def tearDown(self):
        pass

    @patch('lethe.email_utils.smtplib.SMTP')
    def test_send_4_week_email(self, smtp_mock):
        smtp_mocked_instance = MagicMock()
        smtp_mock.return_value = smtp_mocked_instance
        person1 = MagicMock(email='<EMAIL>', dob=datetime.strptime('05/07/1993', '%d/%m/%Y'))
        person1.name = 'Eva'
        person2 = MagicMock(email='<EMAIL>', dob=datetime.strptime('05/02/1993', '%d/%m/%Y'))
        person2.name = 'Bob'
        send_basic_email(person1, person2, 4)
        self.assertEqual(
            smtp_mocked_instance.sendmail.assert_has_calls([
                call('<EMAIL>', [], 'Content-Type: text/plain; charset="us-ascii"\nMIME-Version: 1.0\nContent-Transfer-Encoding: 7bit\nSubject: Birthday Reminder for Bob\nFrom: <EMAIL>\n\nBob\'s 24th birthday is 4 weeks away on the 05/02/1993')
            ]),
            None
        )

    @patch('lethe.email_utils.smtplib.SMTP')
    def test_send_2_week_email(self, smtp_mock):
        smtp_mocked_instance = MagicMock()
        smtp_mock.return_value = smtp_mocked_instance
        person1 = MagicMock(email='<EMAIL>', dob=datetime.strptime('05/07/1993', '%d/%m/%Y'))
        person1.name = 'Eva'
        person2 = MagicMock(email='<EMAIL>', dob=datetime.strptime('05/02/1993', '%d/%m/%Y'))
        person2.name = 'Bob'
        send_basic_email(person1, person2, 2)
        self.assertEqual(
            smtp_mocked_instance.sendmail.assert_has_calls([
                call('<EMAIL>', [],
                     'Content-Type: text/plain; charset="us-ascii"\nMIME-Version: 1.0\nContent-Transfer-Encoding: 7bit\nSubject: Birthday Reminder for Bob\nFrom: <EMAIL>\n\nBob\'s 24th birthday is 2 weeks away on the 05/02/1993')
            ]),
            None
        )

    def test_calculate_birthday(self):
        expected = {
            '21st' : MagicMock(dob=datetime.strptime('05/07/1996', '%d/%m/%Y')),
            '22nd' : MagicMock(dob=datetime.strptime('05/07/1995', '%d/%m/%Y')),
            '23rd' : MagicMock(dob=datetime.strptime('05/07/1994', '%d/%m/%Y')),
            '24th' : MagicMock(dob=datetime.strptime('05/07/1993', '%d/%m/%Y')),
            '30th' : MagicMock(dob=datetime.strptime('05/07/1987', '%d/%m/%Y')),
        }
        for expected_result, mock in expected.iteritems():
            birthday = calculate_birthday(mock)
            self.assertEqual(birthday, expected_result)<commit_msg>changing to be python 3 compatible<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
test_lethe
----------------------------------

Tests for `lethe` module.
"""


import sys
import unittest
from datetime import datetime
import os
from mock import patch, MagicMock, call
from lethe.email_utils import send_basic_email, calculate_birthday

fixtures_dir = os.path.join(os.path.dirname(__file__), 'fixtures')

class TestEmailUtils(unittest.TestCase):

    def setUp(self):
        pass

    def tearDown(self):
        pass

    @patch('lethe.email_utils.smtplib.SMTP')
    def test_send_4_week_email(self, smtp_mock):
        smtp_mocked_instance = MagicMock()
        smtp_mock.return_value = smtp_mocked_instance
        person1 = MagicMock(email='<EMAIL>', dob=datetime.strptime('05/07/1993', '%d/%m/%Y'))
        person1.name = 'Eva'
        person2 = MagicMock(email='<EMAIL>', dob=datetime.strptime('05/02/1993', '%d/%m/%Y'))
        person2.name = 'Bob'
        send_basic_email(person1, person2, 4)
        self.assertEqual(
            smtp_mocked_instance.sendmail.assert_has_calls([
                call('<EMAIL>', [], 'Content-Type: text/plain; charset="us-ascii"\nMIME-Version: 1.0\nContent-Transfer-Encoding: 7bit\nSubject: Birthday Reminder for Bob\nFrom: <EMAIL>\n\nBob\'s 24th birthday is 4 weeks away on the 05/02/1993')
            ]),
            None
        )

    @patch('lethe.email_utils.smtplib.SMTP')
    def test_send_2_week_email(self, smtp_mock):
        smtp_mocked_instance = MagicMock()
        smtp_mock.return_value = smtp_mocked_instance
        person1 = MagicMock(email='<EMAIL>', dob=datetime.strptime('05/07/1993', '%d/%m/%Y'))
        person1.name = 'Eva'
        person2 = MagicMock(email='<EMAIL>', dob=datetime.strptime('05/02/1993', '%d/%m/%Y'))
        person2.name = 'Bob'
        send_basic_email(person1, person2, 2)
        self.assertEqual(
            smtp_mocked_instance.sendmail.assert_has_calls([
                call('<EMAIL>', [],
                     'Content-Type: text/plain; charset="us-ascii"\nMIME-Version: 1.0\nContent-Transfer-Encoding: 7bit\nSubject: Birthday Reminder for Bob\nFrom: <EMAIL>\n\nBob\'s 24th birthday is 2 weeks away on the 05/02/1993')
            ]),
            None
        )

    def test_calculate_birthday(self):
        expected = {
            '21st' : MagicMock(dob=datetime.strptime('05/07/1996', '%d/%m/%Y')),
            '22nd' : MagicMock(dob=datetime.strptime('05/07/1995', '%d/%m/%Y')),
            '23rd' : MagicMock(dob=datetime.strptime('05/07/1994', '%d/%m/%Y')),
            '24th' : MagicMock(dob=datetime.strptime('05/07/1993', '%d/%m/%Y')),
            '30th' : MagicMock(dob=datetime.strptime('05/07/1987', '%d/%m/%Y')),
        }
        for expected_result, mock in expected.items():
            birthday = calculate_birthday(mock)
            self.assertEqual(birthday, expected_result)
{'fraction_non_alphanumeric': 0.16278668735988963, 'fraction_numerical': 0.04397309881013968, 'mean_word_length': 2.746770025839793, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1277599', 'n_tokens_mistral': 2138, 'n_tokens_neox': 1953, 'n_words': 324}