Start from scratch
This commit is contained in:
parent
24ce2dc6c0
commit
cd92f1c0cc
12 changed files with 105 additions and 1123 deletions
41
socketIO_client/tests/__init__.py
Normal file
41
socketIO_client/tests/__init__.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import logging
|
||||
from unittest import TestCase
|
||||
|
||||
from .. import SocketIO, LoggingNamespace, find_callback
|
||||
|
||||
|
||||
HOST = 'localhost'
|
||||
PORT = 8000
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
|
||||
class BaseMixin(object):
|
||||
|
||||
def test_emit(self):
|
||||
'Emit'
|
||||
namespace = self.socketIO.define(Namespace)
|
||||
self.socketIO.emit('emit')
|
||||
self.socketIO.wait(self.wait_time_in_seconds)
|
||||
self.assertEqual(namespace.args_by_event, {
|
||||
'emit_response': (),
|
||||
})
|
||||
|
||||
|
||||
class Test_XHR_PollingTransport(TestCase, BaseMixin):
|
||||
|
||||
def setUp(self):
|
||||
super(Test_XHR_PollingTransport, self).setUp()
|
||||
self.socketIO = SocketIO(HOST, PORT, transports=['xhr-polling'])
|
||||
self.wait_time_in_seconds = 1
|
||||
|
||||
|
||||
class Namespace(LoggingNamespace):
|
||||
|
||||
def initialize(self):
|
||||
self.args_by_event = {}
|
||||
|
||||
def on_event(self, event, *args):
|
||||
callback, args = find_callback(args)
|
||||
if callback:
|
||||
callback(*args)
|
||||
self.args_by_event[event] = args
|
||||
4
socketIO_client/tests/index.html
Normal file
4
socketIO_client/tests/index.html
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<script src="/socket.io/socket.io.js"></script>
|
||||
<script>
|
||||
var socket = io('http://localhost');
|
||||
</script>
|
||||
90
socketIO_client/tests/serve.js
Normal file
90
socketIO_client/tests/serve.js
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
// DEBUG=* node serve.js
|
||||
|
||||
var app = require('http').createServer(serve).listen(8000);
|
||||
var io = require('socket.io')(app);
|
||||
var fs = require('fs');
|
||||
var PAYLOAD = {'xxx': 'yyy'};
|
||||
|
||||
io.on('connection', function(socket) {
|
||||
socket.on('message', function(data, fn) {
|
||||
if (fn) {
|
||||
// Client requests callback
|
||||
if (data) {
|
||||
fn(data);
|
||||
} else {
|
||||
fn();
|
||||
}
|
||||
} else if (typeof data === 'object') {
|
||||
// Data has type object or is null
|
||||
socket.json.send(data ? data : 'message_response');
|
||||
} else {
|
||||
// Data has type string or is ''
|
||||
socket.send(data ? data : 'message_response');
|
||||
}
|
||||
});
|
||||
socket.on('emit', function() {
|
||||
socket.emit('emit_response');
|
||||
});
|
||||
socket.on('emit_with_payload', function(payload) {
|
||||
socket.emit('emit_with_payload_response', payload);
|
||||
});
|
||||
socket.on('emit_with_multiple_payloads', function(payload1, payload2) {
|
||||
socket.emit('emit_with_multiple_payloads_response', payload1, payload2);
|
||||
});
|
||||
socket.on('emit_with_callback', function(fn) {
|
||||
fn();
|
||||
});
|
||||
socket.on('emit_with_callback_with_payload', function(fn) {
|
||||
fn(PAYLOAD);
|
||||
});
|
||||
socket.on('emit_with_callback_with_multiple_payloads', function(fn) {
|
||||
fn(PAYLOAD, PAYLOAD);
|
||||
});
|
||||
socket.on('emit_with_event', function(payload) {
|
||||
socket.emit('emit_with_event_response', payload);
|
||||
});
|
||||
socket.on('ack', function(payload) {
|
||||
socket.emit('ack_response', payload, function(payload) {
|
||||
socket.emit('ack_callback_response', payload);
|
||||
});
|
||||
});
|
||||
socket.on('aaa', function() {
|
||||
socket.emit('aaa_response', PAYLOAD);
|
||||
});
|
||||
socket.on('bbb', function(payload, fn) {
|
||||
if (fn) fn(payload);
|
||||
});
|
||||
socket.on('wait_with_disconnect', function() {
|
||||
socket.emit('wait_with_disconnect_response');
|
||||
});
|
||||
});
|
||||
|
||||
io.of('/chat').on('connection', function(socket) {
|
||||
socket.on('emit_with_payload', function(payload) {
|
||||
socket.emit('emit_with_payload_response', payload);
|
||||
});
|
||||
socket.on('aaa', function() {
|
||||
socket.emit('aaa_response', 'in chat');
|
||||
});
|
||||
socket.on('ack', function(payload) {
|
||||
socket.emit('ack_response', payload, function(payload) {
|
||||
socket.emit('ack_callback_response', payload);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
io.of('/news').on('connection', function(socket) {
|
||||
socket.on('emit_with_payload', function(payload) {
|
||||
socket.emit('emit_with_payload_response', payload);
|
||||
});
|
||||
socket.on('aaa', function() {
|
||||
socket.emit('aaa_response', 'in news');
|
||||
});
|
||||
});
|
||||
|
||||
function serve(req, res) {
|
||||
fs.readFile(__dirname + '/index.html', function(err, data) {
|
||||
res.writeHead(200);
|
||||
res.end(data);
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue