Commit 9d0b61de authored by Grégory Wisniewski's avatar Grégory Wisniewski

Update test runner

- Remove hard-coded mail addresses and smtp server informations.
- Use command line to:
  - select which tests to run
  - define mail sender, recipients and server

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1722 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent a9588cb2
......@@ -21,6 +21,7 @@ import unittest
import tempfile
import logging
import time
import sys
import os
# list of test modules
......@@ -71,15 +72,9 @@ FUNC_TEST_MODULES = [
]
# configuration
UNIT_TESTS = True
FUNCTIONAL_TESTS = True
SEND_REPORT = False
CONSOLE_LOG = False
ATTACH_LOG = False # for ZODB test, only the client side is logged
LOG_FILE = 'neo.log'
SENDER = 'gregory@nexedi.com'
RECIPIENTS = ['gregory@nexedi.com'] #['neo-report@erp5.org']
SMTP_SERVER = ( "mail.nexedi.com", "25")
# override logging configuration to send all messages to a file
logger = logging.getLogger()
......@@ -276,7 +271,7 @@ class NeoTestRunner(unittest.TestResult):
self.errors = self._buildErrors()
self.warnings = self._buildWarnings()
def sendReport(self):
def sendReport(self, smtp_server, sender, recipients):
""" Send a mail with the report summary """
import smtplib
......@@ -286,8 +281,8 @@ class NeoTestRunner(unittest.TestResult):
# build the email
msg = MIMEMultipart()
msg['Subject'] = self.subject
msg['From'] = SENDER
msg['To'] = ', '.join(RECIPIENTS)
msg['From'] = sender
msg['To'] = ', '.join(recipients)
#msg.preamble = self.subject
msg.epilogue = ''
......@@ -306,13 +301,13 @@ class NeoTestRunner(unittest.TestResult):
log.add_header('Content-Disposition', 'attachment', filename=LOG_FILE)
msg.attach(log)
# Send the email via our own SMTP server.
# Send the email via a smtp server
s = smtplib.SMTP()
s.connect(*SMTP_SERVER)
s.connect(*mail_server)
mail = msg.as_string()
for recipient in RECIPIENTS:
for recipient in recipients:
try:
s.sendmail(SENDER, recipient, mail)
s.sendmail(sender, recipient, mail)
except smtplib.SMTPRecipientsRefused, e:
print "Mail for %s fails : %s" % (recipient, e)
s.close()
......@@ -323,25 +318,32 @@ if __name__ == "__main__":
parser = optparse.OptionParser()
parser.add_option('-f', '--functional', action='store_true')
parser.add_option('-u', '--unit', action='store_true')
parser.add_option('', '--recipient', action='append')
parser.add_option('', '--sender')
parser.add_option('', '--server')
(options, args) = parser.parse_args()
if options.functional or options.unit:
# override defaults
FUNCTIONAL_TESTS = options.functional
UNIT_TESTS = options.unit
if not UNIT_TESTS and not FUNCTIONAL_TESTS:
raise RuntimeError('Nothing to run')
# check arguments
if bool(options.sender) ^ bool(options.recipient):
sys.exit('Need a sender and recipients to mail report')
if not (options.unit o options.functional):
sys.exit('Nothing to run, please set -f and/or -u flag')
mail_server = options.server or '127.0.0.1:25'
mail_server = mail_server.split(':')
# run and build the report
# run requested tests
runner = NeoTestRunner()
if UNIT_TESTS:
if options.unit:
runner.run('Unit tests', UNIT_TEST_MODULES)
if FUNCTIONAL_TESTS:
if options.functional:
runner.run('Functional tests', FUNC_TEST_MODULES)
# build report
runner.build()
print runner.errors
print runner.warnings
print runner.summary
# send a mail
if SEND_REPORT:
runner.sendReport()
if options.sender:
runner.sendReport(mail_server, options.sender, options.recipient)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment