Skip to content

Commit

Permalink
Small coverage increase in protocols/utils (#904)
Browse files Browse the repository at this point in the history
  • Loading branch information
euri10 authored Dec 22, 2020
1 parent 7a667a5 commit e01c927
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tests/protocols/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import socket

from uvicorn.protocols.utils import get_local_addr, get_remote_addr
import pytest

from uvicorn.protocols.utils import get_client_addr, get_local_addr, get_remote_addr


class MockSocket:
Expand Down Expand Up @@ -80,3 +82,12 @@ def test_get_remote_addr():

transport = MockTransport({"peername": ("123.45.6.7", 123)})
assert get_remote_addr(transport) == ("123.45.6.7", 123)


@pytest.mark.parametrize(
"scope, expected_client",
[({"client": ("127.0.0.1", 36000)}, "127.0.0.1:36000"), ({"client": None}, "")],
ids=["ip:port client", "None client"],
)
def test_get_client_addr(scope, expected_client):
assert get_client_addr(scope) == expected_client

0 comments on commit e01c927

Please sign in to comment.