Permalink
Browse files

Rename the flaskext.flatpages package to flask_flatpages

  • Loading branch information...
1 parent 65398a6 commit 191aeaf6b53f8391f966c4b6c1d5cebc854fdf16 @SimonSapin SimonSapin committed Jul 3, 2012
View
@@ -4,6 +4,5 @@ recursive-exclude docs *.pyc
recursive-exclude docs *.pyo
prune docs/_build
prune docs/_themes/.git
-recursive-include flaskext/flatpages/tests/pages *
-recursive-include flaskext/flatpages/tests/pages_shift_jis *
-
+recursive-include flask_flatpages/pages *
+recursive-include flask_flatpages/pages_shift_jis *
@@ -1,6 +1,6 @@
# coding: utf8
"""
- flaskext.flatpages
+ flas_flatpages
~~~~~~~~~~~~~~~~~~
Flask-FlatPages provides a collections of pages to your Flask application.
@@ -158,6 +158,7 @@ def get(self, path, default=None):
"""
:Return: the :class:`Page` object at ``path``, or ``default``
if there is none.
+
"""
# This may trigger the property. Do it outside of the try block.
pages = self._pages
@@ -170,6 +171,7 @@ def get_or_404(self, path):
""":Return: the :class:`Page` object at ``path``.
:raises: :class:`NotFound` if the pages does not exist.
This is caught by Flask and triggers a 404 error.
+
"""
page = self.get(path)
if not page:
@@ -19,7 +19,7 @@
import jinja2
from werkzeug.exceptions import NotFound
from flask import Flask
-from flaskext.flatpages import FlatPages
+from flask_flatpages import FlatPages
@contextmanager
@@ -37,7 +37,7 @@ def temp_directory():
def temp_pages(app=None):
"""This context manager gives a FlatPages object configured
in a temporary directory with a copy of the test pages.
-
+
Using a temporary copy allows us to safely write and remove stuff without
worrying about undoing our changes.
"""
@@ -59,7 +59,7 @@ def test_removed(self):
assert os.path.isdir(temp)
# should be removed now
assert not os.path.exists(temp)
-
+
def test_exception(self):
try:
with temp_directory() as temp:
@@ -70,7 +70,7 @@ def test_exception(self):
else:
assert False, 'Exception did not propagate'
assert not os.path.exists(temp)
-
+
def test_writing(self):
with temp_directory() as temp:
filename = os.path.join(temp, 'foo')
@@ -168,7 +168,7 @@ def test_lazy_loading(self):
# bar.html is normally empty
self.assertEquals(bar.meta, {})
self.assertEquals(bar.body, '')
-
+
with temp_pages() as pages:
filename = os.path.join(pages.root, 'foo', 'bar.html')
# write as pages is already constructed
@@ -185,7 +185,7 @@ def test_reloading(self):
# bar.html is normally empty
self.assertEquals(bar.meta, {})
self.assertEquals(bar.body, '')
-
+
filename = os.path.join(pages.root, 'foo', 'bar.html')
# rewrite already loaded page
with open(filename, 'w') as fd:
@@ -198,14 +198,14 @@ def test_reloading(self):
self.assertEquals(bar2.meta, {})
self.assertEquals(bar2.body, '')
self.assert_(bar2 is bar)
-
+
# request reloading
pages.reload()
-
+
# write again
with open(filename, 'w') as fd:
fd.write('\nsecond rewrite')
-
+
# get another page
pages.get('hello')
@@ -219,15 +219,15 @@ def test_reloading(self):
self.assertEquals(bar3.body, 'second rewrite') # not third
# Page objects are not reused when a file is re-read.
self.assert_(bar3 is not bar2)
-
+
# Removing does not trigger reloading either
os.remove(filename)
bar4 = pages.get('foo/bar')
self.assertEquals(bar4.meta, {})
self.assertEquals(bar4.body, 'second rewrite')
self.assert_(bar4 is bar3)
-
+
pages.reload()
bar5 = pages.get('foo/bar')
@@ -237,13 +237,13 @@ def test_caching(self):
with temp_pages() as pages:
foo = pages.get('foo')
bar = pages.get('foo/bar')
-
+
filename = os.path.join(pages.root, 'foo', 'bar.html')
with open(filename, 'w') as fd:
fd.write('\nrewritten')
pages.reload()
-
+
foo2 = pages.get('foo')
bar2 = pages.get('foo/bar')
@@ -256,24 +256,24 @@ def test_caching(self):
def assert_no_auto_reset(self, pages):
bar = pages.get('foo/bar')
self.assertEquals(bar.body, '')
-
+
filename = os.path.join(pages.root, 'foo', 'bar.html')
with open(filename, 'w') as fd:
fd.write('\nrewritten')
# simulate a request (before_request functions are called)
with pages.app.test_request_context():
pages.app.preprocess_request()
-
+
# not updated
bar2 = pages.get('foo/bar')
self.assertEquals(bar2.body, '')
self.assert_(bar2 is bar)
-
+
def assert_auto_reset(self, pages):
bar = pages.get('foo/bar')
self.assertEquals(bar.body, '')
-
+
filename = os.path.join(pages.root, 'foo', 'bar.html')
with open(filename, 'w') as fd:
fd.write('\nrewritten')
@@ -282,12 +282,12 @@ def assert_auto_reset(self, pages):
# pages.reload() is not call explicitly
with pages.app.test_request_context():
pages.app.preprocess_request()
-
+
# updated
bar2 = pages.get('foo/bar')
self.assertEquals(bar2.body, 'rewritten')
self.assert_(bar2 is not bar)
-
+
def test_default_no_auto_reset(self):
with temp_pages() as pages:
self.assert_no_auto_reset(pages)
@@ -314,4 +314,3 @@ def test_configured_auto_reset(self):
if __name__ == '__main__':
unittest.main()
-
@@ -1 +0,0 @@
-__import__('pkg_resources').declare_namespace(__name__)
View
@@ -25,10 +25,9 @@
description='Provides flat static pages to a Flask application',
long_description=__doc__,
packages=find_packages(),
- namespace_packages=['flaskext'],
# test pages
package_data={'': ['pages*/*.*', 'pages/*/*.*', 'pages/*/*/*.*']},
- test_suite='flaskext.flatpages.tests',
+ test_suite='flask_flatpages.tests',
zip_safe=False,
platforms='any',
install_requires=[
View
@@ -1,4 +1,4 @@
[tox]
envlist = py25, py26, py27, pypy
[testenv]
-commands=python setup.py -q test
+commands=python -m flask_flatpages.tests

0 comments on commit 191aeaf

Please sign in to comment.