changeset 4441:f02b3e7dffe6

fixed wsgiapplication tests factored the wsgi application to a configurable class added correct config passing
author Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
date Sat, 27 Dec 2008 19:03:30 +0100
parents ec62380ae400
children 39109af9ac90
files MoinMoin/_tests/test_wsgiapp.py MoinMoin/conftest.py MoinMoin/wsgiapp.py
diffstat 3 files changed, 31 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_wsgiapp.py	Mon Dec 29 02:09:32 2008 +0100
+++ b/MoinMoin/_tests/test_wsgiapp.py	Sat Dec 27 19:03:30 2008 +0100
@@ -12,6 +12,7 @@
 DOC_TYPE = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
 
 class TestApplication:
+    # self.client is made by conftest
 
     # These should exist
     PAGES = ('FrontPage', 'RecentChanges', 'HelpContents', 'FindPage')
@@ -20,19 +21,19 @@
 
     def testWSGIAppExisting(self):
         for page in self.PAGES:
-            def _test_():
+            def _test_(page=page):
                 appiter, status, headers = self.client.get('/%s' % page)
-                print repr(list(appiter))
+                output = ''.join(appiter)
+                print output
                 assert status[:3] == '200'
                 assert ('Content-Type', 'text/html; charset=utf-8') in headers
-                output = ''.join(appiter)
                 for needle in (DOC_TYPE, page):
                     assert needle in output
             yield _test_
 
     def testWSGIAppAbsent(self):
         for page in self.NO_PAGES:
-            def _test_():
+            def _test_(page=page):
                 appiter, status, headers = self.client.get('/%s' % page)
                 assert status[:3] == '404'
                 output = ''.join(appiter)
--- a/MoinMoin/conftest.py	Mon Dec 29 02:09:32 2008 +0100
+++ b/MoinMoin/conftest.py	Sat Dec 27 19:03:30 2008 +0100
@@ -31,7 +31,7 @@
 
 from MoinMoin.support.python_compatibility import set
 from MoinMoin.web.request import TestRequest, Client
-from MoinMoin.wsgiapp import application, init
+from MoinMoin.wsgiapp import Application, init
 from MoinMoin._tests import maketestwiki, wikiconfig
 
 coverage_modules = set()
@@ -94,9 +94,12 @@
         cls = self.obj
         if hasattr(cls, 'Config'):
             cls.request = init_test_request(given_config=cls.Config)
+            cls.client = Client(Application(cls.Config))
         else:
             cls.request = self.parent.request
-        cls.client = Client(application)
+            #XXX: this is the extremely messy way to configure the wsgi app
+            #     with the correct testing config
+            cls.client = Client(Application(self.parent.request.cfg.__class__))
         super(MoinClassCollector, self).setup()
 
 
--- a/MoinMoin/wsgiapp.py	Mon Dec 29 02:09:32 2008 +0100
+++ b/MoinMoin/wsgiapp.py	Sat Dec 27 19:03:30 2008 +0100
@@ -230,16 +230,26 @@
     else:
         return context.lang
 
-def application(environ, start_response):
-    try:
-        request = Request(environ)
-        context = init(request)
-        response = run(context)
-        context.clock.stop('total')
-    except HTTPException, e:
-        response = e
-    except error.ConfigurationError, e:
-        response = fatal_response(e)
+class Application(object):
+    def __init__(self, app_config=None):
 
-    return response(environ, start_response)
+        class AppRequest(Request):
+            given_config = app_config
 
+        self.Request = AppRequest
+
+    def __call__(self, environ, start_response):
+        try:
+            request = self.Request(environ)
+            context = init(request)
+            response = run(context)
+            context.clock.stop('total')
+        except HTTPException, e:
+            response = e
+        except error.ConfigurationError, e:
+            response = fatal_response(e)
+
+        return response(environ, start_response)
+
+#XXX: default application using the default config from disk
+application = Application()