-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathserver_test.py
95 lines (61 loc) · 2.59 KB
/
server_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import unittest
from flask import session
import server
from model import *
from server import app
class FlaskServerIntegrationTests(unittest.TestCase):
""" Integration testing for Investable's server. """
def setUp(self):
""" Sets up a new client test app before each test. """
self.client = app.test_client()
app.config['TESTING'] = True
def test_homepage(self):
""" Test that the homepage route loads. """
result = self.client.get('/')
self.assertEqual(result.status_code, 200)
# import pdb; pdb.set_trace()
self.assertIn('<h1>Find rental property real estate that is <span id="appname">Investable</span>.', result.data)
self.assertIn('Search Again', result.data)
def test_search(self):
""" Test that the search route returns a response. """
app.zwsid = app.zwsid
result = self.client.get('/search.json')
self.assertEqual(result.status_code, 200)
class FlaskDatabaseTests(unittest.TestCase):
""" Flask tests that use the database. """
def setUp(self):
""" Sets up a new client test app and database before each test. """
self.client = app.test_client()
app.config['TESTING'] = True
# Connect to test database
connect_to_db_flask(app, 'postgresql:///testdb')
# Create tables and add sample data
db.create_all()
sample_data()
def tearDown(self):
"""Drop database after every test."""
db.session.close()
db.drop_all()
def test_user(self):
""" Make sure we can find a user. """
glinda = User.query.filter(User.firstname == 'glinda').first()
self.assertEqual('glinda', glinda.firstname)
self.assertEqual('[email protected]', glinda.email)
def test_listing(self):
""" Make sure we can find a listing. """
listing = Listing.query.get(38478998)
self.assertEqual(38478998, listing.zpid)
self.assertEqual(350, listing.hoa)
self.assertEqual(980430, listing.price)
def test_unit_details(self):
""" Make sure we can find unit details. """
listing = Listing.query.get(38478998)
self.assertEqual(2.0, listing.unitdetails.bedrooms)
self.assertEqual(1190, listing.unitdetails.sqft)
self.assertEqual(37.7872375, listing.unitdetails.latitude)
def test_rentals(self):
""" Make sure we can find a rental. """
rental = Rental.query.filter(Rental.cl_id == '6007117642').first()
self.assertEqual(1885, rental.price)
if __name__ == "__main__":
unittest.main()