-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_test.py
73 lines (54 loc) · 1.94 KB
/
app_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
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
import os
import app
import unittest
import tempfile
import StringIO
__author__ = 'bernie'
class ComponentsTestCase(unittest.TestCase):
def setUp(self):
self.db_fd, app.app.config['DATABASE'] = tempfile.mkstemp()
app.app.config['TESTING'] = True
self.app = app.app.test_client()
app.dbconnect(databasename=app.app.config['DATABASE'])
def tearDown(self):
os.close(self.db_fd)
#os.unlink(app.app.config['DATABASE'])
# Check Options to
# list by category
# list all components
# low stock report
def test_checkoptions(self):
rv = self.app.get('/')
assert 'List By Category' in rv.data
assert 'List All Components' in rv.data
assert 'Low Stock Report' in rv.data
# Category search into semiconductors to next level
def test_categorysearch(self):
rv = self.app.get('/categorysearch/0/0')
assert '->Semiconductor' in rv.data
rv = self.app.get('/categorysearch/1/12')
assert '->LED' in rv.data
# Display details of an LED and check the order code
rv = self.app.get('/categorysearch/3/16')
assert '55-0125' in rv.data
# List all components
def test_listall(self):
rv = self.app.get('/showlist/0')
assert 'LED 5mm Red' in rv.data
# Drill down to an LED and check the order code
rv = self.app.get('/showcomponents/8')
assert '55-0120' in rv.data
# Low stock report
def test_lowstock(self):
rv = self.app.get('/showlist/1')
assert 'LED 5mm Red' not in rv.data
assert 'LED 5mm Green' in rv.data
# Open a datasheet
def test_datasheet(self):
with open('docs/led_green_5mm_55-0120.pdf', 'rb') as pdf1:
pdf1StringIO = StringIO.StringIO(pdf1.read())
rv = self.app.get('/docs/led_green_5mm_55-0120.pdf')
pdf1StringIO.seek(0)
assert rv.data == pdf1StringIO.read()
if __name__ == '__main__':
unittest.main()