Beispiel #1
0
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://drugratingz.com...')
    """
    scraper = DrugRatingzScraper()
    with pytest.raises(AssertionError):
        scraper.scrape_page(
            'https://www.drugs.com/comments/aripiprazole/abilify.html?page=1')
Beispiel #2
0
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 = DrugRatingzScraper(collect_urls=True)
    scraper.scrape_page(
        'https://www.drugratingz.com/reviews/141/Drug-Prednisone.html')
    data_collected = list(scraper.reviews[0].keys())
    assert len(data_collected) == 5
    assert 'url' in data_collected
Beispiel #3
0
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 (13)
    """
    scraper = DrugRatingzScraper()
    scraper.scrape_page(
        'https://www.drugratingz.com/reviews/141/Drug-Prednisone.html')
    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) == 13
Beispiel #4
0
def test_no_reviews():
    """
    Tests that the scrape page function returns 'None' when no reviews are
    found on the page
    """
    scraper = DrugRatingzScraper()
    returned = scraper.scrape_page(
        'https://www.drugratingz.com/reviews/18088/Drug-Affinitor.html')
    assert not returned