-
Notifications
You must be signed in to change notification settings - Fork 16
/
tests.py
51 lines (43 loc) · 1.64 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
import unittest
from app import app, db
from app.users import User
class UserModelClass(unittest.TestCase):
@classmethod
def setUpClass(cls):
print('setUp Class')
app.config['SQLALCHEMY_DATABASE_URI'] \
= 'mysql+pymysql://Samuel:tirab33@localhost/assis_testing'
app.config['SQLALCHEMY_ECHO'] = False
db.create_all()
@classmethod
def tearDownClass(cls):
print('tearDown Class')
db.session.remove()
db.drop_all()
def setUp(self):
print('SetUp')
self.u = User(email='[email protected]', leadership=True)
self.u.set_password('[email protected]')
self.l = User(email='[email protected]', leadership=True)
self.l.set_password('[email protected]')
self.r = User(email='[email protected]')
self.r.set_password('[email protected]')
db.session.add(self.u)
db.session.add(self.l)
db.session.add(self.r)
db.session.commit()
def tearDown(self):
print('tearDown')
db.session.query(User).delete()
db.session.commit()
def test_user_creation(self):
returned_u = User.query.filter_by(email='[email protected]').one()
returned_u2 = User.query.filter_by(email='[email protected]').one()
self.assertEqual(returned_u.email, '[email protected]')
self.assertFalse(returned_u2.leadership)
def test_password_hashing(self):
self.assertFalse(self.u.check_password('[email protected]'))
self.assertTrue(self.u.check_password('[email protected]'))
# to test, in console: python tests.py
if __name__ == '__main__':
unittest.main(verbosity=2)