Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit f605772

Browse files
committed
Initial tests of the abstraction layer.
1 parent 4b9e2d7 commit f605772

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

test/test_abstraction.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# -*- coding: utf-8 -*-
2+
import hyper.common.connection
3+
4+
from hyper.common.connection import HTTPConnection
5+
from hyper.common.exceptions import TLSUpgrade
6+
7+
class TestHTTPConnection(object):
8+
def test_h1_kwargs(self):
9+
c = HTTPConnection(
10+
'test', 443, secure=False, window_manager=True, enable_push=True,
11+
other_kwarg=True
12+
)
13+
14+
assert c._h1_kwargs == {
15+
'secure': False,
16+
'other_kwarg': True,
17+
}
18+
19+
def test_h2_kwargs(self):
20+
c = HTTPConnection(
21+
'test', 443, secure=False, window_manager=True, enable_push=True,
22+
other_kwarg=True
23+
)
24+
25+
assert c._h2_kwargs == {
26+
'window_manager': True,
27+
'enable_push': True,
28+
'other_kwarg': True,
29+
}
30+
31+
def test_upgrade(self, monkeypatch):
32+
monkeypatch.setattr(
33+
hyper.common.connection, 'HTTP11Connection', DummyH1Connection
34+
)
35+
monkeypatch.setattr(
36+
hyper.common.connection, 'HTTP20Connection', DummyH2Connection
37+
)
38+
c = HTTPConnection('test', 443)
39+
40+
assert isinstance(c._conn, DummyH1Connection)
41+
42+
r = c.request('GET', '/')
43+
44+
assert r == 'h2'
45+
assert isinstance(c._conn, DummyH2Connection)
46+
assert c._conn._sock == 'totally a socket'
47+
48+
49+
class DummyH1Connection(object):
50+
def __init__(self, *args, **kwargs):
51+
pass
52+
53+
def request(self, *args, **kwargs):
54+
raise TLSUpgrade('h2', 'totally a socket')
55+
56+
57+
class DummyH2Connection(object):
58+
def __init__(self, *args, **kwargs):
59+
pass
60+
61+
def _send_preamble(self):
62+
pass
63+
64+
def request(self, *args, **kwargs):
65+
return 'h2'

0 commit comments

Comments
 (0)