Skip to content

Commit 881b601

Browse files
trollfot1st1
authored andcommitted
Using real object to tests should_upgrade
1 parent ae324ae commit 881b601

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

tests/test_parser.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -349,20 +349,24 @@ def test_parser_request_upgrade_1(self):
349349
b'Upgrade': b'WebSocket'})
350350

351351
def test_parser_request_upgrade_flag(self):
352-
m = mock.Mock()
353-
p = httptools.HttpRequestParser(m)
354352

355-
def on_headers_complete():
356-
self.assertEqual(p.should_upgrade(), False)
353+
class Protocol:
354+
355+
def __init__(self):
356+
self.parser = httptools.HttpRequestParser(self)
357+
358+
def on_url(self, url):
359+
assert self.parser.should_upgrade() is False
357360

358-
def on_message_complete():
359-
self.assertEqual(p.should_upgrade(), True)
361+
def on_headers_complete(self):
362+
assert self.parser.should_upgrade() is True
360363

361-
m.on_headers_complete = on_headers_complete
362-
m.on_message_complete = on_message_complete
363-
364+
def on_message_complete(self):
365+
assert self.parser.should_upgrade() is True
366+
367+
protocol = Protocol()
364368
try:
365-
p.feed_data(UPGRADE_REQUEST1)
369+
protocol.parser.feed_data(UPGRADE_REQUEST1)
366370
except httptools.HttpParserUpgrade as ex:
367371
offset = ex.args[0]
368372
else:

0 commit comments

Comments
 (0)