plugin XEP-0356: Privileged Entity implementation:
This is the second XEP needed to implement PEP in Pubsub Component. This implementation should be more or less complete. rel 476
This commit is contained in:
parent
ba9a2fc6d5
commit
6605e523d0
1 changed files with 1333 additions and 0 deletions
|
|
@ -20,6 +20,7 @@ from unittest.mock import MagicMock, AsyncMock
|
|||
from pytest import fixture
|
||||
from twisted.internet import defer
|
||||
from twisted.words.protocols.jabber import jid
|
||||
from twisted.words.xish import domish
|
||||
from libervia.backend import G
|
||||
from tx_xmpp.data_form import NS_X_DATA
|
||||
from libervia.backend.core.main import LiberviaBackend
|
||||
|
|
@ -94,6 +95,49 @@ def host(bridge, storage):
|
|||
return host
|
||||
|
||||
|
||||
@fixture
|
||||
def client_IQ():
|
||||
"""Factory fixture to create a mock IQ method for testing.
|
||||
|
||||
Usage:
|
||||
def test_something(client, client_IQ):
|
||||
response_elt = domish.Element((None, "iq"))
|
||||
response_elt["type"] = "result"
|
||||
client.IQ = client_IQ(response_elt=response_elt)
|
||||
|
||||
# Later in test:
|
||||
assert len(client.IQ.sent_iqs) == 1
|
||||
|
||||
@param response: Optional response to return from send(). If None, returns empty IQ.
|
||||
@return: The mock IQ method with attached sent_iqs list.
|
||||
"""
|
||||
|
||||
def factory(response_elt=None):
|
||||
sent_iqs = []
|
||||
|
||||
def client_IQ(type_="set", timeout=60):
|
||||
iq_elt = domish.Element((None, "iq"))
|
||||
iq_elt["type"] = type_
|
||||
|
||||
async def mock_send():
|
||||
sent_iqs.append(iq_elt)
|
||||
if response_elt is not None:
|
||||
return response_elt
|
||||
# Return empty IQ by default
|
||||
empty_response = domish.Element((None, "iq"))
|
||||
empty_response["type"] = "result"
|
||||
return empty_response
|
||||
|
||||
iq_elt.send = mock_send
|
||||
return iq_elt
|
||||
|
||||
# Attach list for test assertions
|
||||
client_IQ.sent_iqs = sent_iqs
|
||||
return client_IQ
|
||||
|
||||
return factory
|
||||
|
||||
|
||||
@fixture
|
||||
def client():
|
||||
client = MagicMock()
|
||||
|
|
|
|||
Loading…
Reference in a new issue