"""
A simple smoke-test for C.I.SimplePresence

FIXME: test C.I.Presence too
"""

from twisted.words.xish import domish

from gabbletest import exec_test
from servicetest import EventPattern
import ns
import constants as cs

def test(q, bus, conn, stream):
    conn.Connect()
    _, event = q.expect_many(
        EventPattern('dbus-signal', signal='StatusChanged',
            args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED]),
        EventPattern('stream-iq', query_ns=ns.ROSTER),
        )

    amy_handle = conn.RequestHandles(1, ['amy@foo.com'])[0]

    event.stanza['type'] = 'result'

    item = event.query.addElement('item')
    item['jid'] = 'amy@foo.com'
    item['subscription'] = 'both'

    stream.send(event.stanza)

    presence = domish.Element((None, 'presence'))
    presence['from'] = 'amy@foo.com'
    show = presence.addElement((None, 'show'))
    show.addContent('away')
    status = presence.addElement((None, 'status'))
    status.addContent('At the pub')
    stream.send(presence)

    event = q.expect('dbus-signal', signal='PresencesChanged',
        args=[{amy_handle: (3, 'away', 'At the pub')}])

    presence = domish.Element((None, 'presence'))
    presence['from'] = 'amy@foo.com'
    show = presence.addElement((None, 'show'))
    show.addContent('chat')
    status = presence.addElement((None, 'status'))
    status.addContent('I may have been drinking')
    stream.send(presence)

    event = q.expect('dbus-signal', signal='PresencesChanged',
        args=[{amy_handle: (2, 'chat', 'I may have been drinking')}])

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

@@ -146,16 +146,31 @@
 xec_test
+, make_presence
 %0Afrom se
@@ -745,296 +745,92 @@
 za)%0A
-%0A
     
-presence = domish.Element((None, 'presence'))%0A    presence%5B'from'%5D = 'amy@foo.com'%0A    show = presence.addElement((None
+stream.send(make_presence('amy@foo.com'
 , 
-'
 show
-'))%0A    show.addContent('away')%0A    status = presence.addElement((None
+='away'
 , 
-'
 status
-'))%0A    status.addContent('At the pub')%0A    stream.send(presence)%0A%0A    event =
+='At the pub'))%0A%0A   
  q.e
@@ -942,239 +942,78 @@
     
-presence = domish.Element((None, 'presence'))%0A    presence%5B'from'%5D = 'amy@foo.com'%0A    show = presence.addElement((None
+stream.send(make_presence(%0A        'amy@foo.com'
 , 
-'
 show
-'))%0A    show.addContent('chat')%0A    status = presence.addElement((None
+='chat'
 , 
-'
 status
-'))%0A    status.addContent(
+=
 'I m
@@ -1039,47 +1039,14 @@
 ng')
+)%0A
 %0A   
- stream.send(presence)%0A%0A    event =
  q.e

use make_presence()