Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

email_client.py - formatted strings #539

Merged
merged 2 commits into from
Aug 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/email_report/email_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ def __init__(self):

@staticmethod
def create_email_subject(target):
email_info = '[%s][%s]Iris Test Report %s' % (
target.target_name+" "+str(target.values['fx_version']) if target.target_name == 'Firefox'
else target.target_name, OSHelper.get_os_version().capitalize(), date.today())
os_version = OSHelper.get_os_version().capitalize()
date_today = date.today()
email_info = '[{}][{}]Iris Test Report {}'.format('{} {}'.format(target.target_name, target.values['fx_version']) if target.target_name == 'Firefox'
else target.target_name, os_version, date_today)
return email_info

@staticmethod
Expand All @@ -50,18 +51,22 @@ def get_file_attachment():
filename=os.path.basename(test_report_file))
return attachment
else:
raise Exception('File %s is not present in path' % test_report_file)
raise Exception('File {} is not present in path'.format(test_report_file))

def send_email_report(self, target: str, test_status: str, repo_details: str):
email = MIMEMultipart()
body_message = ""
if isinstance(repo_details, dict):
body_message = MIMEText(
''' Repo_details:\n ''' + """Branch_name:""" + repo_details.get(
'iris_branch')
+ " \n " + '''Branch_head: ''' + repo_details.get(
'iris_branch_head') + "\n\n" + '''Test_Run_Details: ''' + test_status +
''' \nNote: To see the complete run output, please check the attachment.''')
body_message = MIMEText((
' Repo_details:\n'
' Branch_name: {}\n'
' Branch_head: {}\n'
' Test_Run_Details: {}\n'
' Note: To see the complete run output, please check the attachment.'.format(
repo_details.get('iris_branch'),
repo_details.get('iris_branch_head'),
test_status)
))
else:
raise EmailError("Invalid Body Message")

Expand Down Expand Up @@ -89,7 +94,7 @@ def send_email_report(self, target: str, test_status: str, repo_details: str):
raise EmailError("Email was not sent. Please check for iris_log.log file.")
else:
server.quit()
logger.info('Email successfully sent to %s' % self.targets)
logger.info('Email successfully sent to {}'.format(self.targets))


def submit_email_report(target, result):
Expand Down