Skip to content

Commit

Permalink
Update test_browse_scrape_text.py
Browse files Browse the repository at this point in the history
  • Loading branch information
AndresCdo committed Apr 20, 2023
1 parent 4983ddb commit ad739e0
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/unit/test_browse_scrape_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@


class TestScrapeText:
"""Tests for the scrape_text function."""
# Tests that scrape_text() returns the expected text when given a valid URL.
def test_scrape_text_with_valid_url(self, mocker):
# Mock the requests.get() method to return a response with expected text
Expand All @@ -61,6 +62,7 @@ def test_scrape_text_with_valid_url(self, mocker):
# Tests that the function returns an error message when an invalid or unreachable
# url is provided.
def test_invalid_url(self, mocker):
"""Test that the function returns an error message when an invalid or unreachable url is provided."""
# Mock the requests.get() method to raise an exception
mocker.patch(
"requests.Session.get", side_effect=requests.exceptions.RequestException
Expand All @@ -75,6 +77,7 @@ def test_invalid_url(self, mocker):
# Tests that the function returns an empty string when the html page contains no
# text to be scraped.
def test_no_text(self, mocker):
""""Test that the function returns an empty string when the html page contains no text to be scraped."""
# Mock the requests.get() method to return a response with no text
mock_response = mocker.Mock()
mock_response.status_code = 200
Expand All @@ -88,6 +91,7 @@ def test_no_text(self, mocker):
# Tests that the function returns an error message when the response status code is
# an http error (>=400).
def test_http_error(self, mocker):
"""Test that the function returns an error message when the response status code is an http error (>=400)."""
# Mock the requests.get() method to return a response with a 404 status code
mocker.patch("requests.Session.get", return_value=mocker.Mock(status_code=404))

Expand All @@ -99,6 +103,7 @@ def test_http_error(self, mocker):

# Tests that scrape_text() properly handles HTML tags.
def test_scrape_text_with_html_tags(self, mocker):
"""Test that scrape_text() properly handles HTML tags."""
# Create a mock response object with HTML containing tags
html = "<html><body><p>This is <b>bold</b> text.</p></body></html>"
mock_response = mocker.Mock()
Expand Down

0 comments on commit ad739e0

Please sign in to comment.