-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
executable file
·85 lines (68 loc) · 2.37 KB
/
Copy pathtest.py
File metadata and controls
executable file
·85 lines (68 loc) · 2.37 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!venv/bin/python3
import os
import unittest
from config import basedir
from app import app, db
from app.models import Vehicle, GasStop
from datetime import datetime
class TestCase(unittest.TestCase):
def setUp(self):
app.config['TESTING'] = True
app.config['CSRF_ENABLED'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = \
'sqlite:///' + os.path.join(basedir, 'test.db')
self.app = app.test_client()
db.create_all()
def tearDown(self):
db.session.remove()
db.drop_all()
def test_vehicle_password_setter(self):
v = Vehicle(password='Testing Password')
self.assertTrue(v.password_hash is not None)
def test_no_password_getter(self):
v = Vehicle(password='Testing Password')
with self.assertRaises(AttributeError):
v.password
def test_password_verification(self):
v = Vehicle(password='Testing Password')
db.session.add(v)
db.session.commit()
veh = Vehicle.query.first()
self.assertTrue(veh.verify_password('Testing Password'))
self.assertFalse(veh.verify_password('Wrong Password'))
def test_password_salts_are_random(self):
v1 = Vehicle(password='password')
v2 = Vehicle(password='password')
self.assertTrue(v1.password_hash != v2.password_hash)
def test_is_authenticated(self):
v = Vehicle()
self.assertTrue(v.is_authenticated)
def test_is_active(self):
v = Vehicle()
self.assertTrue(v.is_active)
def test_is_anonymous(self):
v = Vehicle()
self.assertFalse(v.is_anonymous)
def test_mileage(self):
v = Vehicle(total_mileage=10.9)
v.add_mileage(10.2)
self.assertTrue(v.mileage == 21.1)
def test_set_mileage(self):
v = Vehicle(total_mileage=20)
v.set_mileage(10)
self.assertTrue(v.mileage == 10)
def test_gas_stop(self):
v = Vehicle(name='Ranger')
GasStop(gallons=10.5,
price=1.25,
trip=123.45,
vehicle=v)
stop = v.gas_stop.all()[0]
stop.mpg = stop.trip / stop.gallons
assert stop.gallons == 10.5
assert stop.price == 1.25
assert stop.trip == 123.45
assert stop.mpg == 123.45 / 10.5
assert stop.vehicle.name == 'Ranger'
if __name__ == '__main__':
unittest.main()