Byparr/tests/main_test.py

48 lines
1.1 KiB
Python
Raw Normal View History

2024-09-13 18:28:36 +00:00
from http import HTTPStatus
2024-10-18 16:33:27 +00:00
from time import sleep
2024-09-13 18:28:36 +00:00
2024-10-21 13:19:31 +00:00
import httpx
2024-09-13 18:04:37 +00:00
import pytest
2024-09-13 18:28:36 +00:00
from starlette.testclient import TestClient
2024-09-13 18:04:37 +00:00
2024-09-13 18:28:36 +00:00
from main import app
2024-09-13 18:04:37 +00:00
from src.models.requests import LinkRequest
2024-10-21 13:46:26 +00:00
from src.utils import logger
2024-09-13 18:04:37 +00:00
2024-09-13 18:28:36 +00:00
client = TestClient(app)
2024-09-13 18:04:37 +00:00
test_websites = [
2024-09-13 19:22:37 +00:00
"https://ext.to/",
"https://btmet.com/",
2024-10-18 14:27:43 +00:00
"https://extratorrent.st/", # github is blocking these
"https://idope.se/", # github is blocking these
2024-10-18 16:03:17 +00:00
"https://www.ygg.re/",
2024-10-27 18:32:06 +00:00
"https://speed.cd/login",
2024-09-13 18:04:37 +00:00
]
@pytest.mark.parametrize("website", test_websites)
2024-09-13 18:28:36 +00:00
def test_bypass(website: str):
2024-10-18 16:33:27 +00:00
sleep(3)
2024-10-21 13:19:31 +00:00
test_request = httpx.get(
website,
)
2024-10-27 18:32:06 +00:00
if (
test_request.status_code != HTTPStatus.OK
and "Just a moment..." not in test_request.text
):
2024-10-21 13:46:26 +00:00
logger.info(f"Skipping {website} due to {test_request.status_code}")
2024-10-21 13:19:31 +00:00
pytest.skip()
2024-09-13 18:28:36 +00:00
response = client.post(
"/v1",
2024-10-18 16:03:17 +00:00
json=LinkRequest(url=website, maxTimeout=30, cmd="request.get").model_dump(),
2024-09-13 18:28:36 +00:00
)
2024-10-21 13:19:31 +00:00
2024-09-13 18:28:36 +00:00
assert response.status_code == HTTPStatus.OK
2024-10-21 13:34:07 +00:00
def test_health_check():
response = client.get("/health")
assert response.status_code == HTTPStatus.OK