<commit_before>
"""
Test that Gabble responds to disco#info queries.
"""

from twisted.words.xish import domish

from gabbletest import go

def expect_connected(event, data):
    if event.type != 'dbus-signal':
        return False

    if event.signal != 'StatusChanged':
        return False

    if event.args != [0, 1]:
        return False

    m = domish.Element(('', 'iq'))
    m['from'] = '<EMAIL>'
    m['id'] = '1'
    query = m.addElement('query')
    query['xmlns'] = 'http://jabber.org/protocol/disco#info'
    data['stream'].send(m)
    return True

def expect_disco_response(event, data):
    if event.type != 'stream-iq':
        return False

    elem = event.stanza

    if elem['id'] != '1':
        return False

    assert elem['type'] == 'result'
    assert elem['to'] == '<EMAIL>'
    data['conn_iface'].Disconnect()
    return True

def expect_disconnected(event, data):
    if event.type != 'dbus-signal':
        return False

    if event.signal != 'StatusChanged':
        return False

    if event.args != [2, 1]:
        return False

    return True

if __name__ == '__main__':
    go()
<commit_msg>port test-disco.py to new test API<commit_after>
"""
Test that Gabble responds to disco#info queries.
"""

from twisted.words.xish import domish

from gabbletest import exec_test

def test(q, bus, conn, stream):
    conn.Connect()
    q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])

    m = domish.Element(('', 'iq'))
    m['from'] = '<EMAIL>'
    m['id'] = '1'
    m.addElement(('http://jabber.org/protocol/disco#info', 'query'))
    stream.send(m)
    return True

    event = q.expect('stream-iq', iq_type='result', to='<EMAIL>')
    elem = event.stanza
    assert elem['id'] == '1'

    conn.Disconnect()
    q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])

if __name__ == '__main__':
    exec_test(test)

{'fraction_non_alphanumeric': 0.16443492233529727, 'fraction_numerical': 0.006427423674343867, 'mean_word_length': 3.0345572354211665, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4584031', 'n_tokens_mistral': 645, 'n_tokens_neox': 625, 'n_words': 159}