-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathzillow_utilities_test.py
77 lines (47 loc) · 2.39 KB
/
zillow_utilities_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
import unittest
import os
from zillow_utilities import *
class ZillowTests (unittest.TestCase):
""" Unit testing for zillow_utilities. """
def setUp(self):
""" Setup before each test. """
self.maxDiff = None
# Get the Flask test client
self.client = app.test_client()
self.mock_file_content = 'mock_zillow_api_xml_parsed.html'
# Mock an address
self.current_script_directory = os.path.dirname(os.path.realpath(__file__))
self.mock_address = 'file://' + self.current_script_directory + '/' + self.mock_file_content
# self.mock_api_xml_parsed = BeautifulSoup(self.mock_api_xml, 'lxml-xml')
self.mock_api_response_code = 0
def test_format_api_url(self):
# Mock an address
self.mock_address = {'address': '151 Bacardi Ave.', 'citystatezip': 'san francisco ca' }
self.assertEqual('http://www.zillow.com/webservice/GetDeepSearchResults.htm?zws-id=' + app.zwsid + '&citystatezip=san+francisco+ca&address=151+Bacardi+Ave.', format_api_url(self.mock_address))
def test_get_api_xml(self):
# Mock an API response parsed by BeautifulSoup
self.mock_api_xml = open(self.mock_file_content).read()
self.assertEqual(self.mock_api_xml, get_api_xml(self.mock_address))
def test_parse_xml(self):
parsed_xml = parse_xml(self.mock_address)
self.assertEqual(0, parsed_xml['api_response_code'])
def test_get_zillow_html_url(self):
self.assertEqual('http://www.zillow.com/homedetails/151-Bacardi-Ave-San-Francisco-CA-94109/11111111_zpid/', get_zillow_html_url(self.mock_address))
def parse_html(self):
pass
def test_get_unit_price(self):
self.assertEqual((100, '$1,500,500'), get_unit_price(self.mock_address))
def test_get_zillow_price_estimate(self):
self.assertEqual('1395020',get_zillow_price_estimate(self.mock_address))
def test_get_zillow_unit_details(self):
self.assertEqual({'neighborhood': 'Tenderloin',
'latlng_point': 'POINT(37.729981 -122.452644)',
'bedrooms': '3',
'bathrooms': '2.5',
'sqft': '1386'
}, get_zillow_unit_details(self.mock_address))
def tearDown(self):
""" Tear down at end of each test. """
pass
if __name__ == "__main__":
unittest.main()