Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add error raising to get_soup #7

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/get_soup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

def get_soup(url):
response = requests.get(url)
if response.status_code != 200:
raise Exception("INSERT HTML ERROR WHEN YOU KNOW HOW TO MOCK THIS")
response.raise_for_status()
soup = BeautifulSoup(response.text, "html.parser")
return soup
10 changes: 6 additions & 4 deletions test/test_get_soup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from bs4 import BeautifulSoup
from unittest.mock import patch, Mock
from requests.exceptions import HTTPError
import pytest


Expand Down Expand Up @@ -34,8 +35,9 @@ def test_a_bad_status_code_raises_an_error():
response_mock = Mock()
response_mock.status_code = test_resp_status
response_mock.text = test_resp_text
with patch(f"{PATCH_PATH}.requests") as requests_mock:
requests_mock.get.return_value = response_mock
with pytest.raises(Exception) as err:
response_mock.raise_for_status.side_effect = HTTPError("404 It ain't here")
with patch(f"{PATCH_PATH}.requests.get") as requests_mock:
requests_mock.return_value = response_mock
with pytest.raises(HTTPError) as err:
get_soup(test_url)
assert str(err.value) == "INSERT HTML ERROR WHEN YOU KNOW HOW TO MOCK THIS"
assert str(err.value) == "404 It ain't here"
Loading