Skip to content

Commit d6e6e31

Browse files
committed
Added MANIFEST.in and unittests
1 parent 7ce181a commit d6e6e31

File tree

3 files changed

+97
-10
lines changed

3 files changed

+97
-10
lines changed

MANIFEST.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
include LICENSE *.py
2+
recursive-include docs *
3+
recursive-exclude docs *.pyc
4+
recursive-exclude docs *.pyo
5+
prune docs/_build
6+
prune docs/_themes/.git

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
setup(
1919
name='Flask-SQLAlchemy',
20-
version='0.8',
20+
version='0.9',
2121
url='http://github.com/mitsuhiko/flask-sqlalchemy',
2222
license='BSD',
2323
author='Armin Ronacher',
@@ -33,6 +33,7 @@
3333
'Flask',
3434
'SQLAlchemy'
3535
],
36+
test_suite='test_sqlalchemy',
3637
classifiers=[
3738
'Development Status :: 4 - Beta',
3839
'Environment :: Web Environment',

test_sqlalchemy.py

Lines changed: 89 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,101 @@
11
import unittest
2+
from datetime import datetime
3+
import flask
24
from flaskext import sqlalchemy
35

46

7+
class BasicAppTestCase(unittest.TestCase):
8+
9+
def setUp(self):
10+
app = flask.Flask(__name__)
11+
app.config['SQLALCHEMY_ENGINE'] = 'sqlite://'
12+
app.config['TESTING'] = True
13+
db = sqlalchemy.SQLAlchemy(app)
14+
15+
class Todo(db.Model):
16+
__tablename__ = 'todos'
17+
id = db.Column('todo_id', db.Integer, primary_key=True)
18+
title = db.Column(db.String(60))
19+
text = db.Column(db.String)
20+
done = db.Column(db.Boolean)
21+
pub_date = db.Column(db.DateTime)
22+
23+
def __init__(self, title, text):
24+
self.title = title
25+
self.text = text
26+
self.done = False
27+
self.pub_date = datetime.utcnow()
28+
29+
@app.route('/')
30+
def index():
31+
return '\n'.join(x.title for x in Todo.query.all())
32+
33+
@app.route('/add', methods=['POST'])
34+
def add():
35+
form = flask.request.form
36+
todo = Todo(form['title'], form['text'])
37+
db.session.add(todo)
38+
db.session.commit()
39+
return 'added'
40+
41+
db.create_all()
42+
43+
self.app = app
44+
self.db = db
45+
self.Todo = Todo
46+
47+
def tearDown(self):
48+
self.db.drop_all()
49+
50+
def test_basic_insert(self):
51+
c = self.app.test_client()
52+
c.post('/add', data=dict(title='First Item', text='The text'))
53+
c.post('/add', data=dict(title='2nd Item', text='The text'))
54+
rv = c.get('/')
55+
assert rv.data == 'First Item\n2nd Item'
56+
57+
def test_request_context(self):
58+
self.assertEqual(self.Todo.query, None)
59+
with self.app.test_request_context():
60+
todo = self.Todo('Test', 'test')
61+
self.db.session.add(todo)
62+
self.db.session.commit()
63+
self.assertEqual(len(self.Todo.query.all()), 1)
64+
65+
def test_query_recording(self):
66+
with self.app.test_request_context():
67+
todo = self.Todo('Test 1', 'test')
68+
self.db.session.add(todo)
69+
self.db.session.commit()
70+
71+
queries = sqlalchemy.get_debug_queries()
72+
self.assertEqual(len(queries), 1)
73+
query = queries[0]
74+
self.assert_('insert into' in query.statement.lower())
75+
self.assertEqual(query.parameters[0], 'Test 1')
76+
self.assertEqual(query.parameters[1], 'test')
77+
self.assert_('test_sqlalchemy.py' in query.context)
78+
self.assert_('test_query_recording' in query.context)
79+
80+
def test_helper_api(self):
81+
self.assertEqual(self.db.metadata, self.db.Model.metadata)
82+
83+
584
class PaginationTestCase(unittest.TestCase):
685

786
def test_basic_pagination(self):
887
p = sqlalchemy.Pagination(None, 1, 20, 500, [])
9-
assert p.page == 1
10-
assert not p.has_prev
11-
assert p.has_next
12-
assert p.total == 500
13-
assert p.pages == 25
14-
assert p.next_num == 2
15-
assert list(p.iter_pages()) == [1, 2, 3, 4, 5, None, 24, 25]
88+
self.assertEqual(p.page, 1)
89+
self.assertFalse(p.has_prev)
90+
self.assert_(p.has_next)
91+
self.assertEqual(p.total, 500)
92+
self.assertEqual(p.pages, 25)
93+
self.assertEqual(p.next_num, 2)
94+
self.assertEqual(list(p.iter_pages()),
95+
[1, 2, 3, 4, 5, None, 24, 25])
1696
p.page = 10
17-
assert list(p.iter_pages()) == [1, 2, None, 8, 9, 10, 11,
18-
12, 13, 14, None, 24, 25]
97+
self.assertEqual(list(p.iter_pages()),
98+
[1, 2, None, 8, 9, 10, 11, 12, 13, 14, None, 24, 25])
1999

20100

21101
if __name__ == '__main__':

0 commit comments

Comments
 (0)