remove dependency of unittest, use pytest
parent
b0cb247b83
commit
06f26cb29c
|
@ -2,7 +2,6 @@
|
|||
# Generated by CodiumAI
|
||||
|
||||
import requests
|
||||
from unittest.mock import Mock
|
||||
import pytest
|
||||
|
||||
from scripts.browse import scrape_text
|
||||
|
@ -76,7 +75,7 @@ class TestScrapeText:
|
|||
# Tests that the function returns an error message when the response status code is an http error (>=400).
|
||||
def test_http_error(self, mocker):
|
||||
# Mock the requests.get() method to return a response with a 404 status code
|
||||
mocker.patch('requests.get', return_value=Mock(status_code=404))
|
||||
mocker.patch('requests.get', return_value=mocker.Mock(status_code=404))
|
||||
|
||||
# Call the function with a URL
|
||||
result = scrape_text("https://www.example.com")
|
||||
|
@ -85,15 +84,13 @@ class TestScrapeText:
|
|||
assert result == "Error: HTTP 404 error"
|
||||
|
||||
# Tests that scrape_text() properly handles HTML tags.
|
||||
def test_scrape_text_with_html_tags(self):
|
||||
def test_scrape_text_with_html_tags(self, mocker):
|
||||
# Create a mock response object with HTML containing tags
|
||||
html = "<html><body><p>This is <b>bold</b> text.</p></body></html>"
|
||||
response = Mock()
|
||||
response.status_code = 200
|
||||
response.text = html
|
||||
|
||||
# Mock the requests.get() method to return the mock response object
|
||||
requests.get = Mock(return_value=response)
|
||||
mock_response = mocker.Mock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.text = html
|
||||
mocker.patch("requests.get", return_value=mock_response)
|
||||
|
||||
# Call the function with a URL
|
||||
result = scrape_text("https://www.example.com")
|
||||
|
|
Loading…
Reference in New Issue