-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
66 lines (50 loc) · 1.83 KB
/
tests.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import os
import unittest
from config import basedir
from app import app, db
from app.models import User, Post
from datetime import datetime
class TestCase(unittest.TestCase):
def setUp(self):
app.config['TESTING'] = True
app.config['CSRF_ENABLED'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'test.db')
self.app = app.test_client()
db.create_all()
def tearDown(self):
db.session.remove()
db.drop_all()
def test_follow(self):
user1 = User(nickname='mitchsvik', password='STRONG', email='[email protected]')
user2 = User(nickname='john', password='qwerty', email='[email protected]')
db.session.add(user1)
db.session.add(user2)
db.session.commit()
assert user1.unfollow(user2) is None
u = user1.follow(user2)
db.session.add(u)
db.session.commit()
assert user1.follow(user2) is None
assert user1.is_following(user2)
assert user1.followed.count() == 1
assert user1.followed.first().nickname == 'john'
assert user2.followers.count() == 1
assert user2.followers.first().nickname == 'mitchsvik'
u = user1.unfollow(user2)
assert u is not None
db.session.add(u)
db.session.commit()
assert user1.is_following(user2) is False
assert user1.followed.count() == 0
assert user2.followers.count() == 0
def test_delete_post(self):
u = User(nickname='mitchsvik', email='[email protected]')
p = Post(body='test', author=u, timestamp=datetime.utcnow())
db.session.add(u)
db.session.add(p)
db.session.commit()
p = Post.query.get(1)
db.session.delete(p)
db.session.commit()
if __name__ == '__main__':
unittest.main()