Permalink
Browse files

Reporting added to tests

  • Loading branch information...
1 parent e0c6cd7 commit 6d15fa9245a53e107ac39cccad4b62204ab8cd38 @AutomatedTester AutomatedTester committed May 31, 2011
Showing with 32 additions and 19 deletions.
  1. +23 −10 garmr.py
  2. +9 −9 test/test_reports.py
View
@@ -67,7 +67,7 @@ def write_results(self, file_name='garmr-results.xml', results=None):
def _format_results(self):
- testcase = """<testcase classname="" name="{testname}" time="{timetaken}">"""
+ testcase = """<testcase classname="" name="{testname}" time="{timetaken}"/>"""
formatted_results = ""
results = {"time_taken":0,
"errors" : 0,
@@ -98,6 +98,7 @@ def __init__(self, urls):
def xframe_checks(self):
result = {}
+ result["name"] = self.xframe_checks.__name__
start = datetime.now()
try:
response = urllib2.urlopen(self.urls)
@@ -111,15 +112,19 @@ def xframe_checks(self):
logger.info("x-frame-options were correct")
except KeyError:
- logger.error("x-frame-options were not found in headers")
- except AssertionError, e:
+ result["failed"] = True
+ logger.critical("x-frame-options were not found in headers")
+ except AssertionError as e:
logger.error(str(e))
+ result["errors"] = True
finish = datetime.now()
result["time_taken"] = self._total_seconds(start, finish)
logger.debug("Time Taken: %s:" % result["time_taken"])
+ return result
def trace_checks(self):
result = {}
+ result["name"] = self.trace_checks.__name__
start = datetime.now()
try:
logger.info("Checking TRACE is not valid")
@@ -133,16 +138,19 @@ def trace_checks(self):
request.getresponse()
raise Exception("TRACE is a valid HTTP call")
except httplib.BadStatusLine, e:
- logger.error("TRACE is not valid")
+ logger.info("TRACE is not valid")
except Exception, e:
logger.error(str(e))
+ result["errors"] = True
finish = datetime.now()
result["time_taken"] = self._total_seconds(start, finish)
logger.debug("Time Taken: %s:" % result["time_taken"])
+ return result
def redirect_checks(self):
result = {}
+ result["name"] = self.redirect_checks.__name__
start = datetime.now()
response = urllib2.urlopen(self.urls)
try:
@@ -151,9 +159,11 @@ def redirect_checks(self):
logger.info("Redirected to HTTPS version of site")
except AssertionError, e:
logger.error(str(e))
+ result["errors"] = True
finish = datetime.now()
result["time_taken"] = self._total_seconds(start, finish)
logger.debug("Time Taken: %s:" % result["time_taken"])
+ return result
def _clean_header(self, response_headers):
headers = {}
@@ -172,7 +182,7 @@ def _clean_url(self, urls):
def _total_seconds(self, start, finish):
td = finish - start
- return (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6
+ return float((td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6)) / 10**6
def main():
usage = "Usage: %prog [option] arg"
@@ -183,18 +193,21 @@ def main():
dest="file_name",
help="File name with URLS to test, Currently not available")
parser.add_option("-x", "--xunit", action="store", type="string",
- dest="xunit",
+ dest="xunit", default='garmr-results.xml',
help="Name of file that you wish to write to")
(options, args) = parser.parse_args()
if options.aut is None and options.file_name is None:
parser.error("Please supply an argument")
- garmr = Garmr(options.aut)
- garmr.trace_checks()
- garmr.xframe_checks()
- garmr.redirect_checks()
+ test_results = []
+ garmr = Garmr(options.aut)
+ test_results.append(garmr.trace_checks())
+ test_results.append(garmr.xframe_checks())
+ test_results.append(garmr.redirect_checks())
+ reporter = Reporter(test_results)
+ reporter.write_results(file_name=options.xunit)
if __name__ == "__main__":
main()
View
@@ -24,7 +24,7 @@ def test_reporter_formats_test_cases_with_no_errors_or_failures(self):
})
reporter = Reporter(tests_list)
result = reporter._format_results()
- assert result["testcase"] == """<testcase classname="" name="%s" time="%s">""" % \
+ assert result["testcase"] == """<testcase classname="" name="%s" time="%s"/>""" % \
(tests_list[0]["name"], tests_list[0]["time_taken"])
assert result["time_taken"] == 1
assert result["errors"] == 0
@@ -41,9 +41,9 @@ def test_reporter_formats_2_test_cases_with_no_errors_or_failures(self):
})
reporter = Reporter(tests_list)
result = reporter._format_results()
- expected = """<testcase classname="" name="%s" time="%s">""" % \
+ expected = """<testcase classname="" name="%s" time="%s"/>""" % \
(tests_list[0]["name"], tests_list[0]["time_taken"])
- expected += """<testcase classname="" name="%s" time="%s">""" % \
+ expected += """<testcase classname="" name="%s" time="%s"/>""" % \
(tests_list[1]["name"], tests_list[1]["time_taken"])
assert result["testcase"] == expected, result["testcase"]
assert result["time_taken"] == 2
@@ -64,9 +64,9 @@ def test_reporter_formats_2_test_cases_with_mix_of_errors_or_failures(self):
})
reporter = Reporter(tests_list)
result = reporter._format_results()
- expected = """<testcase classname="" name="%s" time="%s">""" % \
+ expected = """<testcase classname="" name="%s" time="%s"/>""" % \
(tests_list[0]["name"], tests_list[0]["time_taken"])
- expected += """<testcase classname="" name="%s" time="%s">""" % \
+ expected += """<testcase classname="" name="%s" time="%s"/>""" % \
(tests_list[1]["name"], tests_list[1]["time_taken"])
assert result["testcase"] == expected, result["testcase"]
assert result["time_taken"] == 2
@@ -82,7 +82,7 @@ def test_reporter_formats_test_case_with_one_failure(self):
})
reporter = Reporter(tests_list)
result = reporter._format_results()
- assert result["testcase"] == """<testcase classname="" name="%s" time="%s">""" % \
+ assert result["testcase"] == """<testcase classname="" name="%s" time="%s"/>""" % \
(tests_list[0]["name"], tests_list[0]["time_taken"])
assert result["time_taken"] == 1
assert result["errors"] == 0
@@ -97,7 +97,7 @@ def test_reporter_formats_test_case_with_error(self):
})
reporter = Reporter(tests_list)
result = reporter._format_results()
- assert result["testcase"] == """<testcase classname="" name="%s" time="%s">""" % \
+ assert result["testcase"] == """<testcase classname="" name="%s" time="%s"/>""" % \
(tests_list[0]["name"], tests_list[0]["time_taken"])
assert result["time_taken"] == 1
assert result["errors"] == 1
@@ -112,7 +112,7 @@ def test_reporter_formats_test_case_with_skip(self):
})
reporter = Reporter(tests_list)
result = reporter._format_results()
- assert result["testcase"] == """<testcase classname="" name="%s" time="%s">""" % \
+ assert result["testcase"] == """<testcase classname="" name="%s" time="%s"/>""" % \
(tests_list[0]["name"], tests_list[0]["time_taken"])
assert result["time_taken"] == 1
assert result["errors"] == 0
@@ -129,7 +129,7 @@ def test_that_reporter_writes_to_disk(self):
skips="{skips}" tests="{numtests}" time="{timetaken}">
{testresults}
</testsuite>"""
- testcase = """<testcase classname="" name="%s" time="%s">""" % \
+ testcase = """<testcase classname="" name="%s" time="%s"/>""" % \
(tests_list[0]["name"], tests_list[0]["time_taken"])
expected = suite_xml.format(error=0, failure=0, skips=0, numtests=len(tests_list),

0 comments on commit 6d15fa9

Please sign in to comment.