class testSend(unittest.TestCase): def setUp(self): self.gmail_service = authenticate() self.emailer = Emailer() self.match_xls = '/Users/jjw036/Dropbox/GSA/LinkLunch/matches_04212015.xlsx' self.address_xls = '/Users/jjw036/Dropbox/GSA/LinkLunch/individual_info.xlsx' def test_template(self): template_txt = self.emailer.get_template() pdb.set_trace() test_dict = { 'match1': 'Jia Awesomepants', 'match2': 'Bruce Wayne', 'match1_email': '*****@*****.**', 'match2_email': '*****@*****.**', 'match1_dept': 'Magic', 'match2_dept': 'Crime Fighting', 'based_on': 'cheese', 'chicago': 'Y', 'which_person_chicago': 'Bruce', 'notified':'N', 'additional':'Take note that Bruce\'s batcave is located on the Chicago campus.'} new_body = self.emailer.replace_text(test_dict,template_txt) message, body = self.emailer.get_welcome_email(test_dict, new_body) message = (self.gmail_service.users().messages().send(userId="me", body=body).execute()) def test_get_matches(self): match_list = self.emailer.get_matches(self.match_xls, self.address_xls) def test_get_email(self): match_list = self.emailer.get_matches(self.match_xls, self.address_xls) email_add = self.emailer.get_email('Ivy') self.assertEquals(email_add, '*****@*****.**') def test_send(self): pass
from Emailer import Emailer from authenticate import authenticate import pdb # send it try: match_xls = '/Users/jjw036/Dropbox/GSA/LinkLunch/matches_04212015.xlsx' address_xls = '/Users/jjw036/Dropbox/GSA/LinkLunch/individual_info.xlsx' gmail_service = authenticate() emailer = Emailer() matches = emailer.get_matches(match_xls, address_xls) #parse the list of matches #matches is a list of dicts for match in matches: template = emailer.get_template() new_body = emailer.replace_text(match,template) message, body = emailer.get_welcome_email(match,new_body) print(new_body) user_confirmation = raw_input('Send this email? (1 Y/ 2 n/ 3s) ') if float(user_confirmation) == 1: message = (gmail_service.users().messages().send(userId="me", body=body).execute()) print('Message Id: %s' % message['id']) print(message) elif float(user_confirmation) == 2: break elif float(user_confirmation) == 3: