-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_db.py
51 lines (39 loc) · 1.78 KB
/
test_db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import unittest
from peewee import *
from app import TimelinePost
MODELS = [TimelinePost]
# use an in-memory SQLite for tests.
test_db = SqliteDatabase(':memory:')
class TestTimelinePost(unittest.TestCase):
def setUp(self):
# Bind model classes to test db. Since we have a complete list of
# all models, we do not need to recursively bind dependencies.
test_db.bind(MODELS, bind_refs=False, bind_backrefs=False)
test_db.connect()
test_db.create_tables(MODELS)
def tearDown(self):
test_db.drop_tables(MODELS)
# Close connection to db.
test_db.close()
def test_timeline_post(self):
# Create 2 timeline posts.
first_post = TimelinePost.create(name='John Doe',
email='[email protected]',
content='Hello World, I\'m John!')
assert first_post.id == 1
second_post = TimelinePost.create(name='Jane Doe',
email='[email protected]',
content='Hello World, I\'m Jane!')
assert second_post.id == 2
# Get timeline posts and assert that they are correct
createdPosts = TimelinePost.select().order_by(TimelinePost.id)
# Assert information from first post
assert createdPosts[0].id == 1
assert createdPosts[0].name == 'John Doe'
assert createdPosts[0].email == '[email protected]'
assert createdPosts[0].content == 'Hello World, I\'m John!'
# Assert information from second post
assert createdPosts[1].id == 2
assert createdPosts[1].name == 'Jane Doe'
assert createdPosts[1].email == '[email protected]'
assert createdPosts[1].content == 'Hello World, I\'m Jane!'