Skip to content

Commit

Permalink
Rename the flaskext.flatpages package to flask_flatpages
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Jul 3, 2012
1 parent 65398a6 commit 191aeaf
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 28 deletions.
5 changes: 2 additions & 3 deletions MANIFEST.in
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
39 changes: 19 additions & 20 deletions flaskext/flatpages/tests/__init__.py → flask_flatpages/tests.py
Expand Up @@ -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
Expand All @@ -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.
"""
Expand All @@ -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:
Expand All @@ -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')
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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')

Expand All @@ -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')
Expand All @@ -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')

Expand All @@ -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')
Expand All @@ -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)
Expand All @@ -314,4 +314,3 @@ def test_configured_auto_reset(self):

if __name__ == '__main__':
unittest.main()

1 change: 0 additions & 1 deletion flaskext/__init__.py

This file was deleted.

3 changes: 1 addition & 2 deletions setup.py
Expand Up @@ -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=[
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
@@ -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.