Skip to content

Commit 2c6d829

Browse files
committed
Mock read file from url to avoid real HTTP call.
1 parent b07a85d commit 2c6d829

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

tests/dicts/io/test_io_dict_html.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,26 @@ def test_from_html_with_valid_url_valid_content(self) -> None:
4848
expected_title = (
4949
"Fabio Caccamo - Python/Django full-stack developer - Torino, Italy"
5050
)
51-
url = "https://github.com/fabiocaccamo/python-benedict/raw/s3/tests/dicts/io/input/valid-content.html"
52-
# static method
53-
d = IODict.from_html(url)
54-
self.assertTrue(isinstance(d, dict))
55-
self.assertEqual(d["html"]["head"]["title"], expected_title)
56-
# constructor explicit format
57-
d = IODict(url, format="html")
58-
self.assertTrue(isinstance(d, dict))
59-
self.assertEqual(d["html"]["head"]["title"], expected_title)
60-
# constructor implicit format (because there is not .html extension in the url)
51+
url = "https://fabiocaccamo.com"
52+
53+
# mock fsutil.read_file_from_url to avoid real HTTP calls
54+
with patch("benedict.dicts.io.io_util.fsutil.read_file_from_url") as mock_read:
55+
filepath = self.input_path("valid-content.html")
56+
with open(filepath, encoding="utf-8") as file:
57+
mock_html_content = file.read()
58+
mock_read.return_value = mock_html_content
59+
60+
# static method
61+
d = IODict.from_html(url)
62+
self.assertTrue(isinstance(d, dict))
63+
self.assertEqual(d["html"]["head"]["title"], expected_title)
64+
65+
# constructor explicit format
66+
d = IODict(url, format="html")
67+
self.assertTrue(isinstance(d, dict))
68+
self.assertEqual(d["html"]["head"]["title"], expected_title)
69+
70+
# constructor implicit format (because there is not . html extension in the url)
6171
with self.assertRaises(ValueError):
6272
_ = IODict(url)
6373

0 commit comments

Comments
 (0)