From a4bbdb4f81f289e667e2b08ffd6ee0eefb33800a Mon Sep 17 00:00:00 2001 From: debugtalk Date: Wed, 2 Aug 2017 23:37:23 +0800 Subject: [PATCH] add jenkins-mail-py to support mail test result --- README.md | 42 ++++++++++++++++++++++++++++++++++++------ ate/__init__.py | 2 +- ate/cli.py | 9 +++++++++ requirements_dev.txt | 1 + setup.py | 8 +++++--- 5 files changed, 52 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 90910477..e01d9b2a 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Take full reuse of Python's existing powerful libraries: [`Requests`][requests], - Supports `function`/`variable`/`extract`/`validate` mechanisms to create full test scenarios. - Testcases can be run in diverse ways, with single testset, multiple testsets, or entire project folder. - Test report is concise and clear, with detailed log records. See [`PyUnitReport`][PyUnitReport]. -- Perfect combination with [Jenkins][Jenkins], running continuous integration test and production environment monitoring. +- Perfect combination with [Jenkins][Jenkins], running continuous integration test and production environment monitoring. Send mail notification with [`jenkins-mail-py`][jenkins-mail-py]. - With reuse of [`Locust`][Locust], you can run performance test without extra work. - It is extensible to facilitate the implementation of web platform with [`Flask`][flask] framework. @@ -38,16 +38,21 @@ To ensure the installation or upgrade is successful, you can execute command `at ```text $ ate -V -0.3.0 +0.3.1 ``` Execute the command `ate -h` to view command help. ```text $ ate -h -usage: main.py [-h] [-V] [--log-level LOG_LEVEL] [--report-name REPORT_NAME] - [--failfast] - [testset_paths [testset_paths ...]] +usage: ate [-h] [-V] [--log-level LOG_LEVEL] [--report-name REPORT_NAME] + [--failfast] [--mailgun-api-id MAILGUN_API_ID] + [--mailgun-api-key MAILGUN_API_KEY] [--email-sender EMAIL_SENDER] + [--email-recepients EMAIL_RECEPIENTS] [--mail-subject MAIL_SUBJECT] + [--mail-content MAIL_CONTENT] [--jenkins-job-name JENKINS_JOB_NAME] + [--jenkins-job-url JENKINS_JOB_URL] + [--jenkins-build-number JENKINS_BUILD_NUMBER] + [testset_paths [testset_paths ...]] Api Test Engine. @@ -62,6 +67,24 @@ optional arguments: --report-name REPORT_NAME Specify report name, default is generated time. --failfast Stop the test run on the first error or failure. + --mailgun-api-id MAILGUN_API_ID + Specify mailgun api id. + --mailgun-api-key MAILGUN_API_KEY + Specify mailgun api key. + --email-sender EMAIL_SENDER + Specify email sender. + --email-recepients EMAIL_RECEPIENTS + Specify email recepients. + --mail-subject MAIL_SUBJECT + Specify email subject. + --mail-content MAIL_CONTENT + Specify email content. + --jenkins-job-name JENKINS_JOB_NAME + Specify jenkins job name. + --jenkins-job-url JENKINS_JOB_URL + Specify jenkins job url. + --jenkins-build-number JENKINS_BUILD_NUMBER + Specify jenkins build number. ``` ## Write testcases @@ -143,6 +166,12 @@ If you want to run testsets of a whole project, you can achieve this goal by spe $ ate testcases_folder_path ``` +When you do continuous integration test or production environment monitoring with `Jenkins`, you may need to send test result notification. For instance, you can send email with mailgun service as below. + +```text +$ ate filepath/testcase.yml --mailgun-api-id samples.mailgun.org --mailgun-api-key key-3ax6xnjp29jd6fds4gc373sgvjxteol0 --email-sender excited@samples.mailgun.org --email-recepients test@email.com --jenkins-job-name demo-smoketest --jenkins-job-url http://test.debugtalk.com/job/demo-smoketest/ --jenkins-build-number 69 +``` + ## Supported Python Versions Python `2.7`, `3.3`, `3.4`, `3.5`, and `3.6`. @@ -162,4 +191,5 @@ Python `2.7`, `3.3`, `3.4`, `3.5`, and `3.6`. [Locust]: http://locust.io/ [flask]: http://flask.pocoo.org/ [PyUnitReport]: https://github.com/debugtalk/PyUnitReport -[Jenkins]: https://jenkins.io/index.html \ No newline at end of file +[Jenkins]: https://jenkins.io/index.html +[jenkins-mail-py]: https://github.com/debugtalk/jenkins-mail-py.git \ No newline at end of file diff --git a/ate/__init__.py b/ate/__init__.py index 290d7c60..9c5adf70 100644 --- a/ate/__init__.py +++ b/ate/__init__.py @@ -1 +1 @@ -__version__ = '0.3.0' \ No newline at end of file +__version__ = '0.3.1' \ No newline at end of file diff --git a/ate/cli.py b/ate/cli.py index a06a5999..0609e2be 100644 --- a/ate/cli.py +++ b/ate/cli.py @@ -28,6 +28,12 @@ def main(): '--failfast', action='store_true', default=False, help="Stop the test run on the first error or failure.") + try: + from jenkins_mail_py import MailgunHelper + mailer = MailgunHelper(parser) + except ImportError: + mailer = None + args = parser.parse_args() if args.version: @@ -69,4 +75,7 @@ def main(): if len(result.successes) != result.testsRun: flag = "FAILED" + if mailer and mailer.config_ready: + mailer.send_mail(flag, content=results) + return flag, results diff --git a/requirements_dev.txt b/requirements_dev.txt index a6e5169a..0b2c72d8 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -4,3 +4,4 @@ PyYAML coveralls coverage -e git+https://github.com/debugtalk/PyUnitReport.git#egg=PyUnitReport +-e git+https://github.com/debugtalk/jenkins-mail-py.git#egg=jenkins-mail-py diff --git a/setup.py b/setup.py index 721d1f1b..885f8d04 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ with open('README.md') as f: setup( name='ApiTestEngine', version=version, - description='An API test engine.', + description='API test engine.', long_description=long_description, author='Leo Lee', author_email='mail@debugtalk.com', @@ -27,10 +27,12 @@ setup( "PyYAML", "coveralls", "coverage", - "PyUnitReport" + "PyUnitReport", + "jenkins-mail-py" ], dependency_links=[ - "git+https://github.com/debugtalk/PyUnitReport.git#egg=PyUnitReport" + "git+https://github.com/debugtalk/PyUnitReport.git#egg=PyUnitReport", + "git+https://github.com/debugtalk/jenkins-mail-py.git#egg=jenkins-mail-py" ], classifiers=[ "Development Status :: 3 - Alpha",