-
Notifications
You must be signed in to change notification settings - Fork 8
/
test.py
35 lines (26 loc) · 982 Bytes
/
test.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
import unittest
from app import create_app, db, bcrypt
from app.auth.models import User
class TestUserLogin(unittest.TestCase):
def setUp(self):
self.app = create_app("testing")
self.app_context = self.app.app_context()
self.app_context.push()
db.create_all()
def tearDown(self):
db.session.remove()
db.drop_all()
self.app_context.pop()
def test_add_user(self):
user = User(username='username', email='user@email.com', password='password')
db.session.add(user)
db.session.commit()
assert len(User.query.all()) == 1
def test_check_password(self):
user = User(username='username', email='user@email.com', password='password')
db.session.add(user)
db.session.commit()
user = User.query.filter_by(username='username').first()
assert bcrypt.check_password_hash(user.password, 'password')
if __name__ == '__main__':
unittest.main()