def test_not_subscribing_on_faile_authencitacion(mock_auth): ac = ActiveConnections() app = tornado.web.Application() app.active_connections = ac r = MockRequest() wh = WSHandler(app, r) ac.connections.append(wh) message = json.dumps({ 'subscribe': ['newuser'] }) wh.on_message(message) assert 'newuser' not in wh.subscriptions, 'Didn\'t add subscription'
def test_on_message_autehticate(mock_auth, mock_get, mock_write): ac = ActiveConnections() app = tornado.web.Application() app.active_connections = ac r = MockRequest() wh = WSHandler(app, r) message = json.dumps({ 'id': 9, 'authenticate': { 'name': 'me', 'password': '******', }, }) wh.on_message(message) mock_auth.assert_called_once_with() mock_get.assert_called_once_with('me', 'secret')
def test_on_message_registration(mock_create, mock_write): ac = ActiveConnections() app = tornado.web.Application() app.active_connections = ac r = MockRequest() wh = WSHandler(app, r) message = json.dumps({ 'id': 9, 'register': { 'name': 'me', 'password': '******', }, }) wh.on_message(message) mock_write.assert_called_once_with(json.dumps({ 'id': 9, 'type': 'registration', 'user_id': '3', }))