Skip to content

Commit

Permalink
Moved SOCKSConnection test to the test_interfaces.py
Browse files Browse the repository at this point in the history
  • Loading branch information
cdeler committed Sep 17, 2020
1 parent 67ec24f commit 3c732a2
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 29 deletions.
27 changes: 27 additions & 0 deletions tests/async_tests/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

import httpcore
from httpcore._async.connection import AsyncSOCKSConnection
from httpcore._types import URL
from tests.conftest import Server
from tests.utils import lookup_async_backend
Expand Down Expand Up @@ -397,3 +398,29 @@ async def test_explicit_backend_name() -> None:
assert status_code == 200
assert reason == b"OK"
assert len(http._connections[url[:3]]) == 1 # type: ignore


@pytest.mark.anyio
@pytest.mark.parametrize(
"url",
[
(b"http", b"example.com", 80, b"/"),
(b"https", b"example.com", 443, b"/"),
],
)
@pytest.mark.parametrize("http2", [True, False])
async def test_proxy_connection_without_auth(socks5_proxy, url, http2):
(protocol, hostname, port, path) = url
origin = (protocol, hostname, port)
headers = [(b"host", hostname)]
method = b"GET"

async with AsyncSOCKSConnection(
origin, http2=http2, proxy_origin=socks5_proxy
) as connection:
http_version, status_code, reason, headers, stream = await connection.request(
method, url, headers
)

assert status_code == 200
assert reason == b"OK"
27 changes: 27 additions & 0 deletions tests/sync_tests/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

import httpcore
from httpcore._async.connection import SyncSOCKSConnection
from httpcore._types import URL
from tests.conftest import Server
from tests.utils import lookup_sync_backend
Expand Down Expand Up @@ -397,3 +398,29 @@ def test_explicit_backend_name() -> None:
assert status_code == 200
assert reason == b"OK"
assert len(http._connections[url[:3]]) == 1 # type: ignore



@pytest.mark.parametrize(
"url",
[
(b"http", b"example.com", 80, b"/"),
(b"https", b"example.com", 443, b"/"),
],
)
@pytest.mark.parametrize("http2", [True, False])
def test_proxy_connection_without_auth(socks5_proxy, url, http2):
(protocol, hostname, port, path) = url
origin = (protocol, hostname, port)
headers = [(b"host", hostname)]
method = b"GET"

with SyncSOCKSConnection(
origin, http2=http2, proxy_origin=socks5_proxy
) as connection:
http_version, status_code, reason, headers, stream = connection.request(
method, url, headers
)

assert status_code == 200
assert reason == b"OK"
29 changes: 0 additions & 29 deletions tests/test_socks.py

This file was deleted.

0 comments on commit 3c732a2

Please sign in to comment.