def test_incorrect_url(): """ Tests that the scrape_page function raises and assertion error when a url is entered with an incorrect domain name (not 'https://everydayhealth.com...') """ scraper = EverydayHealthScraper() with pytest.raises(AssertionError): scraper.scrape_page( 'https://www.drugs.com/comments/aripiprazole/abilify.html?page=1')
def test_scrape_page_with_parameters(): """ Tests to make sure that calling the scrape_page function on a scraper object with a non-default parameter (collect_url true) collects the correct types of data ('comment', 'rating, 'date', 'drug', and 'url') """ scraper = EverydayHealthScraper(collect_urls=True) scraper.scrape_page( 'https://www.everydayhealth.com/drugs/hydroxyzine/reviews') data_collected = list(scraper.reviews[0].keys()) assert len(data_collected) == 5 assert 'url' in data_collected
def test_scrape_page_default_parameters(): """ Tests to make sure that calling the scrape_page function on a scraper object with a default parameter collects the correct types of data ('comment', 'rating', 'date', and 'drug') and that the correct number of reviews were collected (20) """ scraper = EverydayHealthScraper() scraper.scrape_page('https://www.everydayhealth.com/drugs/allegra/reviews') data_collected = list(scraper.reviews[0].keys()) assert len(data_collected) == 4 assert 'comment' in data_collected assert 'rating' in data_collected assert 'date' in data_collected assert 'drug' in data_collected assert len(scraper.reviews) == 20
def test_no_reviews(): """ Tests that the scrape page function returns 'None' when no reviews are found on the page """ scraper = EverydayHealthScraper() returned = scraper.scrape_page( 'https://www.everydayhealth.com/drugs/triprolidine/reviews') assert not returned