Commits

Atsushi Odagiri committed 08f1c55

wsgiapp for testing on container.

Comments (0)

Files changed (3)

     eggs
 develop =
     src/jsonrpc
+    src/wsgitestapp
 
 [eggs]
 recipe = zc.recipe.egg

src/wsgitestapp/setup.py

+from setuptools import setup
+
+setup(
+    name="wsgitestapp",
+    author="Atsushi Odagiri",
+    author_email="aodagx@gmail.com",
+    description="""
+testing on wsgi application server.
+""",
+    install_requires=[
+        "WebOb",
+        ],
+)

src/wsgitestapp/wsgitestapp.py

+"""
+testing on wsgi application server
+"""
+
+import unittest
+from webob import Request, Response
+
+
+class TestApp(object):
+    def __init__(self, suite):
+        self.suite = suite
+
+    def __call__(self, environ, start_response):
+        request = Request(environ)
+        response = Response(request=request, charset="utf-8")
+        result = unittest.TestResult()
+        self.suite.run(result)
+
+        allSuccess = (len(result.failures) == 0 and len(result.errors) == 0)
+
+        response.body_file.write("""
+<html>
+<head>
+<style>
+body {
+background-color:silver;
+}
+.error {
+color:red;
+}
+.failure {
+color:yellow;
+}
+.description {
+white-space:pre;
+background: white;
+}
+.section {
+    padding:10px;
+    border: 1px solid gray;
+}
+
+.success {
+    padding: 10px;
+    background:blue;
+    color:white;
+}
+.has-failure {
+    padding: 10px;
+    background:red;
+    color:white;
+}
+</style>
+</head>
+<body>
+<div id="result-bar" class="%s">
+""" % ("success" if allSuccess else "has-failure"))
+
+        response.body_file.write("""
+<ul>
+<li>Test Runs: %d
+<li>Errors: %d
+<li>Failures: %d
+</ul>
+</div>
+""" % (result.testsRun, len(result.errors), len(result.failures)))
+
+        for test, err in result.errors:
+            response.body_file.write("""<div class="section">
+<span class="failure">[Failure]</span> %s
+<p class="description">
+%s
+</p>
+</div>""" % (test.id(), err))
+
+        for test, err in result.failures:
+            response.body_file.write("""<div class="section">
+<span class="failure">[Failure]</span> %s
+<p class="description">
+%s
+</p>
+</div>""" % (test.id(), err))
+
+            
+        return response(environ, start_response)