from app.models.schemas import VisitRequest, WaitUntilValue, ArasResponse from pydantic import ValidationError import pytest class TestWaitUntilValue: def test_valid_values(self): for val in ["load", "domcontentloaded", "networkidle", "commit"]: assert val in WaitUntilValue.__args__ def test_invalid_value_raises_error(self): with pytest.raises(ValidationError): VisitRequest(url="https://example.com", waitUntil="invalid") class TestVisitRequest: def test_minimal_request(self): req = VisitRequest(url="https://example.com") assert str(req.url) == "https://example.com/" assert req.screenshot is False assert req.waitUntil == "load" assert req.waitTime == 0 assert req.proxy is None assert req.proxyAuth is None assert req.incognito is False assert req.screenshotSelector is None assert req.screenshotDelay == 0 assert req.clickSelector is None assert req.selectorTimeout == 1000 def test_full_request(self): req = VisitRequest( url="https://example.com", screenshot=True, waitUntil="networkidle", waitTime=10, proxy="http://proxy:8080", proxyAuth={"username": "user", "password": "pass"}, incognito=True, screenshotSelector="#product", screenshotDelay=500, clickSelector="button#load-more", selectorTimeout=2000, ) assert req.screenshot is True assert req.waitUntil == "networkidle" assert req.waitTime == 10 assert req.proxy == "http://proxy:8080" assert req.proxyAuth["username"] == "user" assert req.incognito is True assert req.screenshotSelector == "#product" assert req.screenshotDelay == 500 assert req.clickSelector == "button#load-more" assert req.selectorTimeout == 2000 def test_screenshot_delay_boundary_values(self): VisitRequest(url="https://example.com", screenshotDelay=0) VisitRequest(url="https://example.com", screenshotDelay=60000) def test_screenshot_delay_invalid_values(self): with pytest.raises(ValidationError): VisitRequest(url="https://example.com", screenshotDelay=-1) with pytest.raises(ValidationError): VisitRequest(url="https://example.com", screenshotDelay=60001) def test_selector_timeout_boundary_values(self): VisitRequest(url="https://example.com", selectorTimeout=100) VisitRequest(url="https://example.com", selectorTimeout=30000) def test_selector_timeout_invalid_values(self): with pytest.raises(ValidationError): VisitRequest(url="https://example.com", selectorTimeout=99) with pytest.raises(ValidationError): VisitRequest(url="https://example.com", selectorTimeout=30001) def test_wait_time_negative_rejected(self): with pytest.raises(ValidationError): VisitRequest(url="https://example.com", waitTime=-1) def test_wait_time_above_max_rejected(self): with pytest.raises(ValidationError): VisitRequest(url="https://example.com", waitTime=61) def test_wait_time_boundary_values(self): # Both 0 and 60 should be valid VisitRequest(url="https://example.com", waitTime=0) VisitRequest(url="https://example.com", waitTime=60) def test_invalid_url_raises_error(self): with pytest.raises(ValidationError): VisitRequest(url="not-a-url") def test_all_waituntil_values(self): for val in ["load", "domcontentloaded", "networkidle", "commit"]: req = VisitRequest(url="https://example.com", waitUntil=val) assert req.waitUntil == val class TestArasResponse: def test_minimal_response(self): resp = ArasResponse(status="OK", message="test", data=None) assert resp.status == "OK" assert resp.message == "test" assert resp.data is None assert resp.extra is None assert resp.code == "UNKNOWN_CODE" def test_full_response(self): resp = ArasResponse( status="OK", message="test", data={"key": "value"}, extra={"extra": "data"}, code="CUSTOM_CODE", ) assert resp.data == {"key": "value"} assert resp.extra == {"extra": "data"} assert resp.code == "CUSTOM_CODE"