import pytest from utils_tools import GetImageUrlTool def test_get_image_url_tool_success(): """Test that GetImageUrlTool correctly extracts product_id and returns the expected image URL.""" tool = GetImageUrlTool() sample_url = "https://minhaloja.natura.com/p/refil-shampoo-mamae-e-bebe/NATBRA-92791?product=refil-shampoo-mamae-e-bebe&productId=NATBRA-92791&consultoria=lidimelocosmeticos&marca=natura" expected_image_url = "https://production.na01.natura.com/on/demandware.static/-/Sites-natura-br-storefront-catalog/default/dw68595724/NATBRA-92791_1.jpg" result = tool._run(sample_url) assert result == expected_image_url def test_get_image_url_tool_different_id(): """Test with a different product_id to ensure extraction works generally.""" tool = GetImageUrlTool() sample_url = "https://minhaloja.natura.com/p/some-product/NATBRA-12345?productId=NATBRA-12345" expected_image_url = "https://production.na01.natura.com/on/demandware.static/-/Sites-natura-br-storefront-catalog/default/dw68595724/NATBRA-12345_1.jpg" result = tool._run(sample_url) assert result == expected_image_url def test_get_image_url_tool_invalid_input_type(): """Test that a ValueError is raised if product_url is not a string.""" tool = GetImageUrlTool() with pytest.raises(ValueError, match="product_url must be a string."): tool._run(12345) # type: ignore def test_get_image_url_tool_missing_pattern(): """Test that a ValueError is raised if NATBRA- pattern is not found.""" tool = GetImageUrlTool() invalid_url = "https://minhaloja.natura.com/p/some-product/INVALID-12345?productId=INVALID-12345" with pytest.raises(ValueError, match="Could not extract product_id from the provided URL."): tool._run(invalid_url)