Commits

danjac  committed 00855a4

added module tests

  • Participants
  • Parent commits 9a59b0a
  • Branches alfajor-integration

Comments (0)

Files changed (1)

File flaskext/testing.py

            
 class _TestModule(object):
 
-    def __init__(self, parent=None):
+    def __init__(self, app=None, parent=None):
 
+        self._app = app
         self._parent = parent
         self._setup_funcs = []
         self._teardown_funcs = []
 
     def teardown(self, func):
         self._teardown_funcs.append(func)
-        return func
-
-    def create_app(self):
-        raise NotImplementedError, "app must be created by parent"
 
     def with_context(self, func):
 
         @functools.wraps(func)
         def decorate():
 
-            if self._parent:
-                app = self._parent.create_app()
-            else:
-                app = self.create_app()
+            app = self._app or self._parent._app
+            if app is None:
+                raise RuntimeError, "No app instance passed"
 
             _app_ctx = app.test_request_context()
             _app_ctx.push()
             
 
     """
-    def __init__(self, app):
+    def __init__(self, app=None):
         
-        self.init_app(app)
-
         super(Testing, self).__init__()
+   
+        if app:
+            self.init_app(app)
 
     def init_app(self, app):
 
-        if isinstance(app, Flask):
-            self.create_app = lambda: app
-
-        else:
-            self.create_app = app
+        self._app = app
 
     def register_module(self):
-        return _TestModule(self)
+        return _TestModule(parent=self)
 
 # old unit-test based classes, for backward compatibility