-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update test_add_product.py - add exception expectation
- Loading branch information
Showing
1 changed file
with
22 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,38 @@ | ||
import pytest | ||
from contextlib import nullcontext as does_not_raise | ||
|
||
from scraper.add_product import add_product | ||
from scraper.exceptions import WebsiteNotSupported | ||
|
||
test_domains = [ | ||
"https://www.amazon.com/", | ||
"https://www.ebay.com/", | ||
"https://www.komplett.dk/", | ||
"https://www.proshop.dk/", | ||
"https://www.computersalg.dk/", | ||
"https://www.elgiganten.dk/", | ||
"https://www.avxperten.dk/", | ||
"https://www.av-cables.dk/", | ||
"https://www.power.dk/", | ||
"https://www.expert.dk/", | ||
"https://www.mm-vision.dk/", | ||
"https://www.coolshop.dk/", | ||
"https://www.sharkgaming.dk/", | ||
"https://www.newegg.com/", | ||
"https://www.hifiklubben.dk/", | ||
("https://www.amazon.com/", does_not_raise()), | ||
("https://www.ebay.com/", does_not_raise()), | ||
("https://www.komplett.dk/", does_not_raise()), | ||
("https://www.proshop.dk/", does_not_raise()), | ||
("https://www.computersalg.dk/", does_not_raise()), | ||
("https://www.elgiganten.dk/", does_not_raise()), | ||
("https://www.avxperten.dk/", does_not_raise()), | ||
("https://www.av-cables.dk/", does_not_raise()), | ||
("https://www.power.dk/", does_not_raise()), | ||
("https://www.expert.dk/", does_not_raise()), | ||
("https://www.mm-vision.dk/", does_not_raise()), | ||
("https://www.coolshop.dk/", does_not_raise()), | ||
("https://www.sharkgaming.dk/", does_not_raise()), | ||
("https://www.newegg.com/", does_not_raise()), | ||
("https://www.hifiklubben.dk/", does_not_raise()), | ||
("https://www.notsupported.com/", pytest.raises(WebsiteNotSupported)), | ||
] | ||
|
||
|
||
# Tests to make sure the websites that are supported can be added to be scraped | ||
@pytest.mark.parametrize("url", test_domains) | ||
def test_add_product(url, mocker): | ||
@pytest.mark.parametrize("url,expectation", test_domains) | ||
def test_add_product(url, expectation, mocker): | ||
mocker.patch("scraper.Scraper.scrape_info", return_value=None) | ||
mocker.patch("scraper.Scraper.save_info", return_value=None) | ||
mocker.patch("scraper.filemanager.Filemanager.add_product_to_csv", return_value=None) | ||
mocker.patch("scraper.add_product.check_if_product_exists", return_value=False) | ||
mocker.patch("scraper.add_product.check_if_product_exists_csv", return_value=False) | ||
mocker.patch("scraper.add_product.add_product_to_records", return_value=None) | ||
|
||
# expect no exceptions to raise | ||
add_product("test", url) | ||
with expectation: | ||
add_product("test", url) |