from rohrpost.handlers import handle_ping


def test_ping(message):
    handle_ping(message, request={'id': 123})
    assert message.reply_channel.closed is False
    assert len(message.reply_channel.data) == 1

    data = message.reply_channel.data[-1]
    assert data['id'] == 123
    assert data['type'] == 'pong'
    assert 'data' not in data


def test_ping_additional_data(message):
    handle_ping(message, request={
        'id': 123,
        'type': 'ping',
        'data': {'some': 'data', 'other': 'data'}
    })
    assert message.reply_channel.closed is False
    assert len(message.reply_channel.data) == 1

    data = message.reply_channel.data[-1]
    assert data['id'] == 123
    assert data['type'] == 'pong'
    assert data['data']['some'] == 'data'


def test_ping_additional_non_dict_data(message):
    handle_ping(message, request={
        'id': 123,
        'type': 'ping',
        'data': 1
    })
    assert message.reply_channel.closed is False
    assert len(message.reply_channel.data) == 1

    data = message.reply_channel.data[-1]
    assert data['id'] == 123
    assert data['type'] == 'pong'
    assert data['data']['data'] == 1

@@ -508,16 +508,34 @@
 : 'data'
+, 'handler': 'foo'
 %7D%0A    %7D)
@@ -780,16 +780,60 @@
  'data'%0A
+    assert data%5B'data'%5D%5B'handler'%5D == 'foo'%0A
 %0A%0Adef te

Add a failing test that demonstrates wrong handling of data