2015-05-02 05:10:25 +00:00
|
|
|
|
|
|
|
from libpathod import language
|
|
|
|
from libpathod.language import websockets
|
2015-05-03 01:54:52 +00:00
|
|
|
import netlib.websockets
|
|
|
|
import tutils
|
2015-05-02 05:10:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
def parse_request(s):
|
|
|
|
return language.parse_requests(s)[0]
|
|
|
|
|
|
|
|
|
|
|
|
class TestWebsocketFrame:
|
|
|
|
def test_values(self):
|
2015-05-02 05:19:48 +00:00
|
|
|
specs = [
|
|
|
|
"wf",
|
2015-05-04 23:16:29 +00:00
|
|
|
"wf:dr",
|
2015-05-03 01:54:52 +00:00
|
|
|
"wf:b'foo'",
|
|
|
|
"wf:cbinary",
|
2015-05-03 22:48:35 +00:00
|
|
|
"wf:c1",
|
|
|
|
"wf:r",
|
|
|
|
"wf:fin",
|
|
|
|
"wf:fin:rsv1:rsv2:rsv3:mask",
|
|
|
|
"wf:-fin:-rsv1:-rsv2:-rsv3:-mask",
|
2015-05-02 05:19:48 +00:00
|
|
|
]
|
|
|
|
for i in specs:
|
|
|
|
wf = parse_request(i)
|
|
|
|
assert isinstance(wf, websockets.WebsocketFrame)
|
|
|
|
assert wf
|
|
|
|
assert wf.values(language.Settings())
|
|
|
|
assert wf.resolve(language.Settings())
|
|
|
|
|
|
|
|
spec = wf.spec()
|
|
|
|
wf2 = parse_request(spec)
|
|
|
|
assert wf2.spec() == spec
|
2015-05-03 01:54:52 +00:00
|
|
|
|
2015-05-03 22:48:35 +00:00
|
|
|
def test_raw(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_flags(self):
|
|
|
|
wf = parse_request("wf:fin:mask:rsv1:rsv2:rsv3")
|
|
|
|
frm = netlib.websockets.Frame.from_bytes(tutils.render(wf))
|
|
|
|
assert frm.header.fin
|
|
|
|
assert frm.header.mask
|
|
|
|
assert frm.header.rsv1
|
|
|
|
assert frm.header.rsv2
|
|
|
|
assert frm.header.rsv3
|
|
|
|
|
|
|
|
wf = parse_request("wf:-fin:-mask:-rsv1:-rsv2:-rsv3")
|
|
|
|
frm = netlib.websockets.Frame.from_bytes(tutils.render(wf))
|
|
|
|
assert not frm.header.fin
|
|
|
|
assert not frm.header.mask
|
|
|
|
assert not frm.header.rsv1
|
|
|
|
assert not frm.header.rsv2
|
|
|
|
assert not frm.header.rsv3
|
|
|
|
|
2015-05-03 01:54:52 +00:00
|
|
|
def test_construction(self):
|
|
|
|
wf = parse_request("wf:c1")
|
|
|
|
frm = netlib.websockets.Frame.from_bytes(tutils.render(wf))
|
2015-05-03 22:48:35 +00:00
|
|
|
assert wf.opcode.value == 1 == frm.header.opcode
|
2015-05-03 01:54:52 +00:00
|
|
|
|
|
|
|
wf = parse_request("wf:cbinary")
|
|
|
|
frm = netlib.websockets.Frame.from_bytes(tutils.render(wf))
|
2015-05-03 22:48:35 +00:00
|
|
|
assert wf.opcode.value == frm.header.opcode
|
|
|
|
assert wf.opcode.value == netlib.websockets.OPCODE.BINARY
|