예제 #1
0
def test_scrape_page_incorrect_website():
    """
    Tests that the scrape_page function raises an assertion error
    when a url is entered with an incorrect domain name (not 'https://drugs.com...')
    """
    scraper = DrugsScraper()
    with pytest.raises(AssertionError):
        scraper.scrape_page('https://www.webmd.com/drugs/drugreview-64439-abilify.aspx?drugid=64439&drugname=abilify')
예제 #2
0
def test_scrape_page_with_parameters():
    """
    Tests to make sure that calling the scrape_page function
    on a scraper object with non-default parameters (collect_url
    and collect_user_id true) collects the correct types of
    data ('comment', 'rating', 'date', 'drug', 'url', and 'user id')
    """
    scraper = DrugsScraper(collect_user_ids=True, collect_urls=True)
    scraper.scrape_page('https://www.drugs.com/comments/acetaminophen/?page=2')
    data_collected = list(scraper.reviews[0].keys())
    assert len(data_collected) == 6
    assert 'user id' in data_collected
    assert 'url' in data_collected
예제 #3
0
def test_scrape_page_default_parameters():
    """
    Tests to make sure that calling the scrape_page function
    on a scraper object with default parameters collects the
    correct types of data ('comment', 'rating', 'date', and 'drug')
    and that the correct number of reviews (25) were collected
    """
    scraper = DrugsScraper()
    scraper.scrape_page('https://www.drugs.com/comments/acetaminophen/?page=2')
    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) == 25
예제 #4
0
def test_scrape_page_no_reviews():
    """
    Tests that the scrape page function returns 0 when
    no reviews are found on the page
    """
    scraper = DrugsScraper()
    returned = scraper.scrape_page('https://www.drugs.com/comments/xylitol/')
    assert returned == 0