Karim shoair commited on
Commit ·
b2b1af0
1
Parent(s): a5f9b38
test: update the tests accordingly
Browse files
tests/cli/test_cli.py
CHANGED
|
@@ -17,7 +17,6 @@ def configure_selector_mock():
|
|
| 17 |
mock_response.html_content = "<html><body>Test content</body></html>"
|
| 18 |
mock_response.encoding = "utf-8"
|
| 19 |
mock_response.get_all_text.return_value = "Test content"
|
| 20 |
-
mock_response.css_first.return_value = mock_response
|
| 21 |
mock_response.css.return_value = [mock_response]
|
| 22 |
return mock_response
|
| 23 |
|
|
|
|
| 17 |
mock_response.html_content = "<html><body>Test content</body></html>"
|
| 18 |
mock_response.encoding = "utf-8"
|
| 19 |
mock_response.get_all_text.return_value = "Test content"
|
|
|
|
| 20 |
mock_response.css.return_value = [mock_response]
|
| 21 |
return mock_response
|
| 22 |
|
tests/parser/test_general.py
CHANGED
|
@@ -147,7 +147,7 @@ class TestTextMatching:
|
|
| 147 |
class TestSimilarElements:
|
| 148 |
def test_finding_similar_products(self, page):
|
| 149 |
"""Test finding similar product elements"""
|
| 150 |
-
first_product = page.
|
| 151 |
similar_products = first_product.find_similar()
|
| 152 |
assert len(similar_products) == 2
|
| 153 |
|
|
@@ -255,7 +255,7 @@ class TestElementNavigation:
|
|
| 255 |
class TestJSONAndAttributes:
|
| 256 |
def test_json_conversion(self, page):
|
| 257 |
"""Test converting content to JSON"""
|
| 258 |
-
script_content = page.css("#page-data::text")[0]
|
| 259 |
assert issubclass(type(script_content.sort()), str)
|
| 260 |
page_data = script_content.json()
|
| 261 |
assert page_data["totalProducts"] == 3
|
|
@@ -282,7 +282,7 @@ class TestJSONAndAttributes:
|
|
| 282 |
assert list(key_value[0].keys()) == ["data-id"]
|
| 283 |
|
| 284 |
# JSON attribute conversion
|
| 285 |
-
attr_json = page.
|
| 286 |
assert attr_json == {"jsonable": "data"}
|
| 287 |
assert isinstance(page.css("#products")[0].attrib.json_string, bytes)
|
| 288 |
|
|
|
|
| 147 |
class TestSimilarElements:
|
| 148 |
def test_finding_similar_products(self, page):
|
| 149 |
"""Test finding similar product elements"""
|
| 150 |
+
first_product = page.css(".product").first
|
| 151 |
similar_products = first_product.find_similar()
|
| 152 |
assert len(similar_products) == 2
|
| 153 |
|
|
|
|
| 255 |
class TestJSONAndAttributes:
|
| 256 |
def test_json_conversion(self, page):
|
| 257 |
"""Test converting content to JSON"""
|
| 258 |
+
script_content = page.css("#page-data::text")[0].get()
|
| 259 |
assert issubclass(type(script_content.sort()), str)
|
| 260 |
page_data = script_content.json()
|
| 261 |
assert page_data["totalProducts"] == 3
|
|
|
|
| 282 |
assert list(key_value[0].keys()) == ["data-id"]
|
| 283 |
|
| 284 |
# JSON attribute conversion
|
| 285 |
+
attr_json = page.css("#products").first.attrib["schema"].json()
|
| 286 |
assert attr_json == {"jsonable": "data"}
|
| 287 |
assert isinstance(page.css("#products")[0].attrib.json_string, bytes)
|
| 288 |
|
tests/parser/test_parser_advanced.py
CHANGED
|
@@ -121,11 +121,12 @@ class TestAdvancedSelectors:
|
|
| 121 |
# ::text pseudo-element
|
| 122 |
texts = page.css("p::text")
|
| 123 |
assert len(texts) == 2
|
| 124 |
-
assert isinstance(texts[0],
|
|
|
|
| 125 |
|
| 126 |
# ::attr() pseudo-element
|
| 127 |
attrs = page.css("div::attr(class)")
|
| 128 |
-
assert "container" in attrs
|
| 129 |
|
| 130 |
def test_complex_attribute_operations(self, complex_html):
|
| 131 |
"""Test complex attribute handling"""
|
|
|
|
| 121 |
# ::text pseudo-element
|
| 122 |
texts = page.css("p::text")
|
| 123 |
assert len(texts) == 2
|
| 124 |
+
assert isinstance(texts[0], Selector)
|
| 125 |
+
assert isinstance(texts[0].get(), TextHandler)
|
| 126 |
|
| 127 |
# ::attr() pseudo-element
|
| 128 |
attrs = page.css("div::attr(class)")
|
| 129 |
+
assert "container" in attrs.getall()
|
| 130 |
|
| 131 |
def test_complex_attribute_operations(self, complex_html):
|
| 132 |
"""Test complex attribute handling"""
|