| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- 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.proxy is None
- assert req.proxyAuth is None
- assert req.incognito is False
- def test_full_request(self):
- req = VisitRequest(
- url="https://example.com",
- screenshot=True,
- waitUntil="networkidle",
- proxy="http://proxy:8080",
- proxyAuth={"username": "user", "password": "pass"},
- incognito=True,
- )
- assert req.screenshot is True
- assert req.waitUntil == "networkidle"
- assert req.proxy == "http://proxy:8080"
- assert req.proxyAuth["username"] == "user"
- assert req.incognito is True
- 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"
|