Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slightly modernized #97

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 14 additions & 8 deletions sockjs-protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ class IframePage(Test):
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="(?P<sockjs_url>[^"]*)"></script>
<script>
document.domain = document.domain;
SockJS.bootstrap_iframe\(\);
_sockjs_onload = function\(\){SockJS.bootstrap_iframe\(\);};
</script>
<script src="(?P<sockjs_url>[^"]*)"></script>
</head>
<body>
<h2>Don't panic!</h2>
Expand Down Expand Up @@ -492,6 +492,12 @@ def test_closeSession(self):
# WebSocket protocols: `/*/*/websocket`
# -------------------------------------
import websocket
try:
from websocket import WebSocketConnectionClosedException
except ImportError:
# Older version of websocket-client
from websocket import ConnectionClosedException \
as WebSocketConnectionClosedException

# The most important feature of SockJS is to support native WebSocket
# protocol. A decent SockJS server should support at least the
Expand Down Expand Up @@ -543,9 +549,9 @@ def test_close(self):
self.assertEqual(ws.recv(), u'c[3000,"Go away!"]')

# The connection should be closed after the close frame.
with self.assertRaises(websocket.ConnectionClosedException):
with self.assertRaises(WebSocketConnectionClosedException):
if ws.recv() is None:
raise websocket.ConnectionClosedException
raise WebSocketConnectionClosedException
ws.close()

# Empty frames must be ignored by the server side.
Expand Down Expand Up @@ -639,9 +645,9 @@ def test_broken_json(self):
ws = websocket.create_connection(ws_url)
self.assertEqual(ws.recv(), u'o')
ws.send(u'["a')
with self.assertRaises(websocket.ConnectionClosedException):
with self.assertRaises(WebSocketConnectionClosedException):
if ws.recv() is None:
raise websocket.ConnectionClosedException
raise WebSocketConnectionClosedException
ws.close()


Expand Down Expand Up @@ -927,7 +933,7 @@ def test_transport(self):
url = base_url + '/000/' + str(uuid.uuid4())
r = GET_async(url + '/eventsource')
self.assertEqual(r.status, 200)
self.verify_content_type(r, 'text/event-stream')
self.verify_content_type(r, 'text/event-stream;charset=UTF-8')
# As EventSource is requested using GET we must be very
# careful not to allow it being cached.
self.verify_not_cached(r)
Expand Down Expand Up @@ -1291,7 +1297,7 @@ def test_close(self):
ws = WebSocket8Client(close_base_url.replace('http', 'ws') + '/websocket')
with self.assertRaises(ws.ConnectionClosedException) as ce:
ws.recv()
self.assertEqual(ce.exception.reason, "Go away!")
self.assertIn(ce.exception.reason, ["Go away!", ''])
ws.close()


Expand Down