def test_write_message_no_subscribers(mock_connection): ac = ActiveConnections() c = MockConnection() ac.connections = [c] ac.write_message({'user': '******'}) assert mock_connection.call_count == 0, 'Called when noone subscribed'
def test_write_message(mock_connection): ac = ActiveConnections() c = MockConnection() c.subscriptions = ['someuser'] ac.connections = [c] ac.write_message({'user': '******'}) mock_connection.assert_called_once_with(json.dumps({'user': '******'}))
def test_double_remove(): ac = ActiveConnections() c = MockConnection() ac.connections = [c] ac.remove(c) ac.remove(c) assert len(ac.connections) == 0
def test_remove(): ac = ActiveConnections() c1 = MockConnection() c2 = MockConnection() ac.connections = [c1, c2] ac.remove(c1) assert c1 not in ac.connections assert c2 in ac.connections