def test_single_web_page_extract_method_for_address(self): """Test if an individual address is correctly extracted """ swp = nyt.single_web_page(self.soup_1) swp.extract_data() self.assertEqual( str(swp.soup.find_all("p",class_= "listing-detail-text listing-address")[0]),\ '<p class="listing-detail-text listing-address" title="155 West 11th Street">\n 155 West 11th Street </p>')
def test_single_web_page_extract_method_for_bed_bath(self): """Test if bed/bath html soup is correctly extracted """ swp = nyt.single_web_page(self.soup_1) swp.extract_data() self.assertEqual( str(swp.soup.find_all("p", class_= "listing-detail-text size-description")[0]),\ '<p class="listing-detail-text size-description">\n<span>3 Beds</span>\n<span class="border">|</span>\n<span>3 Baths</span>\n<span class="border">|</span>\n<span>Condo</span>\n</p>')
def test_single_web_page_extract_method_for_neighborhood(self): """Test if 'neighborhood' is correctly extracted """ swp = nyt.single_web_page(self.soup_1) swp.extract_data() self.assertEqual( str(swp.soup.find_all("p", {"class": "listing-neighborhood"})[0]), \ '<p class="listing-neighborhood" data-city="New York">\n West Village </p>')
def test_single_web_page_extract_method_for_listing_price(self): """Test if an individual listing price is correctly extracted """ swp = nyt.single_web_page(self.soup_1) swp.extract_data() self.assertEqual( str(swp.soup.find_all("p", {"class": "listing-price"})[0]), \ '<p class="listing-price">\n $17,750,000 </p>')
def test_single_web_page(self): """ Test end to end functionality of single_web_page Class by observing a single listing """ swp = nyt.single_web_page(self.soup_1) swp.extract_data() self.assertEqual(swp.transform_data()[0],[u'17750000', 3,3,\ 'West Village','40.736173','-74.000069',\ '155 West 11th Street'])
def test_single_web_page_longitude(self): """ Test end to end functionality of longitude feature """ swp = nyt.single_web_page(self.soup_1) swp.extract_data() self.assertEqual( swp.soup.find_all("div", {"data-latitude": True})[0]['data-longitude'], '-74.000069')
def test_single_web_page_transform_method_beds(self): """ Test if transform_data method cleans bed/bath html for output """ swp = nyt.single_web_page(self.soup_1) swp.extract_data() self.assertEqual( str(swp.soup.find_all("p",\ class_= "listing-detail-text size-description")[0]\ .contents[1].get_text()), \ '3 Beds')
def test_single_web_page_transform_method_for_neighborhood(self): """Test if 'neighborhood' extract is properly transformed for output """ swp = nyt.single_web_page(self.soup_1) swp.extract_data() self.assertEqual( str(swp.soup.find_all("p",\ {"class": "listing-neighborhood"})[0].text.strip() \ .replace("\n","") \ .replace(",","") \ .encode('ascii','ignore')),'West Village')
def test_single_web_page_transform_method_listing_price(self): """ Test if transform_data method cleans html listing price for output """ swp = nyt.single_web_page(self.soup_1) swp.extract_data() self.assertEqual(swp.transform_data()[0][0], u'17750000')