Skip to content

Commit c39dbb0

Browse files
committed
test: Add coverage improvement test for scrapegraph-py/tests/test_markdownify.py
1 parent 84ba517 commit c39dbb0

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import pytest
2+
from scrapegraph_py.models.markdownify import MarkdownifyRequest, GetMarkdownifyRequest
3+
4+
def test_markdownify_request_invalid_url_scheme():
5+
"""
6+
Test that MarkdownifyRequest raises a ValueError when the website_url does not
7+
start with either 'http://' or 'https://'.
8+
"""
9+
with pytest.raises(ValueError, match="Invalid URL"):
10+
MarkdownifyRequest(website_url="ftp://example.com")
11+
12+
def test_markdownify_request_empty_url():
13+
"""
14+
Test that MarkdownifyRequest raises a ValueError when the website_url is empty or contains only whitespace.
15+
"""
16+
with pytest.raises(ValueError, match="Website URL cannot be empty"):
17+
MarkdownifyRequest(website_url=" ")
18+
19+
def test_markdownify_request_valid_url():
20+
"""
21+
Test that MarkdownifyRequest properly creates an instance when provided with a valid URL.
22+
This covers the scenario where the input URL meets all validation requirements.
23+
"""
24+
valid_url = "https://example.com"
25+
req = MarkdownifyRequest(website_url=valid_url)
26+
assert req.website_url == valid_url
27+
28+
def test_markdownify_request_untrimmed_url():
29+
"""
30+
Test that MarkdownifyRequest raises a ValueError when the website_url contains leading or trailing whitespace.
31+
Although the stripped URL would be valid, the actual value is not processed further, causing the check
32+
for the proper URL scheme to fail.
33+
"""
34+
# The URL has leading whitespace, so it does not start directly with "https://"
35+
with pytest.raises(ValueError, match="Invalid URL"):
36+
MarkdownifyRequest(website_url=" https://example.com")
37+
38+
def test_get_markdownify_request_invalid_uuid():
39+
"""
40+
Test that GetMarkdownifyRequest raises a ValueError when the request_id is not a valid UUID.
41+
"""
42+
with pytest.raises(ValueError, match="request_id must be a valid UUID"):
43+
GetMarkdownifyRequest(request_id="invalid_uuid")
44+
45+
def test_get_markdownify_request_valid_uuid():
46+
"""
47+
Test that GetMarkdownifyRequest properly creates an instance when provided with a valid UUID.
48+
"""
49+
valid_uuid = "123e4567-e89b-12d3-a456-426614174000"
50+
req = GetMarkdownifyRequest(request_id=valid_uuid)
51+
assert req.request_id == valid_uuid
52+
53+
def test_get_markdownify_request_untrimmed_uuid():
54+
"""
55+
Test that GetMarkdownifyRequest raises a ValueError when the request_id
56+
contains leading or trailing whitespace, despite the trimmed UUID being valid.
57+
"""
58+
with pytest.raises(ValueError, match="request_id must be a valid UUID"):
59+
GetMarkdownifyRequest(request_id=" 123e4567-e89b-12d3-a456-426614174000 ")

0 commit comments

Comments
 (0)