Skip to content

Commit

Permalink
Update test_add_product.py - add exception expectation
Browse files Browse the repository at this point in the history
  • Loading branch information
Crinibus committed Sep 16, 2022
1 parent 713df95 commit 862aa3d
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions tests/test_add_product.py
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)

0 comments on commit 862aa3d

Please sign in to comment.