-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_user_model.py
44 lines (35 loc) · 1.47 KB
/
test_user_model.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
import unittest
from server import app, db, connect_to_db, User, Dashboard
class TestModels(unittest.TestCase):
def setUp(self):
"""Set up the test environment"""
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.drop_all()
db.create_all()
connect_to_db(app, db_uri=app.config['SQLALCHEMY_DATABASE_URI'])
def tearDown(self):
"""Tear down the test environment"""
db.session.remove()
db.drop_all()
def test_user_model(self):
"""Test the User model"""
user = User(fname='John', lname='Doe', email='[email protected]', password='password123')
db.session.add(user)
db.session.commit()
self.assertEqual(user.fname, 'John')
self.assertEqual(user.lname, 'Doe')
self.assertEqual(user.email, '[email protected]')
self.assertEqual(user.password, 'password123')
def test_dashboard_model(self):
"""Test the Dashboard model"""
user = User(fname='John', lname='Doe', email='[email protected]', password='password123')
db.session.add(user)
db.session.commit()
dashboard = Dashboard(dashboard_title='My Dashboard', user=user)
db.session.add(dashboard)
db.session.commit()
self.assertEqual(dashboard.dashboard_title, 'My Dashboard')
self.assertEqual(dashboard.user, user)
if __name__ == '__main__':
unittest.main()