本文整理汇总了Python中servicetest.assertLength函数的典型用法代码示例。如果您正苦于以下问题:Python assertLength函数的具体用法?Python assertLength怎么用?Python assertLength使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assertLength函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _cb_disco_iq
def _cb_disco_iq(self, iq):
nodes = xpath.queryForNodes("/iq/query", iq)
query = nodes[0]
if query.getAttribute('node') is None:
return
node = query.attributes['node']
ver = node.replace("http://telepathy.freedesktop.org/caps#", "")
if iq.getAttribute('type') == 'result':
if FileTransferTest.caps_identities is None or \
FileTransferTest.caps_features is None:
identity_nodes = xpath.queryForNodes('/iq/query/identity', iq)
assertLength(1, identity_nodes)
identity_node = identity_nodes[0]
identity_category = identity_node['category']
identity_type = identity_node['type']
identity_name = identity_node['name']
identity = '%s/%s//%s' % (identity_category, identity_type,
identity_name)
FileTransferTest.caps_identities = [identity]
FileTransferTest.caps_features = []
for feature in xpath.queryForNodes('/iq/query/feature', iq):
FileTransferTest.caps_features.append(feature['var'])
# Check if the hash matches the announced capabilities
assertEquals(compute_caps_hash(FileTransferTest.caps_identities,
FileTransferTest.caps_features,
{}), ver)
if ver == FileTransferTest.caps_ft:
caps_share = compute_caps_hash(FileTransferTest.caps_identities,
FileTransferTest.caps_features + \
[ns.GOOGLE_FEAT_SHARE],
{})
n = query.attributes['node'].replace(ver, caps_share)
query.attributes['node'] = n
for feature in xpath.queryForNodes('/iq/query/feature', iq):
query.children.remove(feature)
for f in FileTransferTest.caps_features + [ns.GOOGLE_FEAT_SHARE]:
el = domish.Element((None, 'feature'))
el['var'] = f
query.addChild(el)
elif iq.getAttribute('type') == 'get':
caps_share = compute_caps_hash(FileTransferTest.caps_identities,
FileTransferTest.caps_features + \
[ns.GOOGLE_FEAT_SHARE],
{})
if ver == caps_share:
n = query.attributes['node'].replace(ver,
FileTransferTest.caps_ft)
query.attributes['node'] = n
示例2: incoming
def incoming(jp, q, bus, conn, stream):
remote_jid = '[email protected]/antennas'
jt = JingleTest2(jp, conn, q, stream, '[email protected]', remote_jid)
jt.prepare()
self_handle = conn.GetSelfHandle()
remote_handle = conn.RequestHandles(cs.HT_CONTACT, [remote_jid])[0]
for a, v in [(True, False), (False, True), (True, True)]:
if v and not jp.can_do_video():
continue
if not a and v and not jp.can_do_video_only():
continue
jt.incoming_call(audio=a, video=v)
e = q.expect('dbus-signal', signal='NewChannels')
chans = e.args[0]
assertLength(1, chans)
path, props = chans[0]
assertEquals(cs.CHANNEL_TYPE_STREAMED_MEDIA, props[cs.CHANNEL_TYPE])
assertEquals(a, props[cs.INITIAL_AUDIO])
assertEquals(v, props[cs.INITIAL_VIDEO])
chan = wrap_channel(bus.get_object(conn.bus_name, path),
cs.CHANNEL_TYPE_STREAMED_MEDIA)
chan.Close()
示例3: try_to_join_muc
def try_to_join_muc(q, bus, conn, stream, muc, request=None):
"""
Ask Gabble to join a MUC, and expect it to send <presence/>
Returns: the stream-presence Event object.
"""
if request is None:
request = {
cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT,
cs.TARGET_HANDLE_TYPE: cs.HT_ROOM,
cs.TARGET_ID: muc,
}
call_async(q, conn.Requests, 'CreateChannel',
dbus.Dictionary(request, signature='sv'))
join_event = q.expect('stream-presence', to='%s/test' % muc)
# XEP-0045 §7.1.2 sez:
# “MUC clients SHOULD signal their ability to speak the MUC protocol by
# including in the initial presence stanza an empty <x/> element
# qualified by the 'http://jabber.org/protocol/muc' namespace.”
x_muc_nodes = xpath.queryForNodes('/presence/x[@xmlns="%s"]' % ns.MUC,
join_event.stanza)
assertLength(1, x_muc_nodes)
return join_event
示例4: sending_request_to_cappy_contact
def sending_request_to_cappy_contact(q, bus, conn, stream, chan):
"""
Test that Gabble requests a receipt from a contact whom we know supports
this extension, but only if asked.
"""
# Convince Gabble that Guybrush supports this extension
caps = { 'node': 'http://whatever',
'ver': caps_helper.compute_caps_hash([], [ns.RECEIPTS], {}),
'hash': 'sha-1',
}
caps_helper.presence_and_disco(q, conn, stream, GUYBRUSH_FULL_JID,
disco=True,
client=caps['node'],
caps=caps,
features=[ns.RECEIPTS])
sync_stream(q, stream)
# Don't ask, don't tell — even if we know Guybrush does support this.
not_sending_request_to_contact(q, bus, conn, stream, chan)
# Ask, tell.
message = [
{ 'message-type': cs.MT_NORMAL,
},
{ 'content-type': 'text/plain',
'content': 'Ulysses?',
}]
chan.Messages.SendMessage(message, cs.MSG_SENDING_FLAGS_REPORT_DELIVERY)
e = q.expect('stream-message', to=GUYBRUSH)
assertLength(1, list(e.stanza.elements(uri=ns.RECEIPTS, name='request')))
示例5: disco_caps
def disco_caps(q, stream, presence):
c_nodes = xpath.queryForNodes('/presence/c', presence.stanza)
assert c_nodes is not None
assertLength(1, c_nodes)
hash = c_nodes[0].attributes['hash']
ver = c_nodes[0].attributes['ver']
node = c_nodes[0].attributes['node']
assertEquals('sha-1', hash)
# ask caps
request = \
elem_iq(stream, 'get', from_='[email protected]/resource')(
elem(ns.DISCO_INFO, 'query', node=(node + '#' + ver))
)
stream.send(request)
# receive caps
event = q.expect('stream-iq', query_ns=ns.DISCO_INFO, iq_id=request['id'])
# Check that Gabble's announcing the identity we think it should be.
(identities, features, dataforms) = extract_disco_parts(event.stanza)
# Check if the hash matches the announced capabilities
assertEquals(compute_caps_hash(identities, features, dataforms), ver)
return (event, features, dataforms)
示例6: test
def test(q, bus, conn, stream):
conn.Connect()
q.expect('dbus-signal', signal='StatusChanged',
args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED])
chan = join(q, bus, conn)
stream.sendMessage('PRIVMSG', CHANNEL, ":who's underlined you?", prefix='marnie')
q.expect('dbus-signal', signal='MessageReceived')
# Without acking the message, destroy the channel.
call_async(q, chan.Destroyable, "Destroy")
q.expect_many(
EventPattern('stream-PART'),
EventPattern('dbus-signal', signal='Closed', path=chan.object_path),
EventPattern('dbus-signal', signal='ChannelClosed', args=[chan.object_path]),
EventPattern('dbus-return', method='Destroy'),
)
# Now Create it again. If we haven't actually left the channel, this will
# fail.
chan = join(q, bus, conn)
# The message should be gone.
messages = chan.Properties.Get(cs.CHANNEL_IFACE_MESSAGES, 'PendingMessages')
assertLength(0, messages)
示例7: check_neither
def check_neither(q, conn, bus, stream, remote_handle):
"""
Make a channel without specifying InitialAudio or InitialVideo; check
that it's announced with both False, and that they're both present and
false in GetAll().
"""
path, props = conn.Requests.CreateChannel({
cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_STREAMED_MEDIA,
cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT,
cs.TARGET_HANDLE: remote_handle})
assertContains((cs.INITIAL_AUDIO, False), props.items())
assertContains((cs.INITIAL_VIDEO, False), props.items())
chan = wrap_channel(bus.get_object(conn.bus_name, path),
cs.CHANNEL_TYPE_STREAMED_MEDIA, ['MediaSignalling'])
props = chan.Properties.GetAll(cs.CHANNEL_TYPE_STREAMED_MEDIA)
assertContains(('InitialAudio', False), props.items())
assertContains(('InitialVideo', False), props.items())
# We shouldn't have started a session yet, so there shouldn't be any
# session handlers. Strictly speaking, there could be a session handler
# with no stream handlers, but...
session_handlers = chan.MediaSignalling.GetSessionHandlers()
assertLength(0, session_handlers)
示例8: run_test
def run_test(q, bus, conn, stream, jt, decloak_allowed):
"""
Requests streams on a media channel to jt.remote_jid without having their
presence at all.
"""
call_async(q, conn.Requests, 'CreateChannel',
{ cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_CALL,
cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT,
cs.TARGET_ID: jt.peer,
cs.CALL_INITIAL_AUDIO: True,
cs.CALL_INITIAL_VIDEO: False,
})
e = q.expect('stream-presence',
to=jt.peer_bare_jid, presence_type=None)
nodes = [ node for node in e.stanza.elements(uri=ns.TEMPPRES, name='temppres') ]
assertLength(1, nodes)
assertEquals('media', nodes[0].getAttribute('reason'))
if decloak_allowed:
jt.send_presence_and_caps()
# RequestStreams should now happily complete
q.expect('dbus-return', method='CreateChannel')
else:
q.expect('dbus-error', method='CreateChannel',
name=cs.OFFLINE)
示例9: test
def test(q, bus, conn, stream):
"""
Check that when we receive a roster update we emit a single AliasesChanged
for all the contacts.
"""
conn.Connect()
# Gabble asks the server for the initial roster
event = q.expect('stream-iq', iq_type='get', query_ns=ns.ROSTER)
result = make_result_iq(stream, event.stanza)
# We reply with a roster with two contacts
bob_jid = '[email protected]'
bob_alias = 'Bob Smith'
add_contact(result, bob_jid, bob_alias)
alice_jid = '[email protected]'
alice_alias = 'Alice'
add_contact(result, alice_jid, alice_alias)
stream.send(result)
# Check we get a single AliasesChanged for both contacts
event = q.expect('dbus-signal', signal='AliasesChanged')
added = event.args[0]
bob_handle, alice_handle = conn.get_contact_handles_sync(
[bob_jid, alice_jid])
assertLength(2, added)
assertContains((bob_handle, bob_alias), added)
assertContains((alice_handle, alice_alias), added)
示例10: test_contact_blocking
def test_contact_blocking(q, bus, conn, stream, stored, deny):
"""test ContactBlocking API"""
assertContains(cs.CONN_IFACE_CONTACT_BLOCKING, conn.Properties.Get(cs.CONN, "Interfaces"))
# 3 contacts are blocked
blocked = conn.RequestBlockedContacts(dbus_interface=cs.CONN_IFACE_CONTACT_BLOCKING)
assertLength(3, blocked)
示例11: check_contact_list_signals
def check_contact_list_signals(q, bus, conn, signals,
ht, name, contacts, lp_contacts=[], rp_contacts=[]):
"""
Looks at NewChannel and NewChannels signals for the contact list with ID
'name' and checks that its members, lp members and rp members are exactly
'contacts', 'lp_contacts' and 'rp_contacts'.
Returns a proxy for the channel.
"""
old_signal, new_signal = signals
path, type, handle_type, handle, suppress_handler = old_signal.args
assertEquals(cs.CHANNEL_TYPE_CONTACT_LIST, type)
assertEquals(name, conn.InspectHandles(handle_type, [handle])[0])
chan = wrap_channel(bus.get_object(conn.bus_name, path),
cs.CHANNEL_TYPE_CONTACT_LIST)
members = chan.Group.GetMembers()
assertEquals(sorted(contacts),
sorted(conn.InspectHandles(cs.HT_CONTACT, members)))
lp_handles = conn.RequestHandles(cs.HT_CONTACT, lp_contacts)
rp_handles = conn.RequestHandles(cs.HT_CONTACT, rp_contacts)
# NB. comma: we're unpacking args. Thython!
info, = new_signal.args
assertLength(1, info) # one channel
path_, emitted_props = info[0]
assertEquals(path_, path)
assertEquals(cs.CHANNEL_TYPE_CONTACT_LIST, emitted_props[cs.CHANNEL_TYPE])
assertEquals(ht, emitted_props[cs.TARGET_HANDLE_TYPE])
assertEquals(handle, emitted_props[cs.TARGET_HANDLE])
channel_props = chan.Properties.GetAll(cs.CHANNEL)
assertEquals(handle, channel_props.get('TargetHandle'))
assertEquals(ht, channel_props.get('TargetHandleType'))
assertEquals(cs.CHANNEL_TYPE_CONTACT_LIST, channel_props.get('ChannelType'))
assertContains(cs.CHANNEL_IFACE_GROUP, channel_props.get('Interfaces'))
assertEquals(name, channel_props['TargetID'])
assertEquals(False, channel_props['Requested'])
assertEquals('', channel_props['InitiatorID'])
assertEquals(0, channel_props['InitiatorHandle'])
group_props = chan.Properties.GetAll(cs.CHANNEL_IFACE_GROUP)
assertContains('HandleOwners', group_props)
assertContains('Members', group_props)
assertEquals(members, group_props['Members'])
assertContains('LocalPendingMembers', group_props)
actual_lp_handles = [x[0] for x in group_props['LocalPendingMembers']]
assertEquals(sorted(lp_handles), sorted(actual_lp_handles))
assertContains('RemotePendingMembers', group_props)
assertEquals(sorted(rp_handles), sorted(group_props['RemotePendingMembers']))
assertContains('GroupFlags', group_props)
return chan
示例12: general_tests
def general_tests (jp, q, bus, conn, stream, path, props):
assertEquals (cs.HT_ROOM, props[cs.TARGET_HANDLE_TYPE])
channel = bus.get_object (conn.bus_name, path)
chan_props = channel.GetAll (cs.CHANNEL_TYPE_CALL,
dbus_interface = dbus.PROPERTIES_IFACE)
contents = chan_props['Contents']
assertLength(1, contents)
示例13: test
def test(q, bus, conn, stream):
event = q.expect('stream-iq', query_ns=ns.ROSTER)
event.stanza['type'] = 'result'
item = event.query.addElement('item')
item['jid'] = '[email protected]'
item['subscription'] = 'both'
item.addElement('group', content='women')
item.addElement('group', content='affected-by-fdo-12791')
# This is a broken roster - Amy appears twice. This should only happen
# if the server is somehow buggy. This was my initial attempt at
# reproducing fd.o #12791 - I doubt it's very realistic, but we shouldn't
# assert, regardless of what input we get!
item = event.query.addElement('item')
item['jid'] = '[email protected]'
item['subscription'] = 'both'
item.addElement('group', content='women')
item = event.query.addElement('item')
item['jid'] = '[email protected]'
item['subscription'] = 'from'
item.addElement('group', content='men')
# This is what was *actually* strange about the #12791 submitter's roster -
# Bob appears, fully subscribed, but also there's an attempt to subscribe
# to one of Bob's resources. We now ignore such items
item = event.query.addElement('item')
item['jid'] = '[email protected]/Resource'
item['subscription'] = 'none'
item['ask'] = 'subscribe'
item = event.query.addElement('item')
item['jid'] = '[email protected]'
item['subscription'] = 'to'
item.addElement('group', content='men')
stream.send(event.stanza)
pairs = expect_contact_list_signals(q, bus, conn,
['publish', 'subscribe', 'stored'],
['men', 'women', 'affected-by-fdo-12791'])
check_contact_list_signals(q, bus, conn, pairs.pop(0), cs.HT_LIST,
'publish', ['[email protected]', '[email protected]'])
check_contact_list_signals(q, bus, conn, pairs.pop(0), cs.HT_LIST,
'subscribe', ['[email protected]', '[email protected]'])
check_contact_list_signals(q, bus, conn, pairs.pop(0), cs.HT_LIST,
'stored', ['[email protected]', '[email protected]', '[email protected]'])
check_contact_list_signals(q, bus, conn, pairs.pop(0), cs.HT_GROUP,
'men', ['[email protected]', '[email protected]'])
check_contact_list_signals(q, bus, conn, pairs.pop(0), cs.HT_GROUP,
'women', ['[email protected]'])
check_contact_list_signals(q, bus, conn, pairs.pop(0), cs.HT_GROUP,
'affected-by-fdo-12791', [])
assertLength(0, pairs) # i.e. we've checked all of them
示例14: test
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', to=None, query_ns='vcard-temp',
query_name='vCard'))
acknowledge_iq(stream, event.stanza)
handle = conn.RequestHandles(cs.HT_CONTACT, ['[email protected]'])[0]
call_async(q, conn.Aliasing, 'RequestAliases', [handle])
event = q.expect('stream-iq', to='[email protected]', iq_type='get',
query_ns=ns.PUBSUB, query_name='pubsub')
items = event.query.firstChildElement()
assertEquals('items', items.name)
assertEquals(ns.NICK, items['node'])
result = make_result_iq(stream, event.stanza)
pubsub = result.firstChildElement()
items = pubsub.addElement('items')
items['node'] = ns.NICK
item = items.addElement('item')
item.addElement('nick', ns.NICK, content='Bobby')
stream.send(result)
q.expect('dbus-signal', signal='AliasesChanged',
args=[[(handle, u'Bobby')]])
q.expect('dbus-return', method='RequestAliases',
value=(['Bobby'],))
# A second request should be satisfied from the cache.
assertEquals(['Bobby'], conn.Aliasing.RequestAliases([handle]))
# Bobby grows up, decides he hates his nickname.
# This is a regression test for
# <https://bugs.freedesktop.org/show_bug.cgi?id=21817>, where this would
# crash Gabble.
message = elem('message', from_='[email protected]')(
elem((ns.PUBSUB + "#event"), 'event')(
elem('items', node=ns.NICK)(
elem('item')(
elem(ns.NICK, 'nick')
)
)
)
)
stream.send(message.toXml())
event = q.expect('dbus-signal', signal='AliasesChanged')
aliases = event.args[0]
assertLength(1, aliases)
h, a = aliases[0]
assertEquals(handle, h)
# The contact explicitly cleared their PEP nick; Gabble should fall back to
# their JID.
assertEquals(a, '[email protected]')
示例15: check_endpoint
def check_endpoint(self, content, endpoint_path):
endpoint = self.bus.get_object(self.conn.bus_name, endpoint_path)
endpoint_props = endpoint.GetAll(cs.CALL_STREAM_ENDPOINT)
assertEquals(('',''), endpoint_props['RemoteCredentials'])
assertEquals(self.context.get_remote_candidates_dbus(),
endpoint_props['RemoteCandidates'])
assertLength(0, endpoint_props['EndpointState'])
assertEquals(cs.CALL_STREAM_TRANSPORT_RAW_UDP,
endpoint_props['Transport'])
assertEquals(False, endpoint_props['IsICELite'])