-
Notifications
You must be signed in to change notification settings - Fork 4
/
testing.py
98 lines (75 loc) · 2.89 KB
/
testing.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import unittest
from unittest import TestCase
from server import app
from model import connect_to_db, db, User, Company, User_Company, DailyPrice, init_app, example_data
class FlaskTests(TestCase):
def setUp(self):
self.client = app.test_client()
app.config['TESTING'] = True
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
def test_homepage(self):
"""Test homepage"""
print(1)
result = self.client.get("/")
self.assertEqual(result.status_code, 200)
self.assertIn(b"Ideas? Issues? Concerns?", result.data)
def user(self):
"""Test user_stock route"""
print(2)
result = self.client.get("/user_stock")
self.assertEqual(result.status_code,200)
self.assertIn(b"<h3>Current Market Data</h3>", result.data)
def add_stock(self):
"""Test add_stock route"""
print(3)
result = self.client.get('/add_stock')
self.assertEqual(result.status_code, 200)
self.assertIn(b'ENTER A TICKER', result.data)
def sector_performance(self):
"""Test add_stock route"""
print(4)
result = self.client.get('/sector')
self.assertEqual(result.status_code, 200)
self.assertIn(b'<title>Sector Performance</title>', result.data)
def ticker_lookup(self):
"""Test add_stock route"""
print(5)
result = self.client.get('/ticker_lookup')
self.assertEqual(result.status_code, 200)
self.assertIn(b'<h1>Ticker Lookup</h1>', result.data)
def test_login(self):
"""Test login page"""
print(6)
result = self.client.get("/login")
self.assertEqual(result.status_code, 200)
self.assertIn(b'<h1>Login</h1>', result.data)
def test_signup(self):
"""Test register page intiall rendering"""
print(7)
result = self.client.get("/register")
self.assertEqual(result.status_code, 200)
self.assertIn(b'<label>First Name:', result.data)
class FlaskTestsDatabase(TestCase):
def setUp(self):
self.client = app.test_client()
app.config['TESTING'] = True
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
connect_to_db(app, db_uri='postgresql:///testdb')
db.create_all()
#currenty example_data doesn't exist
example_data() #write function in model.py that creates test data for each table
def tearDown(self):
db.session.close()
db.drop_all()
def test_database(self):
"""Test that the test db is being used"""
print(8)
user_count = len(User.query.all())
user_company_count = len(User_Company.query.all())
company_count = len(Company.query.all())
self.assertEqual(user_count, 3)
self.assertEqual(user_company_count, 2)
self.assertEqual(company_count, 2)
if __name__ == "__main__":
unittest.main()
# init_app()