-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.py
60 lines (45 loc) · 1.7 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
import unittest
from app import db, create_app
from app.queue.models import Queue, UserQueue
from app.auth.models import User
from app.config import Config
class UserModelCase(unittest.TestCase):
def setUp(self):
config_obj = Config()
config_obj.SQLALCHEMY_DATABASE_URI = 'sqlite://'
app = create_app(config_obj)
db.session.remove()
db.drop_all()
db.create_all()
def tearDown(self):
db.session.remove()
db.drop_all()
def test_password_hashing(self):
u = User(username='susan')
u.set_password('cat')
self.assertFalse(u.check_password('dog'))
self.assertTrue(u.check_password('cat'))
def test_avatar(self):
u = User(username='john', email='[email protected]')
self.assertEqual(u.avatar(128), ('https://www.gravatar.com/avatar/'
'd4c74594d841139328695756648b6bd6'
'?d=identicon&s=128'))
def test_queue(self):
u1 = User(username='u1', email='[email protected]')
u2 = User(username='u2', email='[email protected]')
u3 = User(username='u3', email='[email protected]')
q1 = Queue(name="q")
q2 = Queue(name="q")
q1.add_member(u1, 'u1 printed')
q1.add_member(u2, 'u2 printed')
db.session.add_all([u1, u2, u3, q1, q2])
db.session.commit()
self.assertEqual(2, len(q1.members))
self.assertTrue(q1.contains(u1))
self.assertFalse(q1.contains(u3))
q1.remove_member(u1)
db.session.commit()
self.assertEqual(1, len(q1.members))
self.assertFalse(q1.contains(u1))
if __name__ == '__main__':
unittest.main(verbosity=2)