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 ...@@ -21,6 +21,7 @@ import unittest
import tempfile import tempfile
import logging import logging
import time import time
import sys
import os import os
# list of test modules # list of test modules
...@@ -71,15 +72,9 @@ FUNC_TEST_MODULES = [ ...@@ -71,15 +72,9 @@ FUNC_TEST_MODULES = [
] ]
# configuration # configuration
UNIT_TESTS = True
FUNCTIONAL_TESTS = True
SEND_REPORT = False
CONSOLE_LOG = False CONSOLE_LOG = False
ATTACH_LOG = False # for ZODB test, only the client side is logged ATTACH_LOG = False # for ZODB test, only the client side is logged
LOG_FILE = 'neo.log' 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 # override logging configuration to send all messages to a file
logger = logging.getLogger() logger = logging.getLogger()
...@@ -276,7 +271,7 @@ class NeoTestRunner(unittest.TestResult): ...@@ -276,7 +271,7 @@ class NeoTestRunner(unittest.TestResult):
self.errors = self._buildErrors() self.errors = self._buildErrors()
self.warnings = self._buildWarnings() self.warnings = self._buildWarnings()
def sendReport(self): def sendReport(self, smtp_server, sender, recipients):
""" Send a mail with the report summary """ """ Send a mail with the report summary """
import smtplib import smtplib
...@@ -286,8 +281,8 @@ class NeoTestRunner(unittest.TestResult): ...@@ -286,8 +281,8 @@ class NeoTestRunner(unittest.TestResult):
# build the email # build the email
msg = MIMEMultipart() msg = MIMEMultipart()
msg['Subject'] = self.subject msg['Subject'] = self.subject
msg['From'] = SENDER msg['From'] = sender
msg['To'] = ', '.join(RECIPIENTS) msg['To'] = ', '.join(recipients)
#msg.preamble = self.subject #msg.preamble = self.subject
msg.epilogue = '' msg.epilogue = ''
...@@ -306,13 +301,13 @@ class NeoTestRunner(unittest.TestResult): ...@@ -306,13 +301,13 @@ class NeoTestRunner(unittest.TestResult):
log.add_header('Content-Disposition', 'attachment', filename=LOG_FILE) log.add_header('Content-Disposition', 'attachment', filename=LOG_FILE)
msg.attach(log) msg.attach(log)
# Send the email via our own SMTP server. # Send the email via a smtp server
s = smtplib.SMTP() s = smtplib.SMTP()
s.connect(*SMTP_SERVER) s.connect(*mail_server)
mail = msg.as_string() mail = msg.as_string()
for recipient in RECIPIENTS: for recipient in recipients:
try: try:
s.sendmail(SENDER, recipient, mail) s.sendmail(sender, recipient, mail)
except smtplib.SMTPRecipientsRefused, e: except smtplib.SMTPRecipientsRefused, e:
print "Mail for %s fails : %s" % (recipient, e) print "Mail for %s fails : %s" % (recipient, e)
s.close() s.close()
...@@ -323,25 +318,32 @@ if __name__ == "__main__": ...@@ -323,25 +318,32 @@ if __name__ == "__main__":
parser = optparse.OptionParser() parser = optparse.OptionParser()
parser.add_option('-f', '--functional', action='store_true') parser.add_option('-f', '--functional', action='store_true')
parser.add_option('-u', '--unit', 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() (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: # check arguments
raise RuntimeError('Nothing to run') 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() runner = NeoTestRunner()
if UNIT_TESTS: if options.unit:
runner.run('Unit tests', UNIT_TEST_MODULES) runner.run('Unit tests', UNIT_TEST_MODULES)
if FUNCTIONAL_TESTS: if options.functional:
runner.run('Functional tests', FUNC_TEST_MODULES) runner.run('Functional tests', FUNC_TEST_MODULES)
# build report
runner.build() runner.build()
print runner.errors print runner.errors
print runner.warnings print runner.warnings
print runner.summary print runner.summary
# send a mail # send a mail
if SEND_REPORT: if options.sender:
runner.sendReport() 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