-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
68 lines (56 loc) · 1.9 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
61
62
63
64
65
66
67
68
from datetime import datetime, timedelta
import unittest
from app import create_app, db
from app.models import User, Report, Customer
from config import Config
class TestConfig(Config):
TESTING = True
SQLALCHEMY_DATABASE_URI = 'sqlite://'
class UserModelCase(unittest.TestCase):
def setUp(self):
self.app = create_app(TestConfig)
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_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_create_report(self):
u = User(username='susan')
c = Customer(customer_name='Building')
r = Report(author=u,
customer=c,
summary="No Heat",
action = "Turned on Boiler",
recommendation = "N/A")
self.assertEqual(u, r.author)
self.assertEqual(c, r.customer)
def test_update_username(self):
name1 = 'Steven'
name2 = 'April'
u = User(username=name1)
self.assertEqual(u.getName(), name1)
u.setName(name2)
self.assertEqual(u.getName(), name2)
def test_update_email(self):
email1 = 'test@yahoo.com'
email2 = 'test@gmail.com'
u = User(username = 'test', email=email1)
self.assertEqual(u.getEmail(), email1)
u.setEmail(email2)
self.assertEqual(u.getEmail(), email2)
def test_active_status(self):
u = User()
self.assertTrue(u.isActive())
u.deactivateUser()
self.assertFalse(u.isActive())
u.activateUser()
self.assertTrue(u.isActive())
if __name__ == '__main__':
unittest.main(verbosity=2)