Skip to content

Commit 739c157

Browse files
Parameterize test_404()
1 parent 3c17afd commit 739c157

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed

tests/test_norwegianblue.py

+15-25
Original file line numberDiff line numberDiff line change
@@ -389,39 +389,29 @@ def test_all_products(self) -> None:
389389
assert output == expected
390390

391391
@respx.mock
392-
def test_404(self) -> None:
393-
# Arrange
394-
mocked_url = "https://endoflife.date/api/androd.json"
395-
respx.get(mocked_url).respond(status_code=404)
396-
397-
mocked_url = "https://endoflife.date/api/all.json"
398-
mocked_response = SAMPLE_RESPONSE_ALL_JSON
399-
respx.get(mocked_url).respond(content=mocked_response)
400-
401-
# Act / Assert
402-
with pytest.raises(
403-
ValueError,
404-
match=r"Product 'androd' not found, run 'eol all' for list\. "
405-
r"Did you mean: 'android'?",
406-
):
407-
norwegianblue.norwegianblue(product="androd")
408-
409-
@respx.mock
410-
def test_404_no_suggestions(self) -> None:
392+
@pytest.mark.parametrize(
393+
"product, expected",
394+
[
395+
(
396+
"androd",
397+
r"Product 'androd' not found, run 'eol all' for list\. "
398+
r"Did you mean: 'android'?",
399+
),
400+
("julia", r"Product 'julia' not found, run 'eol all' for list\."),
401+
],
402+
)
403+
def test_404(self, product, expected) -> None:
411404
# Arrange
412-
mocked_url = "https://endoflife.date/api/julia.json"
405+
mocked_url = f"https://endoflife.date/api/{product}.json"
413406
respx.get(mocked_url).respond(status_code=404)
414407

415408
mocked_url = "https://endoflife.date/api/all.json"
416409
mocked_response = SAMPLE_RESPONSE_ALL_JSON
417410
respx.get(mocked_url).respond(content=mocked_response)
418411

419412
# Act / Assert
420-
with pytest.raises(
421-
ValueError,
422-
match=r"Product 'julia' not found, run 'eol all' for list\.",
423-
):
424-
norwegianblue.norwegianblue(product="julia")
413+
with pytest.raises(ValueError, match=expected):
414+
norwegianblue.norwegianblue(product=product)
425415

426416
def test_norwegianblue_norwegianblue(self) -> None:
427417
# Act

0 commit comments

Comments
 (0)