-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtests.py
executable file
·41 lines (35 loc) · 1.26 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
#!/usr/bin/env python
import os
import unittest
from config import basedir
from app import app, db
from app.models import User
class TestCase(unittest.TestCase):
def setUp(self):
app.config['TESTING'] = True
app.config['WTF_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_avatar(self):
u = User(username='john', email='john@example.com')
avatar = u.avatar(128)
expected = 'http://www.gravatar.com/avatar/d4c74594d841139328695756648b6bd6'
assert avatar[0:len(expected)] == expected
def test_make_unique_username(self):
u = User(username='john', email='john@example.com')
db.session.add(u)
db.session.commit()
username = User.make_unique_username('john')
assert username != 'john'
u = User(username=username, email='susan@example.com')
db.session.add(u)
db.session.commit()
username2 = User.make_unique_username('john')
assert username2 != 'john'
assert username2 !=username
if __name__ == '__main__':
unittest.main()