Skip to content

Commit 79b147d

Browse files
author
alevis
committed
added tests.py
1 parent ca89115 commit 79b147d

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os
2+
import unittest
3+
4+
from config import basedir
5+
from app import app, db
6+
from app.models import User
7+
8+
class TestCase(unittest.TestCase):
9+
def setUp(self):
10+
app.config['TESTING'] = True
11+
app.config['WTF_CSRF_ENABLED'] = False
12+
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'+os.path.join(basedir,'test.db')
13+
self.app = app.test_client()
14+
db.create_all()
15+
16+
def tearDown(self):
17+
db.session.remove()
18+
db.drop_all()
19+
20+
def test_avatar(self):
21+
u = User(nickname='john',email='[email protected]')
22+
avatar = u.avatar(120)
23+
expected = 'http://www.gravatar.com/avatar/d4c74594d841139328695756648b6bd6'
24+
assert avatar[0:len(expected)] == expected
25+
def test_make_unique_nickname(self):
26+
u = User(nickname='john',email='[email protected]')
27+
db.session.add(u)
28+
db.session.commit()
29+
nickname = User.make_unique_nickname('john')
30+
assert nickname2 != 'john'
31+
u = User(nickname=nickname, email='[email protected]')
32+
db.session.add(u)
33+
db.session.commit()
34+
nickname2 = User.make_unique_nickname('john')
35+
assert nickname2 != 'john'
36+
assert nickname2 != nickname
37+
if __name__ == '__main__':
38+
unittest.main()

0 commit comments

Comments
 (0)