Permalink
Browse files

Merge pull request #9 from arturhoo/master

Complying with Flask new naming standards
  • Loading branch information...
2 parents 18e7f11 + 0dc3a44 commit 7c0a435b08529c2fd482100038764f69dcb45630 @jarus committed May 24, 2012
Showing with 36 additions and 31 deletions.
  1. +7 −3 example/todo.py
  2. 0 flaskext/mongokit.py → flask_mongokit.py
  3. +0 −1 flaskext/__init__.py
  4. +2 −3 setup.py
  5. +27 −24 tests.py
View
@@ -5,6 +5,7 @@
app = Flask(__name__)
+
class Task(Document):
__collection__ = 'tasks'
structure = {
@@ -14,21 +15,24 @@ class Task(Document):
}
required_fields = ['title', 'creation']
default_values = {'creation': datetime.utcnow()}
- use_dot_notation = True
-
+ use_dot_notation = True
+
db = MongoKit(app)
db.register([Task])
+
@app.route('/')
def show_all():
tasks = db.Task.find()
return render_template('list.html', tasks=tasks)
+
@app.route('/<ObjectId:task_id>')
def show_task(task_id):
task = db.Task.get_from_id(task_id)
return render_template('task.html', task=task)
+
@app.route('/new', methods=["GET", "POST"])
def new_task():
if request.method == 'POST':
@@ -40,4 +44,4 @@ def new_task():
return render_template('new.html')
if __name__ == '__main__':
- app.run(debug=True)
+ app.run(debug=True)
File renamed without changes.
View
@@ -1 +0,0 @@
-__import__('pkg_resources').declare_namespace(__name__)
View
@@ -26,8 +26,7 @@
author_email='Christoph.Heer@googlemail.com',
description='A Flask extension simplifies to use MongoKit',
long_description=__doc__,
- py_modules=['flaskext'],
- namespace_packages=['flaskext'],
+ py_modules=['flask_mongokit'],
zip_safe=False,
platforms='any',
install_requires=[
@@ -45,4 +44,4 @@
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
'Topic :: Software Development :: Libraries :: Python Modules'
]
-)
+)
View
@@ -6,11 +6,12 @@
from datetime import datetime
from flask import Flask
-from flaskext.mongokit import MongoKit, BSONObjectIdConverter, \
+from flask_mongokit import MongoKit, BSONObjectIdConverter, \
Document, Collection
from werkzeug.exceptions import BadRequest, NotFound
from bson import ObjectId
+
class BlogPost(Document):
__collection__ = "posts"
structure = {
@@ -23,10 +24,11 @@ class BlogPost(Document):
}
required_fields = ['title', 'author', 'date_creation']
default_values = {'rank': 0, 'date_creation': datetime.utcnow}
- use_dot_notation = True
+ use_dot_notation = True
+
class TestCase(unittest.TestCase):
-
+
def setUp(self):
self.app = Flask(__name__)
self.app.config['TESTING'] = True
@@ -40,71 +42,71 @@ def setUp(self):
self.ctx = self.app.test_request_context('/')
self.ctx.push()
-
+
def tearDown(self):
self.ctx.pop()
-
+
def test_initialization(self):
self.db.register([BlogPost])
-
+
assert len(self.db.registered_documents) > 0
assert self.db.registered_documents[0] == BlogPost
-
+
assert isinstance(self.db, MongoKit)
assert self.db.name == self.app.config['MONGODB_DATABASE']
assert isinstance(self.db.test, Collection)
def test_decorator_registration(self):
-
+
@self.db.register
class DecoratorRegistered(Document):
pass
assert len(self.db.registered_documents) > 0
assert self.db.registered_documents[0] == DecoratorRegistered
-
+
def test_property_connected(self):
assert not self.db.connected
self.db.connect()
assert self.db.connected
-
+
self.db.disconnect()
assert not self.db.connected
-
+
def test_bson_object_id_converter(self):
converter = BSONObjectIdConverter("/")
-
+
self.assertRaises(BadRequest, converter.to_python, ("132"))
assert converter.to_python("4e4ac5cfffc84958fa1f45fb") == \
ObjectId("4e4ac5cfffc84958fa1f45fb")
assert converter.to_url(ObjectId("4e4ac5cfffc84958fa1f45fb")) == \
"4e4ac5cfffc84958fa1f45fb"
-
+
def test_save_and_find_document(self):
self.db.register([BlogPost])
-
+
assert len(self.db.registered_documents) > 0
assert self.db.registered_documents[0] == BlogPost
-
+
post = self.db.BlogPost()
post.title = u"Flask-MongoKit"
post.body = u"Flask-MongoKit is a layer between Flask and MongoKit"
post.author = u"Christoph Heer"
post.save()
-
+
assert self.db.BlogPost.find().count() > 0
rec_post = self.db.BlogPost.find_one({'title': u"Flask-MongoKit"})
assert rec_post.title == post.title
assert rec_post.body == rec_post.body
assert rec_post.author == rec_post.author
-
+
def test_get_or_404(self):
self.db.register([BlogPost])
-
+
assert len(self.db.registered_documents) > 0
assert self.db.registered_documents[0] == BlogPost
-
+
post = self.db.BlogPost()
post.title = u"Flask-MongoKit"
post.body = u"Flask-MongoKit is a layer between Flask and MongoKit"
@@ -121,10 +123,10 @@ def test_get_or_404(self):
def test_find_one_or_404(self):
self.db.register([BlogPost])
-
+
assert len(self.db.registered_documents) > 0
assert self.db.registered_documents[0] == BlogPost
-
+
post = self.db.BlogPost()
post.title = u"Flask-MongoKit"
post.body = u"Flask-MongoKit is a layer between Flask and MongoKit"
@@ -137,13 +139,14 @@ def test_find_one_or_404(self):
self.db.BlogPost.find_one_or_404({'title': u'Flask-MongoKit'})
except NotFound:
self.fail("There should be a document with this title")
- self.assertRaises(NotFound, self.db.BlogPost.find_one_or_404,
+ self.assertRaises(NotFound, self.db.BlogPost.find_one_or_404,
{'title': u'Flask is great'})
+
def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestCase))
return suite
-
+
if __name__ == '__main__':
- unittest.main()
+ unittest.main()

0 comments on commit 7c0a435

Please sign in to comment.