Skip to content

Commit

Permalink
Merge pull request #630 from karandesai-96/dokuwiki-overview-page
Browse files Browse the repository at this point in the history
[IntegrationTests] Overview page on Dokuwiki.

Running the integration tests will update an overview page on DokuWiki.
  • Loading branch information
yeganer authored Aug 3, 2016
2 parents 37e480a + f323b21 commit 3e55c13
Showing 1 changed file with 54 additions and 10 deletions.
64 changes: 54 additions & 10 deletions tardis/tests/integration_tests/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
3. "pytest-html" ( https://www.github.com/davehunt/pytest-html )
"""
import datetime
import pkg_resources
import json
import os
import pkg_resources
import time

# For specifying error while exception handling
Expand All @@ -39,8 +40,10 @@

try:
import dokuwiki
import requests
except ImportError:
dokuwiki = None
requests = None


class DokuReport(HTMLReport):
Expand Down Expand Up @@ -68,13 +71,11 @@ def __init__(self, dokuwiki_details):
self.dokuwiki_url = dokuwiki_details["url"]

def _generate_report(self, session):
"""
The method writes HTML report to a temporary logfile.
"""
"""Writes HTML report to a temporary logfile."""
suite_stop_time = time.time()
suite_time_delta = suite_stop_time - self.suite_start_time
self.suite_time_delta = suite_stop_time - self.suite_start_time
numtests = self.passed + self.failed + self.xpassed + self.xfailed
generated = datetime.datetime.now()
generated = datetime.datetime.utcnow()

style_css = pkg_resources.resource_string(
pytest_html_path, os.path.join('resources', 'style.css'))
Expand All @@ -86,7 +87,7 @@ def _generate_report(self, session):

summary = [html.h2('Summary'), html.p(
'{0} tests ran in {1:.2f} seconds.'.format(
numtests, suite_time_delta),
numtests, self.suite_time_delta),
html.br(),
html.span('{0} passed'.format(
self.passed), class_='passed'), ', ',
Expand Down Expand Up @@ -154,23 +155,66 @@ def _generate_report(self, session):

def _save_report(self, report_content):
"""
The method uploads the report and closes the temporary file. Temporary
file is made using `tempfile` built-in module, it gets deleted upon
closing.
Uploads the report and closes the temporary file. Temporary file is
made using `tempfile` built-in module, it gets deleted upon closing.
"""
try:
self.doku_conn.pages.set("reports:{0}".format(
tardis.__githash__[:7]), report_content)
except (gaierror, TypeError):
pass

def _wiki_overview_entry(self):
"""Makes an entry of current test run on overview page of dokuwiki."""
if self.errors == 0:
if self.failed + self.xpassed == 0:
status = "Passed"
else:
status = "Failed"
else:
status = "Errored"

suite_start_datetime = datetime.datetime.utcfromtimestamp(self.suite_start_time)

# Fetch commit message from github.
gh_request = requests.get(
"https://api.github.com/repos/tardis-sn/tardis/git/commits/{0}".format(
tardis.__githash__
)
)
gh_commit_data = json.loads(gh_request.content)
# Pick only first line of commit message
gh_commit_message = gh_commit_data['message'].split('\n')[0]

# Truncate long commit messages
if len(gh_commit_message) > 60:
gh_commit_message = "{0}...".format(gh_commit_message[:57])
row = "| "
# Append hash
row += "[[reports:{0}|{0}]] | ".format(tardis.__githash__[:7])
# Append commit message
row += "[[https://www.github.com/tardis-sn/tardis/commit/{0}|{1}]] | ".format(
tardis.__githash__, gh_commit_message
)
# Append start time
row += "{0} | ".format(suite_start_datetime.strftime('%d %b %H:%M:%S'))
# Append time elapsed
row += "{0:.2f} sec | ".format(self.suite_time_delta)
# Append status
row += "{0} |\n".format(status)
try:
self.doku_conn.pages.append('/', row)
except (gaierror, TypeError):
pass

def pytest_sessionfinish(self, session):
"""
This hook function is called by pytest when whole test run is completed.
It calls the two helper methods `_generate_report` and `_save_report`.
"""
report_content = self._generate_report(session)
self._save_report(report_content)
self._wiki_overview_entry()

def pytest_terminal_summary(self, terminalreporter):
"""
Expand Down

0 comments on commit 3e55c13

Please sign in to comment.