Anonymous avatar Anonymous committed 9513beb

test changes

Comments (0)

Files changed (4)

newsmeme/application.py

 from flaskext.principal import Principal, identity_loaded
 
 from newsmeme import helpers
+from newsmeme import views
 from newsmeme.config import DefaultConfig
 from newsmeme.models import User, Tag
 from newsmeme.helpers import render_template
 
 DEFAULT_APP_NAME = "newsmeme"
 
-def create_app(config=None, app_name=None):
+DEFAULT_MODULES = (
+    (views.frontend, ""),
+    (views.post, "/post"),
+    (views.user, "/user"),
+    (views.comment, "/comment"),
+    (views.account, "/acct"),
+    (views.feeds, "/feeds"),
+    (views.openid, "/openid"),
+    (views.api, "/api"),
+)
+
+def create_app(config=None, app_name=None, modules=None):
 
     if app_name is None:
         app_name = DEFAULT_APP_NAME
 
+    if modules is None:
+        modules = DEFAULT_MODULES
+
     app = Flask(app_name)
 
     configure_app(app, config)
     configure_errorhandlers(app)
     configure_extensions(app)
     configure_before_handlers(app)
-    configure_filters(app)
+    configure_template_filters(app)
     configure_context_processors(app)
     # configure_after_handlers(app)
-    configure_modules(app)
+    configure_modules(app, modules)
 
     return app
 
     app.config.from_envvar('APP_CONFIG', silent=True)
 
 
-def configure_modules(app):
+def configure_modules(app, modules):
     
-    for module, url_prefix in app.config['MODULES']:
+    for module, url_prefix in modules:
         app.register_module(module, url_prefix=url_prefix)
 
 
-def configure_filters(app):
+def configure_template_filters(app):
 
     @app.template_filter()
     def timesince(value):

newsmeme/config.py

     CACHE_TYPE = "simple"
     CACHE_DEFAULT_TIMEOUT = 300
 
-    MODULES = (
-        (views.frontend, ""),
-        (views.post, "/post"),
-        (views.user, "/user"),
-        (views.comment, "/comment"),
-        (views.account, "/acct"),
-        (views.feeds, "/feeds"),
-        (views.openid, "/openid"),
-        (views.api, "/api"),
-    )
 
+class TestConfig(object):
 
+    TESTING = True
+    CSRF_ENABLED = False
+    SQLALCHEMY_DATABASE_URI = "sqlite://"
+    SQLALCHEMY_ECHO = False
+
+
+
+

tests/__init__.py

     :license: BSD, see LICENSE for more details.
 """
 from flask import g
-from flaskext.testing import TestCase as _TestCase
+from flaskext.testing import TestCase as Base, Twill
 from flaskext.principal import identity_changed, Identity, AnonymousIdentity
 
 from newsmeme import create_app
+from newsmeme.config import TestConfig
 from newsmeme.models import User, Post, Comment
 from newsmeme.extensions import db
 
-class TestCase(_TestCase):
+class TestCase(Base):
     
     """
     Base TestClass for your application.
     """
 
-    TESTING = True
-    CSRF_ENABLED = False
-    SQLALCHEMY_DATABASE_URI = "sqlite://"
-    SQLALCHEMY_ECHO = False
-
     def create_app(self):
-        return create_app(self)
+        app = create_app(TestConfig())
+        self.twill = Twill(app, port=3000)
+        return app
     
     def setUp(self):
         db.create_all()

tests/test_views.py

         self.assert_200(response)
  
     def test_index(self):
-
+        
         response = self.client.get("/")
         self.assert_200(response)
         
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.