Permalink
Browse files

added test documentation in readme and in apptest.py, edited init so …

…that gae mini profiler is loaded inly in development and not in testing, added unittest2 to dependencies
  • Loading branch information...
1 parent c5b53f2 commit 3a47457417580875335f161337f769c362cf30b0 @pawelmhm pawelmhm committed Oct 15, 2013
Showing with 60 additions and 31 deletions.
  1. +30 −0 README.md
  2. +1 −1 requirements_dev.txt
  3. +11 −15 src/application/__init__.py
  4. +18 −15 src/apptest.py
View
@@ -88,6 +88,36 @@ The handy Flask-Cache extension is included, pre-configured for App Engine's Mem
Use the "Flush Cache" button at http://localhost:8000/memcache to clear the cache.
+Testing
+-------
+Place all your tests in src/tests directory. Test runner is placed in src directory. To run your tests simply go to src directory and do:
+
+<pre class="console">
+ python apptest.py path/to/your/googleappengine/installation
+</pre>
+
+Path to your local google app engine installation must be provided as first argument to the script. If the path is long and you don't like to type it each time you run the tests you can also hardcode it in apptest.py, just edit the variable SDK_PATH and set it to your google app engine folder.
+
+Before running tests set evironment variable FLASK_CONF to the value TEST.
+
+In Linux this is done by:
+
+<pre class="console">
+ export FLASK_CONF=TEST
+</pre>
+
+In Powershell:
+
+<pre class="console">
+ [Environment]::SetEnvironmentVariable("FLASK_CONF", "TEST", "User");
+</pre>
+
+Remember to restart Powershell. Change of environment variable will take place after restarting Powershell.
+
+You can specify your testing configuration (e.g. separate database for tests results) in src/application/settings.py.
+
+To switch back to development configuration just set FLASK_CONF to DEV.
+
Deploying the Application
-------------------------
To deploy the application to App Engine, use [appcfg.py update][appcfg]
View
@@ -4,4 +4,4 @@
PIL
jinja2
simplejson
-
+unittest2
@@ -4,37 +4,33 @@
"""
from flask import Flask
import os
-
from flask_debugtoolbar import DebugToolbarExtension
from werkzeug.debug import DebuggedApplication
app = Flask('application')
if os.getenv('FLASK_CONF') == 'DEV':
- #development settings not to be used in production
+ #development settings n
app.config.from_object('application.settings.Development')
# Flask-DebugToolbar (only enabled when DEBUG=True)
toolbar = DebugToolbarExtension(app)
- # Werkzeug Debugger - enabled by default in new versions of Flask
- #if you set debug to true, right?
- # app.wsgi_app = DebuggedApplication(app.wsgi_app, evalex=True)
+
+ # Google app engine mini profiler
+ # https://github.com/kamens/gae_mini_profiler
+ app.wsgi_app = DebuggedApplication(app.wsgi_app, evalex=True)
+
+ from gae_mini_profiler import profiler, templatetags
+ @app.context_processor
+ def inject_profiler():
+ return dict(profiler_includes=templatetags.profiler_includes())
+ app.wsgi_app = profiler.ProfilerWSGIMiddleware(app.wsgi_app)
elif os.getenv('FLASK_CONF') == 'TEST':
app.config.from_object('application.settings.Testing')
else:
app.config.from_object('application.settings.Production')
-# Remember to set SERVER_SOFTWARE environment variable
-# to value "Devel" to use this
-from gae_mini_profiler import profiler, templatetags
-
-@app.context_processor
-def inject_profiler():
- return dict(profiler_includes=templatetags.profiler_includes())
-
-app.wsgi_app = profiler.ProfilerWSGIMiddleware(app.wsgi_app)
-
# Enable jinja2 loop controls extension
app.jinja_env.add_extension('jinja2.ext.loopcontrols')
View
@@ -1,22 +1,20 @@
#!/usr/bin/python
import sys, os
-# Install the Python unittest2 package before you run this script.
import unittest2
-
-# I kept getting waranings complaining that all modules
-# imported by code in application folder are already in the path
-# I'm not sure how to fix this, and this type of warning
-# is not an error, so I just ignore them
-
import warnings
+# silences Python's complaints about imports
warnings.filterwarnings('ignore',category=UserWarning)
USAGE = """
+Path to your sdk must be the first argument. To run type:
$ apptest.py path/to/your/appengine/installation
-Path to your sdk must be the first argument
-
+Remember to set environment variable FLASK_CONF to TEST.
+Loading configuration depending on the value of
+environment variable allows you to add your own
+testing configuration in src/application/settings.py
+
"""
def main(sdk_path, test_path):
@@ -27,10 +25,15 @@ def main(sdk_path, test_path):
suite = unittest2.loader.TestLoader().discover(test_path)
unittest2.TextTestRunner(verbosity=2).run(suite)
+
if __name__ == '__main__':
- #See: http://code.google.com/appengine/docs/python/tools/localunittesting.html
- #Path to the SDK installation
- SDK_PATH = sys.argv[1]#u"/home/pawel/py/plays/appengine/google_appengine/"
- #Path to tests folder
- TEST_PATH = os.path.join(os.path.dirname(os.path.abspath(__name__)),'tests')
- main(SDK_PATH, TEST_PATH)
+ #See: http://code.google.com/appengine/docs/python/tools/localunittesting.html
+ try:
+ #Path to the SDK installation
+ SDK_PATH = sys.argv[1] # ...or hardcoded path
+ #Path to tests folder
+ TEST_PATH = os.path.join(os.path.dirname(os.path.abspath(__name__)),'tests')
+ main(SDK_PATH, TEST_PATH)
+ except IndexError:
+ # you probably forgot about path as first argument
+ print USAGE

0 comments on commit 3a47457

Please sign in to comment.