def test_add_address(self): # This test function inspired by and partially paraphrased from: # https://github.com/jbbrokaw/basic-scraper/blob/master/test_scraper.py # Also tests extract_listings(), parse_source() # and return_data_from_file(). with self.assertRaises(TypeError): scraper.add_address() with self.assertRaises(TypeError): scraper.add_address(None) content = scraper.return_data_from_file('search_results.html') encoding = 'utf-8' parsed_html = scraper.parse_source(content, encoding) apartment_listing = scraper.extract_listings(parsed_html).next() assert 'data-latitude' in apartment_listing['location'] assert 'data-longitude' in apartment_listing['location']
def test_add_address_2(): listing = { 'pid': '1', 'location': {'data-latitude': 45.0, 'data-longitude': 90.0} } assert add_address(listing)['address'] == 'S228, Qitai, Changji, Xinjiang, China'
def test_add_address_1(): listing = { 'pid': '1', 'location': {'data-latitude': None, 'data-longitude': None} } assert add_address(listing)['address'] == 'unavailable'