harvester/tests/test_harvester.py
2023-11-06 14:41:05 -05:00

33 lines
875 B
Python

import subprocess
import time
import pytest
from harvester.proxy import fetch_list
@pytest.fixture(scope='session', autouse=True)
def start_web_server():
server_process = subprocess.Popen(['python', '-m', 'http.server', '8888'], cwd='tests/data')
time.sleep(1)
yield
server_process.terminate()
def test_fetch_list():
expected = ['127.0.0.1:9000', '127.0.0.1:9001', 'username:pa$$@word@127.0.0.1:9002']
result = fetch_list('http://localhost:8888/proxies.txt')
assert result == expected
def test_fetch_list_fail():
expected = []
result = fetch_list('http://localhost:12345/proxies.txt')
assert result == expected
def test_fetch_list_only_valid():
expected = ['127.0.0.1:9000', '127.0.0.1:9001', 'username:pa$$@word@127.0.0.1:9002']
result = fetch_list('http://localhost:8888/proxies.txt')
assert result == expected