diff --git a/Flask_Testing.egg-info/PKG-INFO b/Flask_Testing.egg-info/PKG-INFO new file mode 100644 index 0000000..e81d7f0 --- /dev/null +++ b/Flask_Testing.egg-info/PKG-INFO @@ -0,0 +1,31 @@ +Metadata-Version: 1.1 +Name: Flask-Testing +Version: 0.4.2 +Summary: Unit testing for Flask +Home-page: https://github.com/jarus/flask-testing +Author: Dan Jacob +Author-email: danjac354@gmail.com +License: BSD +Description: + Flask-Testing + ------------- + + Flask unittest integration. + + Links + ````` + + * `documentation ` + * `development version ` + + +Platform: any +Classifier: Development Status :: 4 - Beta +Classifier: Environment :: Web Environment +Classifier: Intended Audience :: Developers +Classifier: License :: OSI Approved :: BSD License +Classifier: Operating System :: OS Independent +Classifier: Programming Language :: Python +Classifier: Programming Language :: Python :: 3 +Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content +Classifier: Topic :: Software Development :: Libraries :: Python Modules diff --git a/Flask_Testing.egg-info/SOURCES.txt b/Flask_Testing.egg-info/SOURCES.txt new file mode 100644 index 0000000..d46b299 --- /dev/null +++ b/Flask_Testing.egg-info/SOURCES.txt @@ -0,0 +1,33 @@ +LICENSE +MANIFEST.in +README +setup.py +Flask_Testing.egg-info/PKG-INFO +Flask_Testing.egg-info/SOURCES.txt +Flask_Testing.egg-info/dependency_links.txt +Flask_Testing.egg-info/not-zip-safe +Flask_Testing.egg-info/requires.txt +Flask_Testing.egg-info/top_level.txt +docs/.DS_Store +docs/Makefile +docs/conf.py +docs/index.rst +docs/make.bat +docs/_static/flask-testing.png +docs/_themes/README +docs/_themes/flask_theme_support.py +docs/_themes/flask/theme.conf +docs/_themes/flask/static/flasky.css_t +docs/_themes/flask_small/layout.html +docs/_themes/flask_small/theme.conf +docs/_themes/flask_small/static/flasky.css_t +flask_testing/__init__.py +flask_testing/twill.py +flask_testing/utils.py +tests/__init__.py +tests/__main__.py +tests/run.py +tests/test_twill.py +tests/test_utils.py +tests/flask_app/__init__.py +tests/flask_app/templates/index.html \ No newline at end of file diff --git a/Flask_Testing.egg-info/dependency_links.txt b/Flask_Testing.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Flask_Testing.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/Flask_Testing.egg-info/not-zip-safe b/Flask_Testing.egg-info/not-zip-safe new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Flask_Testing.egg-info/not-zip-safe @@ -0,0 +1 @@ + diff --git a/Flask_Testing.egg-info/requires.txt b/Flask_Testing.egg-info/requires.txt new file mode 100644 index 0000000..2077213 --- /dev/null +++ b/Flask_Testing.egg-info/requires.txt @@ -0,0 +1 @@ +Flask \ No newline at end of file diff --git a/Flask_Testing.egg-info/top_level.txt b/Flask_Testing.egg-info/top_level.txt new file mode 100644 index 0000000..99bde78 --- /dev/null +++ b/Flask_Testing.egg-info/top_level.txt @@ -0,0 +1 @@ +flask_testing diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..00199ae --- /dev/null +++ b/LICENSE @@ -0,0 +1,31 @@ +Copyright (c) 2010 by Dan Jacob. + +Some rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +* Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + +* The names of the contributors may not be used to endorse or + promote products derived from this software without specific + prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..6881781 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,9 @@ +include LICENSE +recursive-include tests * +recursive-exclude tests *.pyc +recursive-exclude tests *.pyc +recursive-include docs * +recursive-exclude docs *.pyc +recursive-exclude docs *.pyo +prune docs/_build +prune docs/_themes/.git diff --git a/PKG-INFO b/PKG-INFO new file mode 100644 index 0000000..e81d7f0 --- /dev/null +++ b/PKG-INFO @@ -0,0 +1,31 @@ +Metadata-Version: 1.1 +Name: Flask-Testing +Version: 0.4.2 +Summary: Unit testing for Flask +Home-page: https://github.com/jarus/flask-testing +Author: Dan Jacob +Author-email: danjac354@gmail.com +License: BSD +Description: + Flask-Testing + ------------- + + Flask unittest integration. + + Links + ````` + + * `documentation ` + * `development version ` + + +Platform: any +Classifier: Development Status :: 4 - Beta +Classifier: Environment :: Web Environment +Classifier: Intended Audience :: Developers +Classifier: License :: OSI Approved :: BSD License +Classifier: Operating System :: OS Independent +Classifier: Programming Language :: Python +Classifier: Programming Language :: Python :: 3 +Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content +Classifier: Topic :: Software Development :: Libraries :: Python Modules diff --git a/README b/README new file mode 100644 index 0000000..1e73046 --- /dev/null +++ b/README @@ -0,0 +1,7 @@ +Flask-Testing + +Unit testing support for Flask. + +For full information please refer to the online docs: + +http://packages.python.org/Flask-Testing diff --git a/docs/.DS_Store b/docs/.DS_Store new file mode 100644 index 0000000..214067b Binary files /dev/null and b/docs/.DS_Store differ diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..8e9f867 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,130 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = _build + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest + +help: + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + +clean: + -rm -rf $(BUILDDIR)/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/flask-unittest.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/flask-unittest.qhc" + +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/flask-unittest" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/flask-unittest" + @echo "# devhelp" + +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + make -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." diff --git a/docs/_static/flask-testing.png b/docs/_static/flask-testing.png new file mode 100644 index 0000000..18facb5 Binary files /dev/null and b/docs/_static/flask-testing.png differ diff --git a/docs/_themes/README b/docs/_themes/README new file mode 100644 index 0000000..b3292bd --- /dev/null +++ b/docs/_themes/README @@ -0,0 +1,31 @@ +Flask Sphinx Styles +=================== + +This repository contains sphinx styles for Flask and Flask related +projects. To use this style in your Sphinx documentation, follow +this guide: + +1. put this folder as _themes into your docs folder. Alternatively + you can also use git submodules to check out the contents there. +2. add this to your conf.py: + + sys.path.append(os.path.abspath('_themes')) + html_theme_path = ['_themes'] + html_theme = 'flask' + +The following themes exist: + +- 'flask' - the standard flask documentation theme for large + projects +- 'flask_small' - small one-page theme. Intended to be used by + very small addon libraries for flask. + +The following options exist for the flask_small theme: + + [options] + index_logo = '' filename of a picture in _static + to be used as replacement for the + h1 in the index.rst file. + index_logo_height = 120px height of the index logo + github_fork = '' repository name on github for the + "fork me" badge diff --git a/docs/_themes/flask/static/flasky.css_t b/docs/_themes/flask/static/flasky.css_t new file mode 100644 index 0000000..ed9378e --- /dev/null +++ b/docs/_themes/flask/static/flasky.css_t @@ -0,0 +1,345 @@ +/* + * flasky.css_t + * ~~~~~~~~~~~~ + * + * Sphinx stylesheet -- flasky theme based on nature theme. + * + * :copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS. + * :license: BSD, see LICENSE for details. + * + */ + +@import url("basic.css"); + +/* -- page layout ----------------------------------------------------------- */ + +body { + font-family: 'Georgia', serif; + font-size: 17px; + background-color: #ddd; + color: #000; + margin: 0; + padding: 0; +} + +div.document { + background: #fafafa; +} + +div.documentwrapper { + float: left; + width: 100%; +} + +div.bodywrapper { + margin: 0 0 0 230px; +} + +hr { + border: 1px solid #B1B4B6; +} + +div.body { + background-color: #ffffff; + color: #3E4349; + padding: 0 30px 30px 30px; + min-height: 34em; +} + +img.floatingflask { + padding: 0 0 10px 10px; + float: right; +} + +div.footer { + position: absolute; + right: 0; + margin-top: -70px; + text-align: right; + color: #888; + padding: 10px; + font-size: 14px; +} + +div.footer a { + color: #888; + text-decoration: underline; +} + +div.related { + line-height: 32px; + color: #888; +} + +div.related ul { + padding: 0 0 0 10px; +} + +div.related a { + color: #444; +} + +div.sphinxsidebar { + font-size: 14px; + line-height: 1.5; +} + +div.sphinxsidebarwrapper { + padding: 0 20px; +} + +div.sphinxsidebarwrapper p.logo { + padding: 20px 0 10px 0; + margin: 0; + text-align: center; +} + +div.sphinxsidebar h3, +div.sphinxsidebar h4 { + font-family: 'Garamond', 'Georgia', serif; + color: #222; + font-size: 24px; + font-weight: normal; + margin: 20px 0 5px 0; + padding: 0; +} + +div.sphinxsidebar h4 { + font-size: 20px; +} + +div.sphinxsidebar h3 a { + color: #444; +} + +div.sphinxsidebar p { + color: #555; + margin: 10px 0; +} + +div.sphinxsidebar ul { + margin: 10px 0; + padding: 0; + color: #000; +} + +div.sphinxsidebar a { + color: #444; + text-decoration: none; +} + +div.sphinxsidebar a:hover { + text-decoration: underline; +} + +div.sphinxsidebar input { + border: 1px solid #ccc; + font-family: 'Georgia', serif; + font-size: 1em; +} + +/* -- body styles ----------------------------------------------------------- */ + +a { + color: #004B6B; + text-decoration: underline; +} + +a:hover { + color: #6D4100; + text-decoration: underline; +} + +div.body { + padding-bottom: 40px; /* saved for footer */ +} + +div.body h1, +div.body h2, +div.body h3, +div.body h4, +div.body h5, +div.body h6 { + font-family: 'Garamond', 'Georgia', serif; + font-weight: normal; + margin: 30px 0px 10px 0px; + padding: 0; +} + +div.body h1 { margin-top: 0; padding-top: 20px; font-size: 240%; } +div.body h2 { font-size: 180%; } +div.body h3 { font-size: 150%; } +div.body h4 { font-size: 130%; } +div.body h5 { font-size: 100%; } +div.body h6 { font-size: 100%; } + +a.headerlink { + color: white; + padding: 0 4px; + text-decoration: none; +} + +a.headerlink:hover { + color: #444; + background: #eaeaea; +} + +div.body p, div.body dd, div.body li { + line-height: 1.4em; +} + +div.admonition { + background: #fafafa; + margin: 20px -30px; + padding: 10px 30px; + border-top: 1px solid #ccc; + border-bottom: 1px solid #ccc; +} + +div.admonition p.admonition-title { + font-family: 'Garamond', 'Georgia', serif; + font-weight: normal; + font-size: 24px; + margin: 0 0 10px 0; + padding: 0; + line-height: 1; +} + +div.admonition p.last { + margin-bottom: 0; +} + +div.highlight{ + background-color: white; +} + +dt:target, .highlight { + background: #FAF3E8; +} + +div.note { + background-color: #eee; + border: 1px solid #ccc; +} + +div.seealso { + background-color: #ffc; + border: 1px solid #ff6; +} + +div.topic { + background-color: #eee; +} + +div.warning { + background-color: #ffe4e4; + border: 1px solid #f66; +} + +p.admonition-title { + display: inline; +} + +p.admonition-title:after { + content: ":"; +} + +pre, tt { + font-family: 'Consolas', 'Menlo', 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace; + font-size: 0.9em; +} + +img.screenshot { +} + +tt.descname, tt.descclassname { + font-size: 0.95em; +} + +tt.descname { + padding-right: 0.08em; +} + +img.screenshot { + -moz-box-shadow: 2px 2px 4px #eee; + -webkit-box-shadow: 2px 2px 4px #eee; + box-shadow: 2px 2px 4px #eee; +} + +table.docutils { + border: 1px solid #888; + -moz-box-shadow: 2px 2px 4px #eee; + -webkit-box-shadow: 2px 2px 4px #eee; + box-shadow: 2px 2px 4px #eee; +} + +table.docutils td, table.docutils th { + border: 1px solid #888; + padding: 0.25em 0.7em; +} + +table.field-list, table.footnote { + border: none; + -moz-box-shadow: none; + -webkit-box-shadow: none; + box-shadow: none; +} + +table.footnote { + margin: 15px 0; + width: 100%; + border: 1px solid #eee; +} + +table.field-list th { + padding: 0 0.8em 0 0; +} + +table.field-list td { + padding: 0; +} + +table.footnote td { + padding: 0.5em; +} + +dl { + margin: 0; + padding: 0; +} + +dl dd { + margin-left: 30px; +} + +pre { + background: #eee; + padding: 7px 30px; + margin: 15px -30px; + line-height: 1.3em; +} + +dl pre { + margin-left: -60px; + padding-left: 60px; +} + +dl dl pre { + margin-left: -90px; + padding-left: 90px; +} + +tt { + background-color: #ecf0f3; + color: #222; + /* padding: 1px 2px; */ +} + +tt.xref, a tt { + background-color: #FBFBFB; + text-decoration: none!important; +} + +a:hover tt { + background: #EEE; +} diff --git a/docs/_themes/flask/theme.conf b/docs/_themes/flask/theme.conf new file mode 100644 index 0000000..e47d102 --- /dev/null +++ b/docs/_themes/flask/theme.conf @@ -0,0 +1,4 @@ +[theme] +inherit = basic +stylesheet = flasky.css +pygments_style = flask_theme_support.FlaskyStyle diff --git a/docs/_themes/flask_small/layout.html b/docs/_themes/flask_small/layout.html new file mode 100644 index 0000000..aa1716a --- /dev/null +++ b/docs/_themes/flask_small/layout.html @@ -0,0 +1,22 @@ +{% extends "basic/layout.html" %} +{% block header %} + {{ super() }} + {% if pagename == 'index' %} +
+ {% endif %} +{% endblock %} +{% block footer %} + {% if pagename == 'index' %} +
+ {% endif %} +{% endblock %} +{# do not display relbars #} +{% block relbar1 %}{% endblock %} +{% block relbar2 %} + {% if theme_github_fork %} + Fork me on GitHub + {% endif %} +{% endblock %} +{% block sidebar1 %}{% endblock %} +{% block sidebar2 %}{% endblock %} diff --git a/docs/_themes/flask_small/static/flasky.css_t b/docs/_themes/flask_small/static/flasky.css_t new file mode 100644 index 0000000..fe2141c --- /dev/null +++ b/docs/_themes/flask_small/static/flasky.css_t @@ -0,0 +1,287 @@ +/* + * flasky.css_t + * ~~~~~~~~~~~~ + * + * Sphinx stylesheet -- flasky theme based on nature theme. + * + * :copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS. + * :license: BSD, see LICENSE for details. + * + */ + +@import url("basic.css"); + +/* -- page layout ----------------------------------------------------------- */ + +body { + font-family: 'Georgia', serif; + font-size: 17px; + color: #000; + background: white; + margin: 0; + padding: 0; +} + +div.documentwrapper { + float: left; + width: 100%; +} + +div.bodywrapper { + margin: 40px auto 0 auto; + width: 700px; +} + +hr { + border: 1px solid #B1B4B6; +} + +div.body { + background-color: #ffffff; + color: #3E4349; + padding: 0 30px 30px 30px; +} + +img.floatingflask { + padding: 0 0 10px 10px; + float: right; +} + +div.footer { + text-align: right; + color: #888; + padding: 10px; + font-size: 14px; + width: 650px; + margin: 0 auto 40px auto; +} + +div.footer a { + color: #888; + text-decoration: underline; +} + +div.related { + line-height: 32px; + color: #888; +} + +div.related ul { + padding: 0 0 0 10px; +} + +div.related a { + color: #444; +} + +/* -- body styles ----------------------------------------------------------- */ + +a { + color: #004B6B; + text-decoration: underline; +} + +a:hover { + color: #6D4100; + text-decoration: underline; +} + +div.body { + padding-bottom: 40px; /* saved for footer */ +} + +div.body h1, +div.body h2, +div.body h3, +div.body h4, +div.body h5, +div.body h6 { + font-family: 'Garamond', 'Georgia', serif; + font-weight: normal; + margin: 30px 0px 10px 0px; + padding: 0; +} + +{% if theme_index_logo %} +div.indexwrapper h1 { + text-indent: -999999px; + background: url({{ theme_index_logo }}) no-repeat center center; + height: {{ theme_index_logo_height }}; +} +{% endif %} + +div.body h2 { font-size: 180%; } +div.body h3 { font-size: 150%; } +div.body h4 { font-size: 130%; } +div.body h5 { font-size: 100%; } +div.body h6 { font-size: 100%; } + +a.headerlink { + color: white; + padding: 0 4px; + text-decoration: none; +} + +a.headerlink:hover { + color: #444; + background: #eaeaea; +} + +div.body p, div.body dd, div.body li { + line-height: 1.4em; +} + +div.admonition { + background: #fafafa; + margin: 20px -30px; + padding: 10px 30px; + border-top: 1px solid #ccc; + border-bottom: 1px solid #ccc; +} + +div.admonition p.admonition-title { + font-family: 'Garamond', 'Georgia', serif; + font-weight: normal; + font-size: 24px; + margin: 0 0 10px 0; + padding: 0; + line-height: 1; +} + +div.admonition p.last { + margin-bottom: 0; +} + +div.highlight{ + background-color: white; +} + +dt:target, .highlight { + background: #FAF3E8; +} + +div.note { + background-color: #eee; + border: 1px solid #ccc; +} + +div.seealso { + background-color: #ffc; + border: 1px solid #ff6; +} + +div.topic { + background-color: #eee; +} + +div.warning { + background-color: #ffe4e4; + border: 1px solid #f66; +} + +p.admonition-title { + display: inline; +} + +p.admonition-title:after { + content: ":"; +} + +pre, tt { + font-family: 'Consolas', 'Menlo', 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace; + font-size: 0.85em; +} + +img.screenshot { +} + +tt.descname, tt.descclassname { + font-size: 0.95em; +} + +tt.descname { + padding-right: 0.08em; +} + +img.screenshot { + -moz-box-shadow: 2px 2px 4px #eee; + -webkit-box-shadow: 2px 2px 4px #eee; + box-shadow: 2px 2px 4px #eee; +} + +table.docutils { + border: 1px solid #888; + -moz-box-shadow: 2px 2px 4px #eee; + -webkit-box-shadow: 2px 2px 4px #eee; + box-shadow: 2px 2px 4px #eee; +} + +table.docutils td, table.docutils th { + border: 1px solid #888; + padding: 0.25em 0.7em; +} + +table.field-list, table.footnote { + border: none; + -moz-box-shadow: none; + -webkit-box-shadow: none; + box-shadow: none; +} + +table.footnote { + margin: 15px 0; + width: 100%; + border: 1px solid #eee; +} + +table.field-list th { + padding: 0 0.8em 0 0; +} + +table.field-list td { + padding: 0; +} + +table.footnote td { + padding: 0.5em; +} + +dl { + margin: 0; + padding: 0; +} + +dl dd { + margin-left: 30px; +} + +pre { + padding: 0; + margin: 15px -30px; + padding: 8px; + line-height: 1.3em; + padding: 7px 30px; + background: #eee; + border-radius: 2px; + -moz-border-radius: 2px; + -webkit-border-radius: 2px; +} + +dl pre { + margin-left: -60px; + padding-left: 60px; +} + +tt { + background-color: #ecf0f3; + color: #222; + /* padding: 1px 2px; */ +} + +tt.xref, a tt { + background-color: #FBFBFB; +} + +a:hover tt { + background: #EEE; +} diff --git a/docs/_themes/flask_small/theme.conf b/docs/_themes/flask_small/theme.conf new file mode 100644 index 0000000..542b462 --- /dev/null +++ b/docs/_themes/flask_small/theme.conf @@ -0,0 +1,10 @@ +[theme] +inherit = basic +stylesheet = flasky.css +nosidebar = true +pygments_style = flask_theme_support.FlaskyStyle + +[options] +index_logo = '' +index_logo_height = 120px +github_fork = '' diff --git a/docs/_themes/flask_theme_support.py b/docs/_themes/flask_theme_support.py new file mode 100644 index 0000000..33f4744 --- /dev/null +++ b/docs/_themes/flask_theme_support.py @@ -0,0 +1,86 @@ +# flasky extensions. flasky pygments style based on tango style +from pygments.style import Style +from pygments.token import Keyword, Name, Comment, String, Error, \ + Number, Operator, Generic, Whitespace, Punctuation, Other, Literal + + +class FlaskyStyle(Style): + background_color = "#f8f8f8" + default_style = "" + + styles = { + # No corresponding class for the following: + #Text: "", # class: '' + Whitespace: "underline #f8f8f8", # class: 'w' + Error: "#a40000 border:#ef2929", # class: 'err' + Other: "#000000", # class 'x' + + Comment: "italic #8f5902", # class: 'c' + Comment.Preproc: "noitalic", # class: 'cp' + + Keyword: "bold #004461", # class: 'k' + Keyword.Constant: "bold #004461", # class: 'kc' + Keyword.Declaration: "bold #004461", # class: 'kd' + Keyword.Namespace: "bold #004461", # class: 'kn' + Keyword.Pseudo: "bold #004461", # class: 'kp' + Keyword.Reserved: "bold #004461", # class: 'kr' + Keyword.Type: "bold #004461", # class: 'kt' + + Operator: "#582800", # class: 'o' + Operator.Word: "bold #004461", # class: 'ow' - like keywords + + Punctuation: "bold #000000", # class: 'p' + + # because special names such as Name.Class, Name.Function, etc. + # are not recognized as such later in the parsing, we choose them + # to look the same as ordinary variables. + Name: "#000000", # class: 'n' + Name.Attribute: "#c4a000", # class: 'na' - to be revised + Name.Builtin: "#004461", # class: 'nb' + Name.Builtin.Pseudo: "#3465a4", # class: 'bp' + Name.Class: "#000000", # class: 'nc' - to be revised + Name.Constant: "#000000", # class: 'no' - to be revised + Name.Decorator: "#888", # class: 'nd' - to be revised + Name.Entity: "#ce5c00", # class: 'ni' + Name.Exception: "bold #cc0000", # class: 'ne' + Name.Function: "#000000", # class: 'nf' + Name.Property: "#000000", # class: 'py' + Name.Label: "#f57900", # class: 'nl' + Name.Namespace: "#000000", # class: 'nn' - to be revised + Name.Other: "#000000", # class: 'nx' + Name.Tag: "bold #004461", # class: 'nt' - like a keyword + Name.Variable: "#000000", # class: 'nv' - to be revised + Name.Variable.Class: "#000000", # class: 'vc' - to be revised + Name.Variable.Global: "#000000", # class: 'vg' - to be revised + Name.Variable.Instance: "#000000", # class: 'vi' - to be revised + + Number: "#990000", # class: 'm' + + Literal: "#000000", # class: 'l' + Literal.Date: "#000000", # class: 'ld' + + String: "#4e9a06", # class: 's' + String.Backtick: "#4e9a06", # class: 'sb' + String.Char: "#4e9a06", # class: 'sc' + String.Doc: "italic #8f5902", # class: 'sd' - like a comment + String.Double: "#4e9a06", # class: 's2' + String.Escape: "#4e9a06", # class: 'se' + String.Heredoc: "#4e9a06", # class: 'sh' + String.Interpol: "#4e9a06", # class: 'si' + String.Other: "#4e9a06", # class: 'sx' + String.Regex: "#4e9a06", # class: 'sr' + String.Single: "#4e9a06", # class: 's1' + String.Symbol: "#4e9a06", # class: 'ss' + + Generic: "#000000", # class: 'g' + Generic.Deleted: "#a40000", # class: 'gd' + Generic.Emph: "italic #000000", # class: 'ge' + Generic.Error: "#ef2929", # class: 'gr' + Generic.Heading: "bold #000080", # class: 'gh' + Generic.Inserted: "#00A000", # class: 'gi' + Generic.Output: "#888", # class: 'go' + Generic.Prompt: "#745334", # class: 'gp' + Generic.Strong: "bold #000000", # class: 'gs' + Generic.Subheading: "bold #800080", # class: 'gu' + Generic.Traceback: "bold #a40000", # class: 'gt' + } diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..c4f6bdc --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,222 @@ +# -*- coding: utf-8 -*- +# +# flask-testing documentation build configuration file, created by +# sphinx-quickstart on Wed Jun 23 08:26:41 2010. +# +# This file is execfile()d with the current directory set to its containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys, os + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +sys.path.insert( + 0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) +sys.path.append(os.path.abspath('_themes')) + +# -- General configuration ----------------------------------------------------- + +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be extensions +# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx'] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'Flask-Testing' +copyright = u'2010, Dan Jacob' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = '0.3' +# The full version, including alpha/beta/rc tags. +release = '0.3' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +#language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ['_build'] + +# The reST default role (used for this markup: `text`) to use for all documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +#pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + + +# -- Options for HTML output --------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = 'flask_small' + +html_theme_options = { + 'index_logo': 'flask-testing.png', + 'github_fork': 'jarus/flask-testing' +} +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +html_theme_path = ['_themes'] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = '' + +# Output file base name for HTML help builder. +htmlhelp_basename = 'flask-testingdoc' + + +# -- Options for LaTeX output -------------------------------------------------- + +# The paper size ('letter' or 'a4'). +#latex_paper_size = 'letter' + +# The font size ('10pt', '11pt' or '12pt'). +#latex_font_size = '10pt' + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, author, documentclass [howto/manual]). +latex_documents = [ + ('index', 'flask-testing.tex', u'Flask-Testing Documentation', + u'Dan Jacob', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Additional stuff for the LaTeX preamble. +#latex_preamble = '' + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output -------------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ('index', 'flask-testing', u'Flask-Testing Documentation', + [u'Dan Jacob'], 1) +] diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..05c4aab --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,288 @@ +Flask-Testing +************* + +.. module:: flask_testing + +The **Flask-Testing** extension provides unit testing utilities for Flask. + +Installing Flask-Testing +======================== + +Install with **pip** and **easy_install**:: + + pip install Flask-Testing + +or download the latest version from version control:: + + git clone https://github.com/jarus/flask-testing.git + cd flask-testing + python setup.py develop + +If you are using **virtualenv**, it is assumed that you are installing **Flask-Testing** +in the same virtualenv as your Flask application(s). + +Writing tests +============= + +Simply subclass the ``TestCase`` class:: + + from flask.ext.testing import TestCase + + class MyTest(TestCase): + + pass + + +You must specify the ``create_app`` method, which should return a Flask instance:: + + from flask import Flask + from flask.ext.testing import TestCase + + class MyTest(TestCase): + + def create_app(self): + + app = Flask(__name__) + app.config['TESTING'] = True + return app + +If you don't define ``create_app`` a ``NotImplementedError`` will be raised. + + +Testing with LiveServer +----------------------- + +If you want your tests done via Selenium or other headless browser like +PhantomJS you can use the LiveServerTestCase:: + + import urllib2 + from flask import Flask + from flask.ext.testing import LiveServerTestCase + + class MyTest(LiveServerTestCase): + + def create_app(self): + app = Flask(__name__) + app.config['TESTING'] = True + # Default port is 5000 + app.config['LIVESERVER_PORT'] = 8943 + return app + + def test_server_is_up_and_running(self): + response = urllib2.urlopen(self.get_server_url()) + self.assertEqual(response.code, 200) + +The method ``get_server_url`` will return http://localhost:8943 in this case. + + +Testing JSON responses +---------------------- + +If you are testing a view that returns a JSON response, you can test the output using +a special ``json`` attribute appended to the ``Response`` object:: + + @app.route("/ajax/") + def some_json(): + return jsonify(success=True) + + class TestViews(TestCase): + def test_some_json(self): + response = self.client.get("/ajax/") + self.assertEquals(response.json, dict(success=True)) + +Opt to not render the templates +------------------------------- + +When testing with mocks the template rendering can be a problem. If you don't want to render +the templates in the tests you can use the ``render_templates`` attribute:: + + class TestNotRenderTemplates(TestCase): + + render_templates = False + + def test_assert_not_process_the_template(self): + response = self.client.get("/template/") + + assert "" == response.data + +The signal will be sent anyway so that you can check if the template was rendered using +the ``assert_template_used`` method:: + + class TestNotRenderTemplates(TestCase): + + render_templates = False + + def test_assert_mytemplate_used(self): + response = self.client.get("/template/") + + self.assert_template_used('mytemplate.html') + +When the template rendering is turned off the tests will also run faster and the view logic +can be tested in isolation. + +Using with Twill +---------------- + +`Twill`_ is a simple language for browsing the Web through +a command line interface. + +.. note:: + + Please note that Twill only supports Python 2.x and therefore cannot be used with Python 3 or above. + +``Flask-Testing`` comes with a helper class for creating functional tests using Twill:: + + def test_something_with_twill(self): + + with Twill(self.app, port=3000) as t: + t.browser.go(t.url("/")) + + +The older ``TwillTestCase`` has been deprecated. + +Testing with SQLAlchemy +----------------------- + +This covers a couple of points if you are using **Flask-Testing** with `SQLAlchemy`_. It is +assumed that you are using the `Flask-SQLAlchemy`_ extension, but if not the examples should +not be too difficult to adapt to your own particular setup. + +First, ensure you set the database URI to something other than your production database ! Second, +it's usually a good idea to create and drop your tables with each test run, to ensure clean tests:: + + from flask.ext.testing import TestCase + + from myapp import create_app, db + + class MyTest(TestCase): + + SQLALCHEMY_DATABASE_URI = "sqlite://" + TESTING = True + + def create_app(self): + + # pass in test configuration + return create_app(self) + + def setUp(self): + + db.create_all() + + def tearDown(self): + + db.session.remove() + db.drop_all() + +Notice also that ``db.session.remove()`` is called at the end of each test, to ensure the SQLAlchemy +session is properly removed and that a new session is started with each test run - this is a common +"gotcha". + +Another gotcha is that Flask-SQLAlchemy **also** removes the session instance at the end of every request (as +should any thread safe application using SQLAlchemy with **scoped_session**). Therefore the session +is cleared along with any objects added to it every time you call ``client.get()`` or another client method. + +For example:: + + class SomeTest(MyTest): + + def test_something(self): + + user = User() + db.session.add(user) + db.session.commit() + + # this works + assert user in db.session + + response = self.client.get("/") + + # this raises an AssertionError + assert user in db.session + +You now have to re-add the "user" instance back to the session with ``db.session.add(user)``, if you are going +to make any further database operations on it. + +Also notice that for this example the SQLite in-memory database is used : while it is faster for tests, +if you have database-specific code (e.g. for MySQL or PostgreSQL) it may not be applicable. + +You may also want to add a set of instances for your database inside of a ``setUp()`` once your database +tables have been created. If you want to work with larger sets of data, look at `Fixture`_ which includes +support for SQLAlchemy. + +Running tests +============= + +with unittest +------------- + +For the beginning I go on the theory that you put all your tests into one file +than you can use the :func:`unittest.main` function. This function will discover +all your test methods in your :class:`TestCase` classes. Remember, the test +methods and classes must starts with ``test`` (case-insensitive) that they will +discover. + +An example test file could look like this:: + + import unittest + import flask.ext.testing + + # your test cases + + if __name__ == '__main__': + unittest.main() + +Now you can run your tests with ``python tests.py``. + +with nose +--------- + +The `nose`_ collector and test runner works also fine with Flask-Testing. + +Changes +======= + +0.4.2 (24.07.2014) +------------------ + + * Improved teardown to be more graceful. + * Add ``message`` argument to ``assertStatus`` respectively all assertion methods with fixed status like ``assert404``. + +0.4.1 (27.02.2014) +------------------ + +This release is dedicated to every contributer who made this release possible. Thank you very much. + + * Python 3 compatibility (without twill) + * Add ``LiveServerTestCase`` + * Use unittest2 backports if available in python 2.6 + * Install multiprocessing for python versions earlier than 2.6 + +0.4 (06.07.2012) +---------------- + + * Use of the new introduced import way for flask extensions. Use ``import flask.ext.testing`` instead of ``import flaskext.testing``. + * Replace all ``assert`` with ``self.assert*`` methods for better output with unittest. + * Improved Python 2.5 support. + * Use Flask's preferred JSON module. + + +API +=== + +.. module:: flask.ext.testing + +.. autoclass:: TestCase + :members: + +.. autoclass:: Twill + :members: + +.. autoclass:: TwillTestCase + :members: + +.. _Flask: http://flask.pocoo.org +.. _Twill: http://twill.idyll.org/ +.. _Fixture: http://farmdev.com/projects/fixture/index.html +.. _SQLAlchemy: http://sqlalchemy.org +.. _Flask-SQLAlchemy: http://packages.python.org/Flask-SQLAlchemy/ +.. _nose: http://nose.readthedocs.org/en/latest/ diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..7a5f556 --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,155 @@ +@ECHO OFF + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set BUILDDIR=_build +set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . +if NOT "%PAPER%" == "" ( + set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% +) + +if "%1" == "" goto help + +if "%1" == "help" ( + :help + echo.Please use `make ^` where ^ is one of + echo. html to make standalone HTML files + echo. dirhtml to make HTML files named index.html in directories + echo. singlehtml to make a single large HTML file + echo. pickle to make pickle files + echo. json to make JSON files + echo. htmlhelp to make HTML files and a HTML help project + echo. qthelp to make HTML files and a qthelp project + echo. devhelp to make HTML files and a Devhelp project + echo. epub to make an epub + echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter + echo. text to make text files + echo. man to make manual pages + echo. changes to make an overview over all changed/added/deprecated items + echo. linkcheck to check all external links for integrity + echo. doctest to run all doctests embedded in the documentation if enabled + goto end +) + +if "%1" == "clean" ( + for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i + del /q /s %BUILDDIR%\* + goto end +) + +if "%1" == "html" ( + %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/html. + goto end +) + +if "%1" == "dirhtml" ( + %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. + goto end +) + +if "%1" == "singlehtml" ( + %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. + goto end +) + +if "%1" == "pickle" ( + %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle + echo. + echo.Build finished; now you can process the pickle files. + goto end +) + +if "%1" == "json" ( + %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json + echo. + echo.Build finished; now you can process the JSON files. + goto end +) + +if "%1" == "htmlhelp" ( + %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp + echo. + echo.Build finished; now you can run HTML Help Workshop with the ^ +.hhp project file in %BUILDDIR%/htmlhelp. + goto end +) + +if "%1" == "qthelp" ( + %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp + echo. + echo.Build finished; now you can run "qcollectiongenerator" with the ^ +.qhcp project file in %BUILDDIR%/qthelp, like this: + echo.^> qcollectiongenerator %BUILDDIR%\qthelp\flask-unittest.qhcp + echo.To view the help file: + echo.^> assistant -collectionFile %BUILDDIR%\qthelp\flask-unittest.ghc + goto end +) + +if "%1" == "devhelp" ( + %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp + echo. + echo.Build finished. + goto end +) + +if "%1" == "epub" ( + %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub + echo. + echo.Build finished. The epub file is in %BUILDDIR%/epub. + goto end +) + +if "%1" == "latex" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + echo. + echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "text" ( + %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text + echo. + echo.Build finished. The text files are in %BUILDDIR%/text. + goto end +) + +if "%1" == "man" ( + %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man + echo. + echo.Build finished. The manual pages are in %BUILDDIR%/man. + goto end +) + +if "%1" == "changes" ( + %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes + echo. + echo.The overview file is in %BUILDDIR%/changes. + goto end +) + +if "%1" == "linkcheck" ( + %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck + echo. + echo.Link check complete; look for any errors in the above output ^ +or in %BUILDDIR%/linkcheck/output.txt. + goto end +) + +if "%1" == "doctest" ( + %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest + echo. + echo.Testing of doctests in the sources finished, look at the ^ +results in %BUILDDIR%/doctest/output.txt. + goto end +) + +:end diff --git a/flask_testing/__init__.py b/flask_testing/__init__.py new file mode 100644 index 0000000..187c468 --- /dev/null +++ b/flask_testing/__init__.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +""" + flask_testing + ~~~~~~~~~~~~~ + + Flask unittest integration. + + :copyright: (c) 2010 by Dan Jacob. + :license: BSD, see LICENSE for more details. +""" + +from __future__ import absolute_import +from .utils import TestCase, LiveServerTestCase + +try: + import twill + from .twill import Twill, TwillTestCase + is_twill_available = True +except ImportError: + is_twill_available = False + + class Error(): + def __init__(self, *args, **kwargs): + msg = "'twill' package is required for %s" % ( + self.__class__.__name__) + raise ImportError(msg) + + Twill = Error + TwillTestCase = Error diff --git a/flask_testing/twill.py b/flask_testing/twill.py new file mode 100644 index 0000000..269b743 --- /dev/null +++ b/flask_testing/twill.py @@ -0,0 +1,115 @@ +# -*- coding: utf-8 -*- +""" + flask_testing.twill + ~~~~~~~~~~~~~~~~~~~ + + Flask unittest integration. + + :copyright: (c) 2010 by Dan Jacob. + :license: BSD, see LICENSE for more details. +""" + +from __future__ import absolute_import + +import StringIO +import twill + +from .utils import TestCase + + +class Twill(object): + """ + + :versionadded: 0.3 + + Twill wrapper utility class. + + Creates a Twill ``browser`` instance and handles + WSGI intercept. + + Usage:: + + t = Twill(self.app) + with t: + t.browser.go("/") + t.url("/") + + """ + def __init__(self, app, host='127.0.0.1', port=5000, scheme='http'): + self.app = app + self.host = host + self.port = port + self.scheme = scheme + + self.browser = twill.get_browser() + + def __enter__(self): + twill.set_output(StringIO.StringIO()) + twill.commands.clear_cookies() + twill.add_wsgi_intercept(self.host, + self.port, + lambda: self.app) + + return self + + def __exit__(self, exc_type, exc_value, tb): + twill.remove_wsgi_intercept(self.host, + self.port) + + twill.commands.reset_output() + + def url(self, url): + """ + Makes complete URL based on host, port and scheme + Twill settings. + + :param url: relative URL + """ + return "%s://%s:%d%s" % (self.scheme, + self.host, + self.port, + url) + + +class TwillTestCase(TestCase): + """ + :deprecated: use Twill helper class instead. + + Creates a Twill ``browser`` instance and handles + WSGI intercept. + """ + + twill_host = "127.0.0.1" + twill_port = 5000 + twill_scheme = "http" + + def _pre_setup(self): + super(TwillTestCase, self)._pre_setup() + twill.set_output(StringIO.StringIO()) + twill.commands.clear_cookies() + twill.add_wsgi_intercept(self.twill_host, + self.twill_port, + lambda: self.app) + + self.browser = twill.get_browser() + + def _post_teardown(self): + + twill.remove_wsgi_intercept(self.twill_host, + self.twill_port) + + twill.commands.reset_output() + + super(TwillTestCase, self)._post_teardown() + + def make_twill_url(self, url): + """ + Makes complete URL based on host, port and scheme + Twill settings. + + :param url: relative URL + """ + return "%s://%s:%d%s" % (self.twill_scheme, + self.twill_host, + self.twill_port, + url) diff --git a/flask_testing/utils.py b/flask_testing/utils.py new file mode 100644 index 0000000..bfeae48 --- /dev/null +++ b/flask_testing/utils.py @@ -0,0 +1,373 @@ +# -*- coding: utf-8 -*- +""" + flask_testing.utils + ~~~~~~~~~~~~~~~~~~~ + + Flask unittest integration. + + :copyright: (c) 2010 by Dan Jacob. + :license: BSD, see LICENSE for more details. +""" +from __future__ import absolute_import, with_statement + +import gc +import time +try: + import unittest2 as unittest +except ImportError: + import unittest +import multiprocessing + +from werkzeug import cached_property + +# Use Flask's preferred JSON module so that our runtime behavior matches. +from flask import json_available, templating, template_rendered +if json_available: + from flask import json + +# we'll use signals for template-related tests if +# available in this version of Flask +try: + import blinker + _is_signals = True +except ImportError: # pragma: no cover + _is_signals = False + +__all__ = ["TestCase"] + + +class ContextVariableDoesNotExist(Exception): + pass + + +class JsonResponseMixin(object): + """ + Mixin with testing helper methods + """ + @cached_property + def json(self): + if not json_available: # pragma: no cover + raise NotImplementedError + return json.loads(self.data) + + +def _make_test_response(response_class): + class TestResponse(response_class, JsonResponseMixin): + pass + + return TestResponse + + +def _empty_render(template, context, app): + """ + Used to monkey patch the render_template flask method when + the render_templates property is set to False in the TestCase + """ + if _is_signals: + template_rendered.send(app, template=template, context=context) + + return "" + + +class TestCase(unittest.TestCase): + + render_templates = True + run_gc_after_test = False + + def create_app(self): + """ + Create your Flask app here, with any + configuration you need. + """ + raise NotImplementedError + + def __call__(self, result=None): + """ + Does the required setup, doing it here + means you don't have to call super.setUp + in subclasses. + """ + try: + self._pre_setup() + super(TestCase, self).__call__(result) + finally: + self._post_teardown() + + def _pre_setup(self): + self.app = self.create_app() + + self._orig_response_class = self.app.response_class + self.app.response_class = _make_test_response(self.app.response_class) + + self.client = self.app.test_client() + + self._ctx = self.app.test_request_context() + self._ctx.push() + + if not self.render_templates: + # Monkey patch the original template render with a empty render + self._original_template_render = templating._render + templating._render = _empty_render + + self.templates = [] + if _is_signals: + template_rendered.connect(self._add_template) + + def _add_template(self, app, template, context): + if len(self.templates) > 0: + self.templates = [] + self.templates.append((template, context)) + + def _post_teardown(self): + if getattr(self, '_ctx', None) is not None: + self._ctx.pop() + del self._ctx + + if getattr(self, 'app', None) is not None: + if getattr(self, '_orig_response_class', None) is not None: + self.app.response_class = self._orig_response_class + del self.app + + if hasattr(self, 'client'): + del self.client + + if hasattr(self, 'templates'): + del self.templates + + if _is_signals: + template_rendered.disconnect(self._add_template) + if hasattr(self, '_true_render'): + templating._render = self._true_render + + if self.run_gc_after_test: + gc.collect() + + def assertTemplateUsed(self, name, tmpl_name_attribute='name'): + """ + Checks if a given template is used in the request. + Only works if your version of Flask has signals + support (0.6+) and blinker is installed. + If the template engine used is not Jinja2, provide + ``tmpl_name_attribute`` with a value of its `Template` + class attribute name which contains the provided ``name`` value. + + :versionadded: 0.2 + :param name: template name + :param tmpl_name_attribute: template engine specific attribute name + """ + if not _is_signals: + raise RuntimeError("Signals not supported") + + for template, context in self.templates: + if getattr(template, tmpl_name_attribute) == name: + return True + raise AssertionError("template %s not used" % name) + + assert_template_used = assertTemplateUsed + + def get_context_variable(self, name): + """ + Returns a variable from the context passed to the + template. Only works if your version of Flask + has signals support (0.6+) and blinker is installed. + + Raises a ContextVariableDoesNotExist exception if does + not exist in context. + + :versionadded: 0.2 + :param name: name of variable + """ + if not _is_signals: + raise RuntimeError("Signals not supported") + + for template, context in self.templates: + if name in context: + return context[name] + raise ContextVariableDoesNotExist + + def assertContext(self, name, value): + """ + Checks if given name exists in the template context + and equals the given value. + + :versionadded: 0.2 + :param name: name of context variable + :param value: value to check against + """ + + try: + self.assertEqual(self.get_context_variable(name), value) + except ContextVariableDoesNotExist: + self.fail("Context variable does not exist: %s" % name) + + assert_context = assertContext + + def assertRedirects(self, response, location): + """ + Checks if response is an HTTP redirect to the + given location. + + :param response: Flask response + :param location: relative URL (i.e. without **http://localhost**) + """ + self.assertTrue(response.status_code in (301, 302)) + self.assertEqual(response.location, "http://localhost" + location) + + assert_redirects = assertRedirects + + def assertStatus(self, response, status_code, message=None): + """ + Helper method to check matching response status. + + :param response: Flask response + :param status_code: response status code (e.g. 200) + :param message: Message to display on test failure + """ + + message = message or 'HTTP Status %s expected but got %s' \ + % (status_code, response.status_code) + self.assertEqual(response.status_code, status_code, message) + + assert_status = assertStatus + + def assert200(self, response, message=None): + """ + Checks if response status code is 200 + + :param response: Flask response + :param message: Message to display on test failure + """ + + self.assertStatus(response, 200, message) + + assert_200 = assert200 + + def assert400(self, response, message=None): + """ + Checks if response status code is 400 + + :versionadded: 0.2.5 + :param response: Flask response + :param message: Message to display on test failure + """ + + self.assertStatus(response, 400, message) + + assert_400 = assert400 + + def assert401(self, response, message=None): + """ + Checks if response status code is 401 + + :versionadded: 0.2.1 + :param response: Flask response + :param message: Message to display on test failure + """ + + self.assertStatus(response, 401, message) + + assert_401 = assert401 + + def assert403(self, response, message=None): + """ + Checks if response status code is 403 + + :versionadded: 0.2 + :param response: Flask response + :param message: Message to display on test failure + """ + + self.assertStatus(response, 403, message) + + assert_403 = assert403 + + def assert404(self, response, message=None): + """ + Checks if response status code is 404 + + :param response: Flask response + :param message: Message to display on test failure + """ + + self.assertStatus(response, 404, message) + + assert_404 = assert404 + + def assert405(self, response, message=None): + """ + Checks if response status code is 405 + + :versionadded: 0.2 + :param response: Flask response + :param message: Message to display on test failure + """ + + self.assertStatus(response, 405, message) + + assert_405 = assert405 + + def assert500(self, response, message=None): + """ + Checks if response status code is 500 + + :versionadded: 0.4.1 + :param response: Flask response + :param message: Message to display on test failure + """ + + self.assertStatus(response, 500, message) + + assert_500 = assert500 + + +# A LiveServerTestCase useful with Selenium or headless browsers +# Inspired by https://docs.djangoproject.com/en/dev/topics/testing/#django.test.LiveServerTestCase + +class LiveServerTestCase(unittest.TestCase): + + def create_app(self): + """ + Create your Flask app here, with any + configuration you need. + """ + raise NotImplementedError + + def __call__(self, result=None): + """ + Does the required setup, doing it here means you don't have to + call super.setUp in subclasses. + """ + + # Get the app + self.app = self.create_app() + + try: + self._spawn_live_server() + super(LiveServerTestCase, self).__call__(result) + finally: + self._terminate_live_server() + + def get_server_url(self): + """ + Return the url of the test server + """ + return 'http://localhost:%s' % self.port + + def _spawn_live_server(self): + self._process = None + self.port = self.app.config.get('LIVESERVER_PORT', 5000) + + worker = lambda app, port: app.run(port=port) + + self._process = multiprocessing.Process( + target=worker, args=(self.app, self.port) + ) + + self._process.start() + + # we must wait the server start listening + time.sleep(1) + + def _terminate_live_server(self): + if self._process: + self._process.terminate() diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..861a9f5 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,5 @@ +[egg_info] +tag_build = +tag_date = 0 +tag_svn_revision = 0 + diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..91ad2aa --- /dev/null +++ b/setup.py @@ -0,0 +1,58 @@ +""" +Flask-Testing +------------- + +Flask unittest integration. + +Links +````` + +* `documentation ` +* `development version ` + +""" +import sys +from setuptools import setup + +tests_require = [ + 'blinker' +] + +install_requires = [ + 'Flask' +] + +if sys.version_info[0] < 3: + tests_require.append('twill==0.9') + +if sys.version_info < (2, 6): + tests_require.append('simplejson') + install_requires.append('multiprocessing') + +setup( + name='Flask-Testing', + version='0.4.2', + url='https://github.com/jarus/flask-testing', + license='BSD', + author='Dan Jacob', + author_email='danjac354@gmail.com', + description='Unit testing for Flask', + long_description=__doc__, + packages=['flask_testing'], + test_suite="tests.suite", + zip_safe=False, + platforms='any', + install_requires=install_requires, + tests_require=tests_require, + classifiers=[ + 'Development Status :: 4 - Beta', + 'Environment :: Web Environment', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: BSD License', + 'Operating System :: OS Independent', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3', + 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', + 'Topic :: Software Development :: Libraries :: Python Modules' + ] +) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..3865848 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,21 @@ +import unittest + +from flask_testing import is_twill_available + +from .test_utils import TestSetup, TestSetupFailure, TestClientUtils, TestLiveServer, TestTeardownGraceful +from .test_twill import TestTwill, TestTwillDeprecated + + +def suite(): + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestSetup)) + suite.addTest(unittest.makeSuite(TestSetupFailure)) + suite.addTest(unittest.makeSuite(TestTeardownGraceful)) + suite.addTest(unittest.makeSuite(TestClientUtils)) + suite.addTest(unittest.makeSuite(TestLiveServer)) + if is_twill_available: + suite.addTest(unittest.makeSuite(TestTwill)) + suite.addTest(unittest.makeSuite(TestTwillDeprecated)) + else: + print("!!! Skipping tests of Twill components\n") + return suite diff --git a/tests/__main__.py b/tests/__main__.py new file mode 100644 index 0000000..e80fce3 --- /dev/null +++ b/tests/__main__.py @@ -0,0 +1,4 @@ +from run import run + +if __name__ == '__main__': + run() diff --git a/tests/flask_app/__init__.py b/tests/flask_app/__init__.py new file mode 100644 index 0000000..d270cfe --- /dev/null +++ b/tests/flask_app/__init__.py @@ -0,0 +1,41 @@ +from flask import Flask, Response, abort, redirect, jsonify, render_template,\ + url_for + + +def create_app(): + + app = Flask(__name__) + + @app.route("/") + def index(): + return Response("OK") + + @app.route("/template/") + def index_with_template(): + return render_template("index.html", name="test") + + @app.route("/oops/") + def bad_url(): + abort(404) + + @app.route("/redirect/") + def redirect_to_index(): + return redirect(url_for("index")) + + @app.route("/ajax/") + def ajax(): + return jsonify(name="test") + + @app.route("/forbidden/") + def forbidden(): + abort(403) + + @app.route("/unauthorized/") + def unauthorized(): + abort(401) + + @app.route("/internal_server_error/") + def internal_server_error(): + abort(500) + + return app diff --git a/tests/flask_app/templates/index.html b/tests/flask_app/templates/index.html new file mode 100644 index 0000000..d86bac9 --- /dev/null +++ b/tests/flask_app/templates/index.html @@ -0,0 +1 @@ +OK diff --git a/tests/run.py b/tests/run.py new file mode 100644 index 0000000..dafb992 --- /dev/null +++ b/tests/run.py @@ -0,0 +1,32 @@ +import sys +import unittest + +try: + from coverage import coverage + coverage_available = True +except ImportError: + coverage_available = False + + +def run(): + if coverage_available: + cov = coverage(source=['flask_testing']) + cov.start() + + from tests import suite + result = unittest.TextTestRunner(verbosity=2).run(suite()) + if not result.wasSuccessful(): + sys.exit(1) + + if coverage_available: + cov.stop() + + print("\nCode Coverage") + cov.report() + cov.html_report(directory='cover') + else: + print("\nTipp:\n\tUse 'pip install coverage' to get great code " + "coverage stats") + +if __name__ == '__main__': + run() diff --git a/tests/test_twill.py b/tests/test_twill.py new file mode 100644 index 0000000..d0c74e0 --- /dev/null +++ b/tests/test_twill.py @@ -0,0 +1,40 @@ +from __future__ import with_statement + +from flask_testing import TestCase, TwillTestCase, Twill +from .flask_app import create_app + + +class TestTwill(TestCase): + + def create_app(self): + app = create_app() + app.config.from_object(self) + return app + + def test_twill_setup(self): + + twill = Twill(self.app) + + self.assertEqual(twill.host, "127.0.0.1") + self.assertEqual(twill.port, 5000) + self.assertTrue(twill.browser is not None) + + def test_make_twill_url(self): + with Twill(self.app) as t: + self.assertEqual(t.url("/"), "http://127.0.0.1:5000/") + + +class TestTwillDeprecated(TwillTestCase): + + def create_app(self): + app = create_app() + app.config.from_object(self) + return app + + def test_twill_setup(self): + self.assertEqual(self.twill_host, '127.0.0.1') + self.assertEqual(self.twill_port, 5000) + self.assertTrue(self.browser is not None) + + def test_make_twill_url(self): + self.assertEqual(self.make_twill_url("/"), "http://127.0.0.1:5000/") diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000..1b81c80 --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,209 @@ +try: + from urllib2 import urlopen +except ImportError: + from urllib.request import urlopen +from unittest import TestResult +from flask_testing import TestCase, LiveServerTestCase +from flask_testing.utils import ContextVariableDoesNotExist +from .flask_app import create_app + + +class TestSetup(TestCase): + + def create_app(self): + return create_app() + + def test_setup(self): + self.assertTrue(self.app is not None) + self.assertTrue(self.client is not None) + self.assertTrue(self._ctx is not None) + + +class TestSetupFailure(TestCase): + + def _pre_setup(self): + pass + + def test_setup_failure(self): + '''Should not fail in _post_teardown if _pre_setup fails''' + assert True + +class TestTeardownGraceful(TestCase): + + def create_app(self): + return create_app() + + def test_remove_testcase_attributes(self): + """ + There should no exception after this test because teardown + is graceful. + """ + + del self.app + del self._ctx + +class TestClientUtils(TestCase): + + def create_app(self): + return create_app() + + def test_get_json(self): + response = self.client.get("/ajax/") + self.assertEqual(response.json, dict(name="test")) + + def test_status_failure_message(self): + expected_message = 'my message' + try: + self.assertStatus(self.client.get('/'), 404, expected_message) + except AssertionError as e: + self.assertTrue(expected_message in e.args[0] or \ + expected_message in e.message) + + def test_default_status_failure_message(self): + expected_message = 'HTTP Status 404 expected but got 200' + try: + self.assertStatus(self.client.get('/'), 404) + except AssertionError as e: + self.assertTrue(expected_message in e.args[0] or \ + expected_message in e.message) + + def test_assert_200(self): + self.assert200(self.client.get("/")) + + def test_assert_404(self): + self.assert404(self.client.get("/oops/")) + + def test_assert_403(self): + self.assert403(self.client.get("/forbidden/")) + + def test_assert_401(self): + self.assert401(self.client.get("/unauthorized/")) + + def test_assert_405(self): + self.assert405(self.client.post("/")) + + def test_assert_500(self): + self.assert500(self.client.get("/internal_server_error/")) + + def test_assert_redirects(self): + response = self.client.get("/redirect/") + self.assertRedirects(response, "/") + + def test_assert_template_used(self): + try: + self.client.get("/template/") + self.assert_template_used("index.html") + except RuntimeError: + pass + + def test_assert_template_not_used(self): + self.client.get("/") + try: + self.assert_template_used("index.html") + assert False + except AssertionError: + pass + except RuntimeError: + pass + + def test_get_context_variable(self): + try: + self.client.get("/template/") + self.assertEqual(self.get_context_variable("name"), "test") + except RuntimeError: + pass + + def test_assert_context(self): + try: + self.client.get("/template/") + self.assert_context("name", "test") + except RuntimeError: + pass + + def test_assert_bad_context(self): + try: + self.client.get("/template/") + self.assertRaises(AssertionError, self.assert_context, + "name", "foo") + self.assertRaises(AssertionError, self.assert_context, + "foo", "foo") + except RuntimeError: + pass + + def test_assert_get_context_variable_not_exists(self): + try: + self.client.get("/template/") + self.assertRaises(ContextVariableDoesNotExist, + self.get_context_variable, "foo") + except RuntimeError: + pass + + +class TestLiveServer(LiveServerTestCase): + + def create_app(self): + app = create_app() + app.config['LIVESERVER_PORT'] = 8943 + return app + + def test_server_process_is_spawned(self): + process = self._process + + # Check the process is spawned + self.assertNotEqual(process, None) + + # Check the process is alive + self.assertTrue(process.is_alive()) + + def test_server_listening(self): + response = urlopen(self.get_server_url()) + self.assertTrue(b'OK' in response.read()) + self.assertEqual(response.code, 200) + + +class TestNotRenderTemplates(TestCase): + + render_templates = False + + def create_app(self): + return create_app() + + def test_assert_not_process_the_template(self): + response = self.client.get("/template/") + + assert "" == response.data + + def test_assert_template_rendered_signal_sent(self): + self.client.get("/template/") + + self.assert_template_used('index.html') + + +class TestRenderTemplates(TestCase): + + render_templates = True + + def create_app(self): + return create_app() + + def test_assert_not_process_the_template(self): + response = self.client.get("/template/") + + assert "" != response.data + + +class TestRestoreTheRealRender(TestCase): + + def create_app(self): + return create_app() + + def test_assert_the_real_render_template_is_restored(self): + test = TestNotRenderTemplates('test_assert_not_process_the_template') + test_result = TestResult() + test(test_result) + + assert test_result.wasSuccessful() + + response = self.client.get("/template/") + + assert "" != response.data