massive refactoring to switch from camelCase to snake_case:
historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a pre-PEP8 code, to use the same coding style as in Twisted. However, snake_case is more readable and it's better to follow PEP8 best practices, so it has been decided to move on full snake_case. Because Libervia has a huge codebase, this ended with a ugly mix of camelCase and snake_case. To fix that, this patch does a big refactoring by renaming every function and method (including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case. This is a massive change, and may result in some bugs.
This commit is contained in:
parent
d50412c7f7
commit
6a6f15707a
17 changed files with 9945 additions and 9945 deletions
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
## logging configuration for tests ##
|
||||
from sat.core import log_config
|
||||
log_config.satConfigure()
|
||||
log_config.sat_configure()
|
||||
|
||||
import logging
|
||||
from sat.core.log import getLogger
|
||||
|
|
@ -52,14 +52,14 @@ def b2s(value):
|
|||
return "True" if value else "False"
|
||||
|
||||
|
||||
def muteLogging():
|
||||
def mute_logging():
|
||||
"""Temporarily set the logging level to CRITICAL to not pollute the output with expected errors."""
|
||||
logger = getLogger()
|
||||
logger.original_level = logger.getEffectiveLevel()
|
||||
logger.setLevel(logging.CRITICAL)
|
||||
|
||||
|
||||
def unmuteLogging():
|
||||
def unmute_logging():
|
||||
"""Restore the logging level after it has been temporarily disabled."""
|
||||
logger = getLogger()
|
||||
logger.setLevel(logger.original_level)
|
||||
|
|
@ -97,17 +97,17 @@ class FakeSAT(object):
|
|||
self.plugins = {}
|
||||
self.profiles = {}
|
||||
|
||||
def delContact(self, to, profile_key):
|
||||
def contact_del(self, to, profile_key):
|
||||
#TODO
|
||||
pass
|
||||
|
||||
def registerCallback(self, callback, *args, **kwargs):
|
||||
def register_callback(self, callback, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def messageSend(self, to_s, msg, subject=None, mess_type='auto', extra={}, profile_key='@NONE@'):
|
||||
self.sendAndStoreMessage({"to": JID(to_s)})
|
||||
def message_send(self, to_s, msg, subject=None, mess_type='auto', extra={}, profile_key='@NONE@'):
|
||||
self.send_and_store_message({"to": JID(to_s)})
|
||||
|
||||
def _sendMessageToStream(self, mess_data, client):
|
||||
def _send_message_to_stream(self, mess_data, client):
|
||||
"""Save the information to check later to whom messages have been sent.
|
||||
|
||||
@param mess_data: message data dictionnary
|
||||
|
|
@ -116,7 +116,7 @@ class FakeSAT(object):
|
|||
client.xmlstream.send(mess_data['xml'])
|
||||
return mess_data
|
||||
|
||||
def _storeMessage(self, mess_data, client):
|
||||
def _store_message(self, mess_data, client):
|
||||
"""Save the information to check later if entries have been added to the history.
|
||||
|
||||
@param mess_data: message data dictionnary
|
||||
|
|
@ -125,7 +125,7 @@ class FakeSAT(object):
|
|||
self.stored_messages.append(mess_data["to"])
|
||||
return mess_data
|
||||
|
||||
def sendMessageToBridge(self, mess_data, client):
|
||||
def send_message_to_bridge(self, mess_data, client):
|
||||
"""Simulate the message being sent to the frontends.
|
||||
|
||||
@param mess_data: message data dictionnary
|
||||
|
|
@ -133,33 +133,33 @@ class FakeSAT(object):
|
|||
"""
|
||||
return mess_data # TODO
|
||||
|
||||
def getProfileName(self, profile_key):
|
||||
def get_profile_name(self, profile_key):
|
||||
"""Get the profile name from the profile_key"""
|
||||
return profile_key
|
||||
|
||||
def getClient(self, profile_key):
|
||||
def get_client(self, profile_key):
|
||||
"""Convenient method to get client from profile key
|
||||
@return: client or None if it doesn't exist"""
|
||||
profile = self.memory.getProfileName(profile_key)
|
||||
profile = self.memory.get_profile_name(profile_key)
|
||||
if not profile:
|
||||
raise exceptions.ProfileKeyUnknown
|
||||
if profile not in self.profiles:
|
||||
self.profiles[profile] = FakeClient(self, profile)
|
||||
return self.profiles[profile]
|
||||
|
||||
def getJidNStream(self, profile_key):
|
||||
def get_jid_n_stream(self, profile_key):
|
||||
"""Convenient method to get jid and stream from profile key
|
||||
@return: tuple (jid, xmlstream) from profile, can be None"""
|
||||
return (C.PROFILE_DICT[profile_key], None)
|
||||
|
||||
def isConnected(self, profile):
|
||||
def is_connected(self, profile):
|
||||
return True
|
||||
|
||||
def getSentMessages(self, profile_index):
|
||||
def get_sent_messages(self, profile_index):
|
||||
"""Return all the sent messages (in the order they have been sent) and
|
||||
empty the list. Called by tests. FakeClient instances associated to each
|
||||
profile must have been previously initialized with the method
|
||||
FakeSAT.getClient.
|
||||
FakeSAT.get_client.
|
||||
|
||||
@param profile_index: index of the profile to consider (cf. C.PROFILE)
|
||||
@return: the sent messages for given profile, or None"""
|
||||
|
|
@ -170,10 +170,10 @@ class FakeSAT(object):
|
|||
except IndexError:
|
||||
return None
|
||||
|
||||
def getSentMessage(self, profile_index):
|
||||
def get_sent_message(self, profile_index):
|
||||
"""Pop and return the sent message in first position (works like a FIFO).
|
||||
Called by tests. FakeClient instances associated to each profile must have
|
||||
been previously initialized with the method FakeSAT.getClient.
|
||||
been previously initialized with the method FakeSAT.get_client.
|
||||
|
||||
@param profile_index: index of the profile to consider (cf. C.PROFILE)
|
||||
@return: the sent message for given profile, or None"""
|
||||
|
|
@ -182,20 +182,20 @@ class FakeSAT(object):
|
|||
except IndexError:
|
||||
return None
|
||||
|
||||
def getSentMessageXml(self, profile_index):
|
||||
def get_sent_message_xml(self, profile_index):
|
||||
"""Pop and return the sent message in first position (works like a FIFO).
|
||||
Called by tests. FakeClient instances associated to each profile must have
|
||||
been previously initialized with the method FakeSAT.getClient.
|
||||
been previously initialized with the method FakeSAT.get_client.
|
||||
@return: XML representation of the sent message for given profile, or None"""
|
||||
entry = self.getSentMessage(profile_index)
|
||||
entry = self.get_sent_message(profile_index)
|
||||
return entry.toXml() if entry else None
|
||||
|
||||
def findFeaturesSet(self, features, identity=None, jid_=None, profile=C.PROF_KEY_NONE):
|
||||
"""Call self.addFeature from your tests to change the return value.
|
||||
def find_features_set(self, features, identity=None, jid_=None, profile=C.PROF_KEY_NONE):
|
||||
"""Call self.add_feature from your tests to change the return value.
|
||||
|
||||
@return: a set of entities
|
||||
"""
|
||||
client = self.getClient(profile)
|
||||
client = self.get_client(profile)
|
||||
if jid_ is None:
|
||||
jid_ = JID(client.jid.host)
|
||||
try:
|
||||
|
|
@ -205,12 +205,12 @@ class FakeSAT(object):
|
|||
pass
|
||||
return defer.succeed(set())
|
||||
|
||||
def addFeature(self, jid_, feature, profile_key):
|
||||
def add_feature(self, jid_, feature, profile_key):
|
||||
"""Add a feature to an entity.
|
||||
|
||||
To be called from your tests when needed.
|
||||
"""
|
||||
client = self.getClient(profile_key)
|
||||
client = self.get_client(profile_key)
|
||||
if not hasattr(client, 'features'):
|
||||
client.features = {}
|
||||
if jid_ not in client.features:
|
||||
|
|
@ -224,13 +224,13 @@ class FakeBridge(object):
|
|||
def __init__(self):
|
||||
self.expected_calls = {}
|
||||
|
||||
def expectCall(self, name, *check_args, **check_kwargs):
|
||||
def expect_call(self, name, *check_args, **check_kwargs):
|
||||
if hasattr(self, name): # queue this new call as one already exists
|
||||
self.expected_calls.setdefault(name, [])
|
||||
self.expected_calls[name].append((check_args, check_kwargs))
|
||||
return
|
||||
|
||||
def checkCall(*args, **kwargs):
|
||||
def check_call(*args, **kwargs):
|
||||
if args != check_args or kwargs != check_kwargs:
|
||||
print("\n\n--------------------")
|
||||
print("Args are not equals:")
|
||||
|
|
@ -244,19 +244,19 @@ class FakeBridge(object):
|
|||
args, kwargs = self.expected_calls[name].pop(0)
|
||||
if len(self.expected_calls[name]) == 0:
|
||||
del self.expected_calls[name]
|
||||
self.expectCall(name, *args, **kwargs)
|
||||
self.expect_call(name, *args, **kwargs)
|
||||
|
||||
setattr(self, name, checkCall)
|
||||
setattr(self, name, check_call)
|
||||
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async_=False, doc=None):
|
||||
def add_method(self, name, int_suffix, in_sign, out_sign, method, async_=False, doc=None):
|
||||
pass
|
||||
|
||||
def addSignal(self, name, int_suffix, signature):
|
||||
def add_signal(self, name, int_suffix, signature):
|
||||
pass
|
||||
|
||||
def addTestCallback(self, name, method):
|
||||
def add_test_callback(self, name, method):
|
||||
"""This can be used to register callbacks for bridge methods AND signals.
|
||||
Contrary to expectCall, this will not check if the method or signal is
|
||||
Contrary to expect_call, this will not check if the method or signal is
|
||||
called/sent with the correct arguments, it will instead run the callback
|
||||
of your choice."""
|
||||
setattr(self, name, method)
|
||||
|
|
@ -271,16 +271,16 @@ class FakeParams(Params):
|
|||
Params.__init__(self, host, storage)
|
||||
self.params = {} # naive simulation of values storage
|
||||
|
||||
def setParam(self, name, value, category, security_limit=-1, profile_key='@NONE@'):
|
||||
profile = self.getProfileName(profile_key)
|
||||
def param_set(self, name, value, category, security_limit=-1, profile_key='@NONE@'):
|
||||
profile = self.get_profile_name(profile_key)
|
||||
self.params.setdefault(profile, {})
|
||||
self.params[profile_key][(category, name)] = value
|
||||
|
||||
def getParamA(self, name, category, attr="value", profile_key='@NONE@'):
|
||||
profile = self.getProfileName(profile_key)
|
||||
def param_get_a(self, name, category, attr="value", profile_key='@NONE@'):
|
||||
profile = self.get_profile_name(profile_key)
|
||||
return self.params[profile][(category, name)]
|
||||
|
||||
def getProfileName(self, profile_key, return_profile_keys=False):
|
||||
def get_profile_name(self, profile_key, return_profile_keys=False):
|
||||
if profile_key == '@DEFAULT@':
|
||||
return C.PROFILE[0]
|
||||
elif profile_key == '@NONE@':
|
||||
|
|
@ -288,7 +288,7 @@ class FakeParams(Params):
|
|||
else:
|
||||
return profile_key
|
||||
|
||||
def loadIndParams(self, profile, cache=None):
|
||||
def load_ind_params(self, profile, cache=None):
|
||||
self.params[profile] = {}
|
||||
return defer.succeed(None)
|
||||
|
||||
|
|
@ -301,7 +301,7 @@ class FakeMemory(Memory):
|
|||
# manipulating basic stuff, the others should be overwritten when needed
|
||||
self.host = host
|
||||
self.params = FakeParams(host, None)
|
||||
self.config = tools_config.parseMainConf()
|
||||
self.config = tools_config.parse_main_conf()
|
||||
self.reinit()
|
||||
|
||||
def reinit(self):
|
||||
|
|
@ -312,29 +312,29 @@ class FakeMemory(Memory):
|
|||
self.params.frontends_cache = []
|
||||
self.entities_data = {}
|
||||
|
||||
def getProfileName(self, profile_key, return_profile_keys=False):
|
||||
return self.params.getProfileName(profile_key, return_profile_keys)
|
||||
def get_profile_name(self, profile_key, return_profile_keys=False):
|
||||
return self.params.get_profile_name(profile_key, return_profile_keys)
|
||||
|
||||
def addToHistory(self, from_jid, to_jid, message, _type='chat', extra=None, timestamp=None, profile="@NONE@"):
|
||||
def add_to_history(self, from_jid, to_jid, message, _type='chat', extra=None, timestamp=None, profile="@NONE@"):
|
||||
pass
|
||||
|
||||
def addContact(self, contact_jid, attributes, groups, profile_key='@DEFAULT@'):
|
||||
def contact_add(self, contact_jid, attributes, groups, profile_key='@DEFAULT@'):
|
||||
pass
|
||||
|
||||
def setPresenceStatus(self, contact_jid, show, priority, statuses, profile_key='@DEFAULT@'):
|
||||
def set_presence_status(self, contact_jid, show, priority, statuses, profile_key='@DEFAULT@'):
|
||||
pass
|
||||
|
||||
def addWaitingSub(self, type_, contact_jid, profile_key):
|
||||
def add_waiting_sub(self, type_, contact_jid, profile_key):
|
||||
pass
|
||||
|
||||
def delWaitingSub(self, contact_jid, profile_key):
|
||||
def del_waiting_sub(self, contact_jid, profile_key):
|
||||
pass
|
||||
|
||||
def updateEntityData(self, entity_jid, key, value, silent=False, profile_key="@NONE@"):
|
||||
def update_entity_data(self, entity_jid, key, value, silent=False, profile_key="@NONE@"):
|
||||
self.entities_data.setdefault(entity_jid, {})
|
||||
self.entities_data[entity_jid][key] = value
|
||||
|
||||
def getEntityData(self, entity_jid, keys, profile_key):
|
||||
def entity_data_get(self, entity_jid, keys, profile_key):
|
||||
result = {}
|
||||
for key in keys:
|
||||
result[key] = self.entities_data[entity_jid][key]
|
||||
|
|
@ -358,9 +358,9 @@ class FakeRosterProtocol(SatRosterProtocol):
|
|||
SatRosterProtocol.__init__(self, host)
|
||||
self.parent = parent
|
||||
self._jids = {}
|
||||
self.addItem(parent.jid.userhostJID())
|
||||
self.add_item(parent.jid.userhostJID())
|
||||
|
||||
def addItem(self, jid, *args, **kwargs):
|
||||
def add_item(self, jid, *args, **kwargs):
|
||||
if not args and not kwargs:
|
||||
# defaults values setted for the tests only
|
||||
kwargs["subscriptionTo"] = True
|
||||
|
|
@ -369,9 +369,9 @@ class FakeRosterProtocol(SatRosterProtocol):
|
|||
attrs = {'to': b2s(roster_item.subscriptionTo), 'from': b2s(roster_item.subscriptionFrom), 'ask': b2s(roster_item.pendingOut)}
|
||||
if roster_item.name:
|
||||
attrs['name'] = roster_item.name
|
||||
self.host.bridge.expectCall("newContact", jid.full(), attrs, roster_item.groups, self.parent.profile)
|
||||
self.host.bridge.expect_call("contact_new", jid.full(), attrs, roster_item.groups, self.parent.profile)
|
||||
self._jids[jid] = roster_item
|
||||
self._registerItem(roster_item)
|
||||
self._register_item(roster_item)
|
||||
|
||||
|
||||
class FakeXmlStream(object):
|
||||
|
|
@ -420,8 +420,8 @@ class FakeClient(object):
|
|||
|
||||
class SatTestCase(unittest.TestCase):
|
||||
|
||||
def assertEqualXML(self, xml, expected, ignore_blank=False):
|
||||
def equalElt(got_elt, exp_elt):
|
||||
def assert_equal_xml(self, xml, expected, ignore_blank=False):
|
||||
def equal_elt(got_elt, exp_elt):
|
||||
if ignore_blank:
|
||||
for elt in got_elt, exp_elt:
|
||||
for attr in ('text', 'tail'):
|
||||
|
|
@ -449,7 +449,7 @@ class SatTestCase(unittest.TestCase):
|
|||
print("children len: got %d expected: %d" % (len(got_elt), len(exp_elt)))
|
||||
return False
|
||||
for idx, child in enumerate(got_elt):
|
||||
if not equalElt(child, exp_elt[idx]):
|
||||
if not equal_elt(child, exp_elt[idx]):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
@ -460,7 +460,7 @@ class SatTestCase(unittest.TestCase):
|
|||
xml_elt = etree.fromstring(remove_blank(xml) if ignore_blank else xml)
|
||||
expected_elt = etree.fromstring(remove_blank(expected) if ignore_blank else expected)
|
||||
|
||||
if not equalElt(xml_elt, expected_elt):
|
||||
if not equal_elt(xml_elt, expected_elt):
|
||||
print("---")
|
||||
print("XML are not equals:")
|
||||
print("got:\n-\n%s\n-\n\n" % etree.tostring(xml_elt, encoding='utf-8'))
|
||||
|
|
@ -468,7 +468,7 @@ class SatTestCase(unittest.TestCase):
|
|||
print("---")
|
||||
raise DifferentXMLException
|
||||
|
||||
def assertEqualUnsortedList(self, a, b, msg):
|
||||
def assert_equal_unsorted_list(self, a, b, msg):
|
||||
counter_a = Counter(a)
|
||||
counter_b = Counter(b)
|
||||
if counter_a != counter_b:
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class FakeMUCClient(object):
|
|||
@param profile_key: the profile key of the user joining the room
|
||||
@return: the deferred joined wokkel.muc.Room instance
|
||||
"""
|
||||
profile = self.host.memory.getProfileName(profile_key)
|
||||
profile = self.host.memory.get_profile_name(profile_key)
|
||||
roster = {}
|
||||
|
||||
# ask the other profiles to fill our roster
|
||||
|
|
@ -101,7 +101,7 @@ class FakeMUCClient(object):
|
|||
@param profile_key: the profile key of the user joining the room
|
||||
@return: a dummy deferred
|
||||
"""
|
||||
profile = self.host.memory.getProfileName(profile_key)
|
||||
profile = self.host.memory.get_profile_name(profile_key)
|
||||
room = self.joined_rooms[roomJID]
|
||||
# remove ourself from the other rosters
|
||||
for i in range(0, len(C.PROFILE)):
|
||||
|
|
@ -134,20 +134,20 @@ class FakeXEP_0045(plugin_xep_0045.XEP_0045):
|
|||
@param profile_key: the profile of the user joining the room
|
||||
@return: the deferred joined wokkel.muc.Room instance or None
|
||||
"""
|
||||
profile = self.host.memory.getProfileName(profile_key)
|
||||
profile = self.host.memory.get_profile_name(profile_key)
|
||||
if room_jid in self.clients[profile].joined_rooms:
|
||||
return defer.succeed(None)
|
||||
room = self.clients[profile].join(room_jid, nick, profile_key=profile)
|
||||
return room
|
||||
|
||||
def joinRoom(self, muc_index, user_index):
|
||||
def join_room(self, muc_index, user_index):
|
||||
"""Called by tests
|
||||
@return: the nickname of the user who joined room"""
|
||||
muc_jid = C.MUC[muc_index]
|
||||
nick = C.JID[user_index].user
|
||||
profile = C.PROFILE[user_index]
|
||||
self.join(muc_jid, nick, profile_key=profile)
|
||||
return self.getNick(muc_index, user_index)
|
||||
return self.get_nick(muc_index, user_index)
|
||||
|
||||
def leave(self, room_jid, profile_key="@DEFAULT@"):
|
||||
"""
|
||||
|
|
@ -155,21 +155,21 @@ class FakeXEP_0045(plugin_xep_0045.XEP_0045):
|
|||
@param profile_key: the profile of the user leaving the room
|
||||
@return: a dummy deferred
|
||||
"""
|
||||
profile = self.host.memory.getProfileName(profile_key)
|
||||
profile = self.host.memory.get_profile_name(profile_key)
|
||||
if room_jid not in self.clients[profile].joined_rooms:
|
||||
raise plugin_xep_0045.UnknownRoom("This room has not been joined")
|
||||
return self.clients[profile].leave(room_jid, profile)
|
||||
|
||||
def leaveRoom(self, muc_index, user_index):
|
||||
def leave_room(self, muc_index, user_index):
|
||||
"""Called by tests
|
||||
@return: the nickname of the user who left the room"""
|
||||
muc_jid = C.MUC[muc_index]
|
||||
nick = self.getNick(muc_index, user_index)
|
||||
nick = self.get_nick(muc_index, user_index)
|
||||
profile = C.PROFILE[user_index]
|
||||
self.leave(muc_jid, profile_key=profile)
|
||||
return nick
|
||||
|
||||
def getRoom(self, muc_index, user_index):
|
||||
def get_room(self, muc_index, user_index):
|
||||
"""Called by tests
|
||||
@return: a wokkel.muc.Room instance"""
|
||||
profile = C.PROFILE[user_index]
|
||||
|
|
@ -179,13 +179,13 @@ class FakeXEP_0045(plugin_xep_0045.XEP_0045):
|
|||
except (AttributeError, KeyError):
|
||||
return None
|
||||
|
||||
def getNick(self, muc_index, user_index):
|
||||
def get_nick(self, muc_index, user_index):
|
||||
try:
|
||||
return self.getRoomNick(C.MUC[muc_index], C.PROFILE[user_index])
|
||||
return self.get_room_nick(C.MUC[muc_index], C.PROFILE[user_index])
|
||||
except (KeyError, AttributeError):
|
||||
return ""
|
||||
|
||||
def getNickOfUser(self, muc_index, user_index, profile_index, secure=True):
|
||||
def get_nick_of_user(self, muc_index, user_index, profile_index, secure=True):
|
||||
try:
|
||||
room = self.clients[C.PROFILE[profile_index]].joined_rooms[C.MUC[muc_index]]
|
||||
return self.getRoomNickOfUser(room, C.JID[user_index])
|
||||
|
|
@ -200,7 +200,7 @@ class FakeXEP_0249(object):
|
|||
def invite(self, target, room, options={}, profile_key="@DEFAULT@"):
|
||||
"""
|
||||
Invite a user to a room. To accept the invitation from a test,
|
||||
just call FakeXEP_0045.joinRoom (no need to have a dedicated method).
|
||||
just call FakeXEP_0045.join_room (no need to have a dedicated method).
|
||||
@param target: jid of the user to invite
|
||||
@param room: jid of the room where the user is invited
|
||||
@options: attribute with extra info (reason, password) as in #XEP-0249
|
||||
|
|
@ -278,13 +278,13 @@ class FakeSatPubSubClient(object):
|
|||
self.__rsm_responses[ext_data["id"]] = RSMResponse(len(items), *args)
|
||||
return defer.succeed(items)
|
||||
|
||||
def retractItems(self, service, nodeIdentifier, itemIdentifiers, sender=None):
|
||||
def retract_items(self, service, nodeIdentifier, itemIdentifiers, sender=None):
|
||||
node = self.__items[nodeIdentifier]
|
||||
for item in [item for item in node if item["id"] in itemIdentifiers]:
|
||||
node.remove(item)
|
||||
return defer.succeed(None)
|
||||
|
||||
def getRSMResponse(self, id):
|
||||
def get_rsm_response(self, id):
|
||||
if id not in self.__rsm_responses:
|
||||
return {}
|
||||
result = self.__rsm_responses[id].toDict()
|
||||
|
|
@ -294,7 +294,7 @@ class FakeSatPubSubClient(object):
|
|||
def subscriptions(self, service, nodeIdentifier, sender=None):
|
||||
return defer.succeed([])
|
||||
|
||||
def service_getDiscoItems(self, service, nodeIdentifier, profile_key=C.PROF_KEY_NONE):
|
||||
def service_get_disco_items(self, service, nodeIdentifier, profile_key=C.PROF_KEY_NONE):
|
||||
items = DiscoItems()
|
||||
for item in list(self.__items.keys()):
|
||||
items.append(DiscoItem(service, item))
|
||||
|
|
|
|||
|
|
@ -46,14 +46,14 @@ class SatMessageProtocolTest(unittest.TestCase):
|
|||
self.message = xmpp.SatMessageProtocol(self.host)
|
||||
self.message.parent = helpers.FakeClient(self.host)
|
||||
|
||||
def test_onMessage(self):
|
||||
def test_on_message(self):
|
||||
xml = """
|
||||
<message type="chat" from="sender@example.net/house" to="test@example.org/SàT" id="test_1">
|
||||
<body>test</body>
|
||||
</message>
|
||||
"""
|
||||
stanza = parseXml(xml)
|
||||
self.host.bridge.expectCall("messageNew", "sender@example.net/house", "test", "chat", "test@example.org/SàT", {}, profile=Const.PROFILE[0])
|
||||
self.host.bridge.expect_call("message_new", "sender@example.net/house", "test", "chat", "test@example.org/SàT", {}, profile=Const.PROFILE[0])
|
||||
self.message.onMessage(stanza)
|
||||
|
||||
|
||||
|
|
@ -64,15 +64,15 @@ class SatRosterProtocolTest(unittest.TestCase):
|
|||
self.roster = xmpp.SatRosterProtocol(self.host)
|
||||
self.roster.parent = helpers.FakeClient(self.host)
|
||||
|
||||
def test__registerItem(self):
|
||||
def test_register_item(self):
|
||||
roster_item = RosterItem(Const.JID[0])
|
||||
roster_item.name = "Test Man"
|
||||
roster_item.subscriptionTo = True
|
||||
roster_item.subscriptionFrom = True
|
||||
roster_item.ask = False
|
||||
roster_item.groups = set(["Test Group 1", "Test Group 2", "Test Group 3"])
|
||||
self.host.bridge.expectCall("newContact", Const.JID_STR[0], {'to': 'True', 'from': 'True', 'ask': 'False', 'name': 'Test Man'}, set(["Test Group 1", "Test Group 2", "Test Group 3"]), Const.PROFILE[0])
|
||||
self.roster._registerItem(roster_item)
|
||||
self.host.bridge.expect_call("contact_new", Const.JID_STR[0], {'to': 'True', 'from': 'True', 'ask': 'False', 'name': 'Test Man'}, set(["Test Group 1", "Test Group 2", "Test Group 3"]), Const.PROFILE[0])
|
||||
self.roster._register_item(roster_item)
|
||||
|
||||
|
||||
class SatPresenceProtocolTest(unittest.TestCase):
|
||||
|
|
@ -83,29 +83,29 @@ class SatPresenceProtocolTest(unittest.TestCase):
|
|||
self.presence.parent = helpers.FakeClient(self.host)
|
||||
|
||||
def test_availableReceived(self):
|
||||
self.host.bridge.expectCall("presenceUpdate", Const.JID_STR[0], "xa", 15, {'default': "test status", 'fr': 'statut de test'}, Const.PROFILE[0])
|
||||
self.host.bridge.expect_call("presence_update", Const.JID_STR[0], "xa", 15, {'default': "test status", 'fr': 'statut de test'}, Const.PROFILE[0])
|
||||
self.presence.availableReceived(Const.JID[0], 'xa', {None: "test status", 'fr': 'statut de test'}, 15)
|
||||
|
||||
def test_availableReceived_empty_statuses(self):
|
||||
self.host.bridge.expectCall("presenceUpdate", Const.JID_STR[0], "xa", 15, {}, Const.PROFILE[0])
|
||||
def test_available_received_empty_statuses(self):
|
||||
self.host.bridge.expect_call("presence_update", Const.JID_STR[0], "xa", 15, {}, Const.PROFILE[0])
|
||||
self.presence.availableReceived(Const.JID[0], 'xa', None, 15)
|
||||
|
||||
def test_unavailableReceived(self):
|
||||
self.host.bridge.expectCall("presenceUpdate", Const.JID_STR[0], "unavailable", 0, {}, Const.PROFILE[0])
|
||||
self.host.bridge.expect_call("presence_update", Const.JID_STR[0], "unavailable", 0, {}, Const.PROFILE[0])
|
||||
self.presence.unavailableReceived(Const.JID[0], None)
|
||||
|
||||
def test_subscribedReceived(self):
|
||||
self.host.bridge.expectCall("subscribe", "subscribed", Const.JID[0].userhost(), Const.PROFILE[0])
|
||||
self.host.bridge.expect_call("subscribe", "subscribed", Const.JID[0].userhost(), Const.PROFILE[0])
|
||||
self.presence.subscribedReceived(Const.JID[0])
|
||||
|
||||
def test_unsubscribedReceived(self):
|
||||
self.host.bridge.expectCall("subscribe", "unsubscribed", Const.JID[0].userhost(), Const.PROFILE[0])
|
||||
self.host.bridge.expect_call("subscribe", "unsubscribed", Const.JID[0].userhost(), Const.PROFILE[0])
|
||||
self.presence.unsubscribedReceived(Const.JID[0])
|
||||
|
||||
def test_subscribeReceived(self):
|
||||
self.host.bridge.expectCall("subscribe", "subscribe", Const.JID[0].userhost(), Const.PROFILE[0])
|
||||
self.host.bridge.expect_call("subscribe", "subscribe", Const.JID[0].userhost(), Const.PROFILE[0])
|
||||
self.presence.subscribeReceived(Const.JID[0])
|
||||
|
||||
def test_unsubscribeReceived(self):
|
||||
self.host.bridge.expectCall("subscribe", "unsubscribe", Const.JID[0].userhost(), Const.PROFILE[0])
|
||||
self.host.bridge.expect_call("subscribe", "unsubscribe", Const.JID[0].userhost(), Const.PROFILE[0])
|
||||
self.presence.unsubscribeReceived(Const.JID[0])
|
||||
|
|
|
|||
|
|
@ -29,96 +29,96 @@ class FakeXEP_0045Test(helpers.SatTestCase):
|
|||
self.host = helpers.FakeSAT()
|
||||
self.plugin = helpers_plugins.FakeXEP_0045(self.host)
|
||||
|
||||
def test_joinRoom(self):
|
||||
self.plugin.joinRoom(0, 0)
|
||||
self.assertEqual("test", self.plugin.getNick(0, 0))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 0, 0))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 1, 0))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 2, 0))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 3, 0))
|
||||
self.assertEqual("", self.plugin.getNick(0, 1))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 0, 1))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 1, 1))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 2, 1))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 3, 1))
|
||||
self.assertEqual("", self.plugin.getNick(0, 2))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 0, 2))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 1, 2))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 2, 2))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 3, 2))
|
||||
self.assertEqual("", self.plugin.getNick(0, 3))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 0, 3))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 1, 3))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 2, 3))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 3, 3))
|
||||
self.plugin.joinRoom(0, 1)
|
||||
self.assertEqual("test", self.plugin.getNick(0, 0))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 0, 0))
|
||||
self.assertEqual("sender", self.plugin.getNickOfUser(0, 1, 0))
|
||||
self.assertEqual("sender", self.plugin.getNickOfUser(0, 2, 0))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 3, 0))
|
||||
self.assertEqual("sender", self.plugin.getNick(0, 1))
|
||||
self.assertEqual("test", self.plugin.getNickOfUser(0, 0, 1))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 1, 1))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 2, 1))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 3, 1))
|
||||
self.assertEqual("", self.plugin.getNick(0, 2))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 0, 2))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 1, 2))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 2, 2))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 3, 2))
|
||||
self.assertEqual("", self.plugin.getNick(0, 3))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 0, 3))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 1, 3))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 2, 3))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 3, 3))
|
||||
self.plugin.joinRoom(0, 2)
|
||||
self.assertEqual("test", self.plugin.getNick(0, 0))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 0, 0))
|
||||
self.assertEqual("sender", self.plugin.getNickOfUser(0, 1, 0))
|
||||
self.assertEqual("sender", self.plugin.getNickOfUser(0, 2, 0))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 3, 0))
|
||||
self.assertEqual("sender", self.plugin.getNick(0, 1))
|
||||
self.assertEqual("test", self.plugin.getNickOfUser(0, 0, 1))
|
||||
def test_join_room(self):
|
||||
self.plugin.join_room(0, 0)
|
||||
self.assertEqual("test", self.plugin.get_nick(0, 0))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 0, 0))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 1, 0))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 2, 0))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 3, 0))
|
||||
self.assertEqual("", self.plugin.get_nick(0, 1))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 0, 1))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 1, 1))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 2, 1))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 3, 1))
|
||||
self.assertEqual("", self.plugin.get_nick(0, 2))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 0, 2))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 1, 2))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 2, 2))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 3, 2))
|
||||
self.assertEqual("", self.plugin.get_nick(0, 3))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 0, 3))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 1, 3))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 2, 3))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 3, 3))
|
||||
self.plugin.join_room(0, 1)
|
||||
self.assertEqual("test", self.plugin.get_nick(0, 0))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 0, 0))
|
||||
self.assertEqual("sender", self.plugin.get_nick_of_user(0, 1, 0))
|
||||
self.assertEqual("sender", self.plugin.get_nick_of_user(0, 2, 0))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 3, 0))
|
||||
self.assertEqual("sender", self.plugin.get_nick(0, 1))
|
||||
self.assertEqual("test", self.plugin.get_nick_of_user(0, 0, 1))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 1, 1))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 2, 1))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 3, 1))
|
||||
self.assertEqual("", self.plugin.get_nick(0, 2))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 0, 2))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 1, 2))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 2, 2))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 3, 2))
|
||||
self.assertEqual("", self.plugin.get_nick(0, 3))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 0, 3))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 1, 3))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 2, 3))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 3, 3))
|
||||
self.plugin.join_room(0, 2)
|
||||
self.assertEqual("test", self.plugin.get_nick(0, 0))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 0, 0))
|
||||
self.assertEqual("sender", self.plugin.get_nick_of_user(0, 1, 0))
|
||||
self.assertEqual("sender", self.plugin.get_nick_of_user(0, 2, 0))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 3, 0))
|
||||
self.assertEqual("sender", self.plugin.get_nick(0, 1))
|
||||
self.assertEqual("test", self.plugin.get_nick_of_user(0, 0, 1))
|
||||
self.assertEqual(
|
||||
"sender", self.plugin.getNickOfUser(0, 1, 1)
|
||||
"sender", self.plugin.get_nick_of_user(0, 1, 1)
|
||||
) # Const.JID[2] is in the roster for Const.PROFILE[1]
|
||||
self.assertEqual("sender", self.plugin.getNickOfUser(0, 2, 1))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 3, 1))
|
||||
self.assertEqual("sender", self.plugin.getNick(0, 2))
|
||||
self.assertEqual("test", self.plugin.getNickOfUser(0, 0, 2))
|
||||
self.assertEqual("sender", self.plugin.getNickOfUser(0, 1, 2))
|
||||
self.assertEqual("sender", self.plugin.get_nick_of_user(0, 2, 1))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 3, 1))
|
||||
self.assertEqual("sender", self.plugin.get_nick(0, 2))
|
||||
self.assertEqual("test", self.plugin.get_nick_of_user(0, 0, 2))
|
||||
self.assertEqual("sender", self.plugin.get_nick_of_user(0, 1, 2))
|
||||
self.assertEqual(
|
||||
"sender", self.plugin.getNickOfUser(0, 2, 2)
|
||||
"sender", self.plugin.get_nick_of_user(0, 2, 2)
|
||||
) # Const.JID[1] is in the roster for Const.PROFILE[2]
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 3, 2))
|
||||
self.assertEqual("", self.plugin.getNick(0, 3))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 0, 3))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 1, 3))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 2, 3))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 3, 3))
|
||||
self.plugin.joinRoom(0, 3)
|
||||
self.assertEqual("test", self.plugin.getNick(0, 0))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 0, 0))
|
||||
self.assertEqual("sender", self.plugin.getNickOfUser(0, 1, 0))
|
||||
self.assertEqual("sender", self.plugin.getNickOfUser(0, 2, 0))
|
||||
self.assertEqual("sender_", self.plugin.getNickOfUser(0, 3, 0))
|
||||
self.assertEqual("sender", self.plugin.getNick(0, 1))
|
||||
self.assertEqual("test", self.plugin.getNickOfUser(0, 0, 1))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 3, 2))
|
||||
self.assertEqual("", self.plugin.get_nick(0, 3))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 0, 3))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 1, 3))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 2, 3))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 3, 3))
|
||||
self.plugin.join_room(0, 3)
|
||||
self.assertEqual("test", self.plugin.get_nick(0, 0))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 0, 0))
|
||||
self.assertEqual("sender", self.plugin.get_nick_of_user(0, 1, 0))
|
||||
self.assertEqual("sender", self.plugin.get_nick_of_user(0, 2, 0))
|
||||
self.assertEqual("sender_", self.plugin.get_nick_of_user(0, 3, 0))
|
||||
self.assertEqual("sender", self.plugin.get_nick(0, 1))
|
||||
self.assertEqual("test", self.plugin.get_nick_of_user(0, 0, 1))
|
||||
self.assertEqual(
|
||||
"sender", self.plugin.getNickOfUser(0, 1, 1)
|
||||
"sender", self.plugin.get_nick_of_user(0, 1, 1)
|
||||
) # Const.JID[2] is in the roster for Const.PROFILE[1]
|
||||
self.assertEqual("sender", self.plugin.getNickOfUser(0, 2, 1))
|
||||
self.assertEqual("sender_", self.plugin.getNickOfUser(0, 3, 1))
|
||||
self.assertEqual("sender", self.plugin.getNick(0, 2))
|
||||
self.assertEqual("test", self.plugin.getNickOfUser(0, 0, 2))
|
||||
self.assertEqual("sender", self.plugin.getNickOfUser(0, 1, 2))
|
||||
self.assertEqual("sender", self.plugin.get_nick_of_user(0, 2, 1))
|
||||
self.assertEqual("sender_", self.plugin.get_nick_of_user(0, 3, 1))
|
||||
self.assertEqual("sender", self.plugin.get_nick(0, 2))
|
||||
self.assertEqual("test", self.plugin.get_nick_of_user(0, 0, 2))
|
||||
self.assertEqual("sender", self.plugin.get_nick_of_user(0, 1, 2))
|
||||
self.assertEqual(
|
||||
"sender", self.plugin.getNickOfUser(0, 2, 2)
|
||||
"sender", self.plugin.get_nick_of_user(0, 2, 2)
|
||||
) # Const.JID[1] is in the roster for Const.PROFILE[2]
|
||||
self.assertEqual("sender_", self.plugin.getNickOfUser(0, 3, 2))
|
||||
self.assertEqual("sender_", self.plugin.getNick(0, 3))
|
||||
self.assertEqual("test", self.plugin.getNickOfUser(0, 0, 3))
|
||||
self.assertEqual("sender", self.plugin.getNickOfUser(0, 1, 3))
|
||||
self.assertEqual("sender", self.plugin.getNickOfUser(0, 2, 3))
|
||||
self.assertEqual(None, self.plugin.getNickOfUser(0, 3, 3))
|
||||
self.assertEqual("sender_", self.plugin.get_nick_of_user(0, 3, 2))
|
||||
self.assertEqual("sender_", self.plugin.get_nick(0, 3))
|
||||
self.assertEqual("test", self.plugin.get_nick_of_user(0, 0, 3))
|
||||
self.assertEqual("sender", self.plugin.get_nick_of_user(0, 1, 3))
|
||||
self.assertEqual("sender", self.plugin.get_nick_of_user(0, 2, 3))
|
||||
self.assertEqual(None, self.plugin.get_nick_of_user(0, 3, 3))
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class MemoryTest(unittest.TestCase):
|
|||
def setUp(self):
|
||||
self.host = helpers.FakeSAT()
|
||||
|
||||
def _getParamXML(self, param="1", security_level=None):
|
||||
def _get_param_xml(self, param="1", security_level=None):
|
||||
"""Generate XML for testing parameters
|
||||
|
||||
@param param (str): a subset of "123"
|
||||
|
|
@ -37,7 +37,7 @@ class MemoryTest(unittest.TestCase):
|
|||
@return (str)
|
||||
"""
|
||||
|
||||
def getParam(name):
|
||||
def get_param(name):
|
||||
return """
|
||||
<param name="%(param_name)s" label="%(param_label)s" value="true" type="bool" %(security)s/>
|
||||
""" % {
|
||||
|
|
@ -50,11 +50,11 @@ class MemoryTest(unittest.TestCase):
|
|||
|
||||
params = ""
|
||||
if "1" in param:
|
||||
params += getParam(Const.ENABLE_UNIBOX_PARAM)
|
||||
params += get_param(Const.ENABLE_UNIBOX_PARAM)
|
||||
if "2" in param:
|
||||
params += getParam(Const.PARAM_IN_QUOTES)
|
||||
params += get_param(Const.PARAM_IN_QUOTES)
|
||||
if "3" in param:
|
||||
params += getParam("Dummy param")
|
||||
params += get_param("Dummy param")
|
||||
return """
|
||||
<params>
|
||||
<individual>
|
||||
|
|
@ -69,7 +69,7 @@ class MemoryTest(unittest.TestCase):
|
|||
"params": params,
|
||||
}
|
||||
|
||||
def _paramExists(self, param="1", src=None):
|
||||
def _param_exists(self, param="1", src=None):
|
||||
"""
|
||||
|
||||
@param param (str): a character in "12"
|
||||
|
|
@ -86,7 +86,7 @@ class MemoryTest(unittest.TestCase):
|
|||
for type_node in src.childNodes:
|
||||
# when src comes self.host.memory.params.dom, we have here
|
||||
# some "individual" or "general" elements, when it comes
|
||||
# from Memory.getParams we have here a "params" elements
|
||||
# from Memory.get_params we have here a "params" elements
|
||||
if type_node.nodeName not in ("individual", "general", "params"):
|
||||
continue
|
||||
for cat_node in type_node.childNodes:
|
||||
|
|
@ -100,7 +100,7 @@ class MemoryTest(unittest.TestCase):
|
|||
return True
|
||||
return False
|
||||
|
||||
def assertParam_generic(self, param="1", src=None, exists=True, deferred=False):
|
||||
def assert_param_generic(self, param="1", src=None, exists=True, deferred=False):
|
||||
"""
|
||||
@param param (str): a character in "12"
|
||||
@param src (DOM element): the top-level element to look in
|
||||
|
|
@ -116,28 +116,28 @@ class MemoryTest(unittest.TestCase):
|
|||
# in this stack we can see the line where the error came from,
|
||||
# if limit=5, 6 is not enough you can increase the value
|
||||
msg += "\n".join(traceback.format_stack(limit=5 if exists else 6))
|
||||
assertion = self._paramExists(param, src)
|
||||
assertion = self._param_exists(param, src)
|
||||
getattr(self, "assert%s" % exists)(assertion, msg)
|
||||
|
||||
def assertParamExists(self, param="1", src=None):
|
||||
self.assertParam_generic(param, src, True)
|
||||
def assert_param_exists(self, param="1", src=None):
|
||||
self.assert_param_generic(param, src, True)
|
||||
|
||||
def assertParamNotExists(self, param="1", src=None):
|
||||
self.assertParam_generic(param, src, False)
|
||||
def assert_param_not_exists(self, param="1", src=None):
|
||||
self.assert_param_generic(param, src, False)
|
||||
|
||||
def assertParamExists_async(self, src, param="1"):
|
||||
"""@param src: a deferred result from Memory.getParams"""
|
||||
self.assertParam_generic(
|
||||
def assert_param_exists_async(self, src, param="1"):
|
||||
"""@param src: a deferred result from Memory.get_params"""
|
||||
self.assert_param_generic(
|
||||
param, minidom.parseString(src.encode("utf-8")), True, True
|
||||
)
|
||||
|
||||
def assertParamNotExists_async(self, src, param="1"):
|
||||
"""@param src: a deferred result from Memory.getParams"""
|
||||
self.assertParam_generic(
|
||||
def assert_param_not_exists_async(self, src, param="1"):
|
||||
"""@param src: a deferred result from Memory.get_params"""
|
||||
self.assert_param_generic(
|
||||
param, minidom.parseString(src.encode("utf-8")), False, True
|
||||
)
|
||||
|
||||
def _getParams(self, security_limit, app="", profile_key="@NONE@"):
|
||||
def _get_params(self, security_limit, app="", profile_key="@NONE@"):
|
||||
"""Get the parameters accessible with the given security limit and application name.
|
||||
|
||||
@param security_limit (int): the security limit
|
||||
|
|
@ -146,16 +146,16 @@ class MemoryTest(unittest.TestCase):
|
|||
"""
|
||||
if profile_key == "@NONE@":
|
||||
profile_key = "@DEFAULT@"
|
||||
return self.host.memory.params.getParams(security_limit, app, profile_key)
|
||||
return self.host.memory.params.get_params(security_limit, app, profile_key)
|
||||
|
||||
def test_updateParams(self):
|
||||
def test_update_params(self):
|
||||
self.host.memory.reinit()
|
||||
# check if the update works
|
||||
self.host.memory.updateParams(self._getParamXML())
|
||||
self.assertParamExists()
|
||||
self.host.memory.update_params(self._get_param_xml())
|
||||
self.assert_param_exists()
|
||||
previous = self.host.memory.params.dom.cloneNode(True)
|
||||
# now check if it is really updated and not duplicated
|
||||
self.host.memory.updateParams(self._getParamXML())
|
||||
self.host.memory.update_params(self._get_param_xml())
|
||||
self.assertEqual(
|
||||
previous.toxml().encode("utf-8"),
|
||||
self.host.memory.params.dom.toxml().encode("utf-8"),
|
||||
|
|
@ -163,23 +163,23 @@ class MemoryTest(unittest.TestCase):
|
|||
|
||||
self.host.memory.reinit()
|
||||
# check successive updates (without intersection)
|
||||
self.host.memory.updateParams(self._getParamXML("1"))
|
||||
self.assertParamExists("1")
|
||||
self.assertParamNotExists("2")
|
||||
self.host.memory.updateParams(self._getParamXML("2"))
|
||||
self.assertParamExists("1")
|
||||
self.assertParamExists("2")
|
||||
self.host.memory.update_params(self._get_param_xml("1"))
|
||||
self.assert_param_exists("1")
|
||||
self.assert_param_not_exists("2")
|
||||
self.host.memory.update_params(self._get_param_xml("2"))
|
||||
self.assert_param_exists("1")
|
||||
self.assert_param_exists("2")
|
||||
|
||||
previous = self.host.memory.params.dom.cloneNode(True) # save for later
|
||||
|
||||
self.host.memory.reinit()
|
||||
# check successive updates (with intersection)
|
||||
self.host.memory.updateParams(self._getParamXML("1"))
|
||||
self.assertParamExists("1")
|
||||
self.assertParamNotExists("2")
|
||||
self.host.memory.updateParams(self._getParamXML("12"))
|
||||
self.assertParamExists("1")
|
||||
self.assertParamExists("2")
|
||||
self.host.memory.update_params(self._get_param_xml("1"))
|
||||
self.assert_param_exists("1")
|
||||
self.assert_param_not_exists("2")
|
||||
self.host.memory.update_params(self._get_param_xml("12"))
|
||||
self.assert_param_exists("1")
|
||||
self.assert_param_exists("2")
|
||||
|
||||
# successive updates with or without intersection should have the same result
|
||||
self.assertEqual(
|
||||
|
|
@ -189,125 +189,125 @@ class MemoryTest(unittest.TestCase):
|
|||
|
||||
self.host.memory.reinit()
|
||||
# one update with two params in a new category
|
||||
self.host.memory.updateParams(self._getParamXML("12"))
|
||||
self.assertParamExists("1")
|
||||
self.assertParamExists("2")
|
||||
self.host.memory.update_params(self._get_param_xml("12"))
|
||||
self.assert_param_exists("1")
|
||||
self.assert_param_exists("2")
|
||||
|
||||
def test_getParams(self):
|
||||
def test_get_params(self):
|
||||
# tests with no security level on the parameter (most secure)
|
||||
params = self._getParamXML()
|
||||
params = self._get_param_xml()
|
||||
self.host.memory.reinit()
|
||||
self.host.memory.updateParams(params)
|
||||
self._getParams(Const.NO_SECURITY_LIMIT).addCallback(self.assertParamExists_async)
|
||||
self._getParams(0).addCallback(self.assertParamNotExists_async)
|
||||
self._getParams(1).addCallback(self.assertParamNotExists_async)
|
||||
self.host.memory.update_params(params)
|
||||
self._get_params(Const.NO_SECURITY_LIMIT).addCallback(self.assert_param_exists_async)
|
||||
self._get_params(0).addCallback(self.assert_param_not_exists_async)
|
||||
self._get_params(1).addCallback(self.assert_param_not_exists_async)
|
||||
# tests with security level 0 on the parameter (not secure)
|
||||
params = self._getParamXML(security_level=0)
|
||||
params = self._get_param_xml(security_level=0)
|
||||
self.host.memory.reinit()
|
||||
self.host.memory.updateParams(params)
|
||||
self._getParams(Const.NO_SECURITY_LIMIT).addCallback(self.assertParamExists_async)
|
||||
self._getParams(0).addCallback(self.assertParamExists_async)
|
||||
self._getParams(1).addCallback(self.assertParamExists_async)
|
||||
self.host.memory.update_params(params)
|
||||
self._get_params(Const.NO_SECURITY_LIMIT).addCallback(self.assert_param_exists_async)
|
||||
self._get_params(0).addCallback(self.assert_param_exists_async)
|
||||
self._get_params(1).addCallback(self.assert_param_exists_async)
|
||||
# tests with security level 1 on the parameter (more secure)
|
||||
params = self._getParamXML(security_level=1)
|
||||
params = self._get_param_xml(security_level=1)
|
||||
self.host.memory.reinit()
|
||||
self.host.memory.updateParams(params)
|
||||
self._getParams(Const.NO_SECURITY_LIMIT).addCallback(self.assertParamExists_async)
|
||||
self._getParams(0).addCallback(self.assertParamNotExists_async)
|
||||
return self._getParams(1).addCallback(self.assertParamExists_async)
|
||||
self.host.memory.update_params(params)
|
||||
self._get_params(Const.NO_SECURITY_LIMIT).addCallback(self.assert_param_exists_async)
|
||||
self._get_params(0).addCallback(self.assert_param_not_exists_async)
|
||||
return self._get_params(1).addCallback(self.assert_param_exists_async)
|
||||
|
||||
def test_paramsRegisterApp(self):
|
||||
def test_params_register_app(self):
|
||||
def register(xml, security_limit, app):
|
||||
"""
|
||||
@param xml: XML definition of the parameters to be added
|
||||
@param security_limit: -1 means no security, 0 is the maximum security then the higher the less secure
|
||||
@param app: name of the frontend registering the parameters
|
||||
"""
|
||||
helpers.muteLogging()
|
||||
self.host.memory.paramsRegisterApp(xml, security_limit, app)
|
||||
helpers.unmuteLogging()
|
||||
helpers.mute_logging()
|
||||
self.host.memory.params_register_app(xml, security_limit, app)
|
||||
helpers.unmute_logging()
|
||||
|
||||
# tests with no security level on the parameter (most secure)
|
||||
params = self._getParamXML()
|
||||
params = self._get_param_xml()
|
||||
self.host.memory.reinit()
|
||||
register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME)
|
||||
self.assertParamExists()
|
||||
self.assert_param_exists()
|
||||
self.host.memory.reinit()
|
||||
register(params, 0, Const.APP_NAME)
|
||||
self.assertParamNotExists()
|
||||
self.assert_param_not_exists()
|
||||
self.host.memory.reinit()
|
||||
register(params, 1, Const.APP_NAME)
|
||||
self.assertParamNotExists()
|
||||
self.assert_param_not_exists()
|
||||
|
||||
# tests with security level 0 on the parameter (not secure)
|
||||
params = self._getParamXML(security_level=0)
|
||||
params = self._get_param_xml(security_level=0)
|
||||
self.host.memory.reinit()
|
||||
register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME)
|
||||
self.assertParamExists()
|
||||
self.assert_param_exists()
|
||||
self.host.memory.reinit()
|
||||
register(params, 0, Const.APP_NAME)
|
||||
self.assertParamExists()
|
||||
self.assert_param_exists()
|
||||
self.host.memory.reinit()
|
||||
register(params, 1, Const.APP_NAME)
|
||||
self.assertParamExists()
|
||||
self.assert_param_exists()
|
||||
|
||||
# tests with security level 1 on the parameter (more secure)
|
||||
params = self._getParamXML(security_level=1)
|
||||
params = self._get_param_xml(security_level=1)
|
||||
self.host.memory.reinit()
|
||||
register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME)
|
||||
self.assertParamExists()
|
||||
self.assert_param_exists()
|
||||
self.host.memory.reinit()
|
||||
register(params, 0, Const.APP_NAME)
|
||||
self.assertParamNotExists()
|
||||
self.assert_param_not_exists()
|
||||
self.host.memory.reinit()
|
||||
register(params, 1, Const.APP_NAME)
|
||||
self.assertParamExists()
|
||||
self.assert_param_exists()
|
||||
|
||||
# tests with security level 1 and several parameters being registered
|
||||
params = self._getParamXML("12", security_level=1)
|
||||
params = self._get_param_xml("12", security_level=1)
|
||||
self.host.memory.reinit()
|
||||
register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME)
|
||||
self.assertParamExists()
|
||||
self.assertParamExists("2")
|
||||
self.assert_param_exists()
|
||||
self.assert_param_exists("2")
|
||||
self.host.memory.reinit()
|
||||
register(params, 0, Const.APP_NAME)
|
||||
self.assertParamNotExists()
|
||||
self.assertParamNotExists("2")
|
||||
self.assert_param_not_exists()
|
||||
self.assert_param_not_exists("2")
|
||||
self.host.memory.reinit()
|
||||
register(params, 1, Const.APP_NAME)
|
||||
self.assertParamExists()
|
||||
self.assertParamExists("2")
|
||||
self.assert_param_exists()
|
||||
self.assert_param_exists("2")
|
||||
|
||||
# tests with several parameters being registered in an existing category
|
||||
self.host.memory.reinit()
|
||||
self.host.memory.updateParams(self._getParamXML("3"))
|
||||
register(self._getParamXML("12"), Const.NO_SECURITY_LIMIT, Const.APP_NAME)
|
||||
self.assertParamExists()
|
||||
self.assertParamExists("2")
|
||||
self.host.memory.update_params(self._get_param_xml("3"))
|
||||
register(self._get_param_xml("12"), Const.NO_SECURITY_LIMIT, Const.APP_NAME)
|
||||
self.assert_param_exists()
|
||||
self.assert_param_exists("2")
|
||||
self.host.memory.reinit()
|
||||
|
||||
def test_paramsRegisterApp_getParams(self):
|
||||
def test_params_register_app_get_params(self):
|
||||
# test retrieving the parameter for a specific frontend
|
||||
self.host.memory.reinit()
|
||||
params = self._getParamXML(security_level=1)
|
||||
self.host.memory.paramsRegisterApp(params, 1, Const.APP_NAME)
|
||||
self._getParams(1, "").addCallback(self.assertParamExists_async)
|
||||
self._getParams(1, Const.APP_NAME).addCallback(self.assertParamExists_async)
|
||||
self._getParams(1, "another_dummy_frontend").addCallback(
|
||||
self.assertParamNotExists_async
|
||||
params = self._get_param_xml(security_level=1)
|
||||
self.host.memory.params_register_app(params, 1, Const.APP_NAME)
|
||||
self._get_params(1, "").addCallback(self.assert_param_exists_async)
|
||||
self._get_params(1, Const.APP_NAME).addCallback(self.assert_param_exists_async)
|
||||
self._get_params(1, "another_dummy_frontend").addCallback(
|
||||
self.assert_param_not_exists_async
|
||||
)
|
||||
|
||||
# the same with several parameters registered at the same time
|
||||
self.host.memory.reinit()
|
||||
params = self._getParamXML("12", security_level=0)
|
||||
self.host.memory.paramsRegisterApp(params, 5, Const.APP_NAME)
|
||||
self._getParams(5, "").addCallback(self.assertParamExists_async)
|
||||
self._getParams(5, "").addCallback(self.assertParamExists_async, "2")
|
||||
self._getParams(5, Const.APP_NAME).addCallback(self.assertParamExists_async)
|
||||
self._getParams(5, Const.APP_NAME).addCallback(self.assertParamExists_async, "2")
|
||||
self._getParams(5, "another_dummy_frontend").addCallback(
|
||||
self.assertParamNotExists_async
|
||||
params = self._get_param_xml("12", security_level=0)
|
||||
self.host.memory.params_register_app(params, 5, Const.APP_NAME)
|
||||
self._get_params(5, "").addCallback(self.assert_param_exists_async)
|
||||
self._get_params(5, "").addCallback(self.assert_param_exists_async, "2")
|
||||
self._get_params(5, Const.APP_NAME).addCallback(self.assert_param_exists_async)
|
||||
self._get_params(5, Const.APP_NAME).addCallback(self.assert_param_exists_async, "2")
|
||||
self._get_params(5, "another_dummy_frontend").addCallback(
|
||||
self.assert_param_not_exists_async
|
||||
)
|
||||
return self._getParams(5, "another_dummy_frontend").addCallback(
|
||||
self.assertParamNotExists_async, "2"
|
||||
return self._get_params(5, "another_dummy_frontend").addCallback(
|
||||
self.assert_param_not_exists_async, "2"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ import string
|
|||
from twisted.internet import defer
|
||||
|
||||
|
||||
def getRandomUnicode(len):
|
||||
def get_random_unicode(len):
|
||||
"""Return a random unicode string"""
|
||||
return "".join(random.choice(string.letters + "éáúóâêûôßüöä") for i in range(len))
|
||||
|
||||
|
|
@ -47,9 +47,9 @@ class CryptoTest(helpers.SatTestCase):
|
|||
d_list.append(d)
|
||||
|
||||
for key_len in (0, 2, 8, 10, 16, 24, 30, 32, 40):
|
||||
key = getRandomUnicode(key_len)
|
||||
key = get_random_unicode(key_len)
|
||||
for message_len in (0, 2, 16, 24, 32, 100):
|
||||
message = getRandomUnicode(message_len)
|
||||
message = get_random_unicode(message_len)
|
||||
test(key, message)
|
||||
return defer.DeferredList(d_list)
|
||||
|
||||
|
|
@ -62,7 +62,7 @@ class CryptoTest(helpers.SatTestCase):
|
|||
d1 = PasswordHasher.verify(password, hashed)
|
||||
d1.addCallback(lambda result: self.assertTrue(result))
|
||||
d_list.append(d1)
|
||||
attempt = getRandomUnicode(10)
|
||||
attempt = get_random_unicode(10)
|
||||
d2 = PasswordHasher.verify(attempt, hashed)
|
||||
d2.addCallback(lambda result: self.assertFalse(result))
|
||||
d_list.append(d2)
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@ class XEP_groupblogTest(helpers.SatTestCase):
|
|||
|
||||
def _initialise(self, profile_key):
|
||||
profile = profile_key
|
||||
client = self.host.getClient(profile)
|
||||
client = self.host.get_client(profile)
|
||||
if not self.__initialised:
|
||||
client.item_access_pubsub = jid.JID(SERVICE)
|
||||
xep_0060 = self.host.plugins["XEP-0060"]
|
||||
|
|
@ -176,15 +176,15 @@ class XEP_groupblogTest(helpers.SatTestCase):
|
|||
)
|
||||
client.pubsub_client.parent = client
|
||||
self.psclient = client.pubsub_client
|
||||
helpers.FakeSAT.getDiscoItems = self.psclient.service_getDiscoItems
|
||||
helpers.FakeSAT.getDiscoItems = self.psclient.service_get_disco_items
|
||||
self.__initialised = True
|
||||
return defer.succeed((profile, client))
|
||||
|
||||
def _addItem(self, profile, item, parent_node=None):
|
||||
client = self.host.getClient(profile)
|
||||
client.pubsub_client._addItem(item, parent_node)
|
||||
def _add_item(self, profile, item, parent_node=None):
|
||||
client = self.host.get_client(profile)
|
||||
client.pubsub_client._add_item(item, parent_node)
|
||||
|
||||
def test_sendGroupBlog(self):
|
||||
def test_send_group_blog(self):
|
||||
self._initialise(C.PROFILE[0])
|
||||
d = self.psclient.items(SERVICE, NODE_ID)
|
||||
d.addCallback(lambda items: self.assertEqual(len(items), 0))
|
||||
|
|
@ -196,9 +196,9 @@ class XEP_groupblogTest(helpers.SatTestCase):
|
|||
d.addCallback(lambda __: self.psclient.items(SERVICE, NODE_ID))
|
||||
return d.addCallback(lambda items: self.assertEqual(len(items), 1))
|
||||
|
||||
def test_deleteGroupBlog(self):
|
||||
def test_delete_group_blog(self):
|
||||
pub_data = (SERVICE, NODE_ID, ITEM_ID_1)
|
||||
self.host.bridge.expectCall(
|
||||
self.host.bridge.expect_call(
|
||||
"personalEvent",
|
||||
C.JID_STR[0],
|
||||
"MICROBLOG_DELETE",
|
||||
|
|
@ -214,7 +214,7 @@ class XEP_groupblogTest(helpers.SatTestCase):
|
|||
)
|
||||
return d.addCallback(self.assertEqual, None)
|
||||
|
||||
def test_updateGroupBlog(self):
|
||||
def test_update_group_blog(self):
|
||||
pub_data = (SERVICE, NODE_ID, ITEM_ID_1)
|
||||
new_text = "silfu23RFWUP)IWNOEIOEFÖ"
|
||||
|
||||
|
|
@ -232,7 +232,7 @@ class XEP_groupblogTest(helpers.SatTestCase):
|
|||
)
|
||||
)
|
||||
|
||||
def test_sendGroupBlogComment(self):
|
||||
def test_send_group_blog_comment(self):
|
||||
self._initialise(C.PROFILE[0])
|
||||
d = self.psclient.items(SERVICE, NODE_ID)
|
||||
d.addCallback(lambda items: self.assertEqual(len(items), 0))
|
||||
|
|
@ -244,7 +244,7 @@ class XEP_groupblogTest(helpers.SatTestCase):
|
|||
d.addCallback(lambda __: self.psclient.items(SERVICE, COMMENTS_NODE_ID_1))
|
||||
return d.addCallback(lambda items: self.assertEqual(len(items), 1))
|
||||
|
||||
def test_getGroupBlogs(self):
|
||||
def test_get_group_blogs(self):
|
||||
self._initialise(C.PROFILE[0])
|
||||
d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1])
|
||||
d.addCallback(
|
||||
|
|
@ -256,7 +256,7 @@ class XEP_groupblogTest(helpers.SatTestCase):
|
|||
)
|
||||
return d.addCallback(self.assertEqual, result)
|
||||
|
||||
def test_getGroupBlogsNoCount(self):
|
||||
def test_get_group_blogs_no_count(self):
|
||||
self._initialise(C.PROFILE[0])
|
||||
d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1])
|
||||
d.addCallback(
|
||||
|
|
@ -270,7 +270,7 @@ class XEP_groupblogTest(helpers.SatTestCase):
|
|||
)
|
||||
return d.addCallback(self.assertEqual, result)
|
||||
|
||||
def test_getGroupBlogsWithIDs(self):
|
||||
def test_get_group_blogs_with_i_ds(self):
|
||||
self._initialise(C.PROFILE[0])
|
||||
d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1])
|
||||
d.addCallback(
|
||||
|
|
@ -284,7 +284,7 @@ class XEP_groupblogTest(helpers.SatTestCase):
|
|||
)
|
||||
return d.addCallback(self.assertEqual, result)
|
||||
|
||||
def test_getGroupBlogsWithRSM(self):
|
||||
def test_get_group_blogs_with_rsm(self):
|
||||
self._initialise(C.PROFILE[0])
|
||||
d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1])
|
||||
d.addCallback(
|
||||
|
|
@ -298,7 +298,7 @@ class XEP_groupblogTest(helpers.SatTestCase):
|
|||
)
|
||||
return d.addCallback(self.assertEqual, result)
|
||||
|
||||
def test_getGroupBlogsWithComments(self):
|
||||
def test_get_group_blogs_with_comments(self):
|
||||
self._initialise(C.PROFILE[0])
|
||||
d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1])
|
||||
d.addCallback(
|
||||
|
|
@ -328,7 +328,7 @@ class XEP_groupblogTest(helpers.SatTestCase):
|
|||
)
|
||||
return d.addCallback(self.assertEqual, result)
|
||||
|
||||
def test_getGroupBlogsWithComments2(self):
|
||||
def test_get_group_blogs_with_comments_2(self):
|
||||
self._initialise(C.PROFILE[0])
|
||||
d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1])
|
||||
d.addCallback(
|
||||
|
|
@ -361,7 +361,7 @@ class XEP_groupblogTest(helpers.SatTestCase):
|
|||
|
||||
return d.addCallback(self.assertEqual, result)
|
||||
|
||||
def test_getGroupBlogsAtom(self):
|
||||
def test_get_group_blogs_atom(self):
|
||||
self._initialise(C.PROFILE[0])
|
||||
d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1])
|
||||
d.addCallback(
|
||||
|
|
@ -376,7 +376,7 @@ class XEP_groupblogTest(helpers.SatTestCase):
|
|||
|
||||
return d.addCallback(cb)
|
||||
|
||||
def test_getMassiveGroupBlogs(self):
|
||||
def test_get_massive_group_blogs(self):
|
||||
self._initialise(C.PROFILE[0])
|
||||
d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1])
|
||||
d.addCallback(
|
||||
|
|
@ -400,7 +400,7 @@ class XEP_groupblogTest(helpers.SatTestCase):
|
|||
d.addCallback(clean)
|
||||
d.addCallback(self.assertEqual, result)
|
||||
|
||||
def test_getMassiveGroupBlogsWithComments(self):
|
||||
def test_get_massive_group_blogs_with_comments(self):
|
||||
self._initialise(C.PROFILE[0])
|
||||
d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1])
|
||||
d.addCallback(
|
||||
|
|
@ -429,7 +429,7 @@ class XEP_groupblogTest(helpers.SatTestCase):
|
|||
d.addCallback(clean)
|
||||
d.addCallback(self.assertEqual, result)
|
||||
|
||||
def test_getGroupBlogComments(self):
|
||||
def test_get_group_blog_comments(self):
|
||||
self._initialise(C.PROFILE[0])
|
||||
d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1])
|
||||
d.addCallback(
|
||||
|
|
@ -446,12 +446,12 @@ class XEP_groupblogTest(helpers.SatTestCase):
|
|||
)
|
||||
return d.addCallback(self.assertEqual, result)
|
||||
|
||||
def test_subscribeGroupBlog(self):
|
||||
def test_subscribe_group_blog(self):
|
||||
self._initialise(C.PROFILE[0])
|
||||
d = self.plugin.subscribeGroupBlog(PUBLISHER, profile_key=C.PROFILE[0])
|
||||
return d.addCallback(self.assertEqual, None)
|
||||
|
||||
def test_massiveSubscribeGroupBlogs(self):
|
||||
def test_massive_subscribe_group_blogs(self):
|
||||
self._initialise(C.PROFILE[0])
|
||||
d = self.plugin.massiveSubscribeGroupBlogs(
|
||||
"JID", [jid.JID(PUBLISHER)], profile_key=C.PROFILE[0]
|
||||
|
|
@ -469,10 +469,10 @@ class XEP_groupblogTest(helpers.SatTestCase):
|
|||
d.addCallback(clean)
|
||||
return d.addCallback(self.assertEqual, None)
|
||||
|
||||
def test_deleteAllGroupBlogs(self):
|
||||
def test_delete_all_group_blogs(self):
|
||||
"""Delete our main node and associated comments node"""
|
||||
self._initialise(C.PROFILE[0])
|
||||
self.host.profiles[C.PROFILE[0]].roster.addItem(jid.JID(OTHER_PUBLISHER))
|
||||
self.host.profiles[C.PROFILE[0]].roster.add_item(jid.JID(OTHER_PUBLISHER))
|
||||
d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1])
|
||||
d.addCallback(
|
||||
lambda __: self.psclient.publish(
|
||||
|
|
@ -517,10 +517,10 @@ class XEP_groupblogTest(helpers.SatTestCase):
|
|||
d.addCallback(lambda items: self.assertEqual(len(items), 2))
|
||||
return d
|
||||
|
||||
def test_deleteAllGroupBlogsComments(self):
|
||||
def test_delete_all_group_blogs_comments(self):
|
||||
"""Delete the comments we posted on other node's"""
|
||||
self._initialise(C.PROFILE[0])
|
||||
self.host.profiles[C.PROFILE[0]].roster.addItem(jid.JID(OTHER_PUBLISHER))
|
||||
self.host.profiles[C.PROFILE[0]].roster.add_item(jid.JID(OTHER_PUBLISHER))
|
||||
d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1])
|
||||
d.addCallback(
|
||||
lambda __: self.psclient.publish(
|
||||
|
|
@ -565,9 +565,9 @@ class XEP_groupblogTest(helpers.SatTestCase):
|
|||
d.addCallback(lambda items: self.assertEqual(len(items), 0))
|
||||
return d
|
||||
|
||||
def test_deleteAllGroupBlogsAndComments(self):
|
||||
def test_delete_all_group_blogs_and_comments(self):
|
||||
self._initialise(C.PROFILE[0])
|
||||
self.host.profiles[C.PROFILE[0]].roster.addItem(jid.JID(OTHER_PUBLISHER))
|
||||
self.host.profiles[C.PROFILE[0]].roster.add_item(jid.JID(OTHER_PUBLISHER))
|
||||
d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1])
|
||||
d.addCallback(
|
||||
lambda __: self.psclient.publish(
|
||||
|
|
|
|||
|
|
@ -73,10 +73,10 @@ class RadiocolTest(helpers.SatTestCase):
|
|||
self.host
|
||||
)
|
||||
for profile in Const.PROFILE:
|
||||
self.host.getClient(profile) # init self.host.profiles[profile]
|
||||
self.host.get_client(profile) # init self.host.profiles[profile]
|
||||
self.songs = []
|
||||
self.playlist = []
|
||||
self.sound_dir = self.host.memory.getConfig("", "media_dir") + "/test/sound/"
|
||||
self.sound_dir = self.host.memory.config_get("", "media_dir") + "/test/sound/"
|
||||
try:
|
||||
for filename in os.listdir(self.sound_dir):
|
||||
if filename.endswith(".ogg") or filename.endswith(".mp3"):
|
||||
|
|
@ -84,7 +84,7 @@ class RadiocolTest(helpers.SatTestCase):
|
|||
except OSError:
|
||||
raise SkipTest("The sound samples in sat_media/test/sound were not found")
|
||||
|
||||
def _buildPlayers(self, players=[]):
|
||||
def _build_players(self, players=[]):
|
||||
"""@return: the "started" content built with the given players"""
|
||||
content = "<started"
|
||||
if not players:
|
||||
|
|
@ -96,7 +96,7 @@ class RadiocolTest(helpers.SatTestCase):
|
|||
content += "</started>"
|
||||
return content
|
||||
|
||||
def _expectedMessage(self, to_jid, type_, content):
|
||||
def _expected_message(self, to_jid, type_, content):
|
||||
"""
|
||||
@param to_jid: recipient full jid
|
||||
@param type_: message type ('normal' or 'groupchat')
|
||||
|
|
@ -118,56 +118,56 @@ class RadiocolTest(helpers.SatTestCase):
|
|||
plugin.RADIOC_TAG,
|
||||
)
|
||||
|
||||
def _rejectSongCb(self, profile_index):
|
||||
def _reject_song_cb(self, profile_index):
|
||||
"""Check if the message "song_rejected" has been sent by the referee
|
||||
and process the command with the profile of the uploader
|
||||
@param profile_index: uploader's profile"""
|
||||
sent = self.host.getSentMessage(0)
|
||||
sent = self.host.get_sent_message(0)
|
||||
content = "<song_rejected xmlns='' reason='Too many songs in queue'/>"
|
||||
self.assertEqualXML(
|
||||
self.assert_equal_xml(
|
||||
sent.toXml(),
|
||||
self._expectedMessage(
|
||||
self._expected_message(
|
||||
JID(
|
||||
ROOM_JID.userhost()
|
||||
+ "/"
|
||||
+ self.plugin_0045.getNick(0, profile_index),
|
||||
+ self.plugin_0045.get_nick(0, profile_index),
|
||||
"normal",
|
||||
content,
|
||||
)
|
||||
),
|
||||
)
|
||||
self._roomGameCmd(
|
||||
sent, ["radiocolSongRejected", ROOM_JID.full(), "Too many songs in queue"]
|
||||
self._room_game_cmd(
|
||||
sent, ["radiocol_song_rejected", ROOM_JID.full(), "Too many songs in queue"]
|
||||
)
|
||||
|
||||
def _noUploadCb(self):
|
||||
def _no_upload_cb(self):
|
||||
"""Check if the message "no_upload" has been sent by the referee
|
||||
and process the command with the profiles of each room users"""
|
||||
sent = self.host.getSentMessage(0)
|
||||
sent = self.host.get_sent_message(0)
|
||||
content = "<no_upload xmlns=''/>"
|
||||
self.assertEqualXML(
|
||||
sent.toXml(), self._expectedMessage(ROOM_JID, "groupchat", content)
|
||||
self.assert_equal_xml(
|
||||
sent.toXml(), self._expected_message(ROOM_JID, "groupchat", content)
|
||||
)
|
||||
self._roomGameCmd(sent, ["radiocolNoUpload", ROOM_JID.full()])
|
||||
self._room_game_cmd(sent, ["radiocol_no_upload", ROOM_JID.full()])
|
||||
|
||||
def _uploadOkCb(self):
|
||||
def _upload_ok_cb(self):
|
||||
"""Check if the message "upload_ok" has been sent by the referee
|
||||
and process the command with the profiles of each room users"""
|
||||
sent = self.host.getSentMessage(0)
|
||||
sent = self.host.get_sent_message(0)
|
||||
content = "<upload_ok xmlns=''/>"
|
||||
self.assertEqualXML(
|
||||
sent.toXml(), self._expectedMessage(ROOM_JID, "groupchat", content)
|
||||
self.assert_equal_xml(
|
||||
sent.toXml(), self._expected_message(ROOM_JID, "groupchat", content)
|
||||
)
|
||||
self._roomGameCmd(sent, ["radiocolUploadOk", ROOM_JID.full()])
|
||||
self._room_game_cmd(sent, ["radiocol_upload_ok", ROOM_JID.full()])
|
||||
|
||||
def _preloadCb(self, attrs, profile_index):
|
||||
def _preload_cb(self, attrs, profile_index):
|
||||
"""Check if the message "preload" has been sent by the referee
|
||||
and process the command with the profiles of each room users
|
||||
@param attrs: information dict about the song
|
||||
@param profile_index: profile index of the uploader
|
||||
"""
|
||||
sent = self.host.getSentMessage(0)
|
||||
attrs["sender"] = self.plugin_0045.getNick(0, profile_index)
|
||||
sent = self.host.get_sent_message(0)
|
||||
attrs["sender"] = self.plugin_0045.get_nick(0, profile_index)
|
||||
radiocol_elt = next(domish.generateElementsNamed(sent.elements(), "radiocol"))
|
||||
preload_elt = next(domish.generateElementsNamed(
|
||||
radiocol_elt.elements(), "preload"
|
||||
|
|
@ -178,13 +178,13 @@ class RadiocolTest(helpers.SatTestCase):
|
|||
)
|
||||
if sent.hasAttribute("from"):
|
||||
del sent["from"]
|
||||
self.assertEqualXML(
|
||||
sent.toXml(), self._expectedMessage(ROOM_JID, "groupchat", content)
|
||||
self.assert_equal_xml(
|
||||
sent.toXml(), self._expected_message(ROOM_JID, "groupchat", content)
|
||||
)
|
||||
self._roomGameCmd(
|
||||
self._room_game_cmd(
|
||||
sent,
|
||||
[
|
||||
"radiocolPreload",
|
||||
"radiocol_preload",
|
||||
ROOM_JID.full(),
|
||||
attrs["timestamp"],
|
||||
attrs["filename"],
|
||||
|
|
@ -195,25 +195,25 @@ class RadiocolTest(helpers.SatTestCase):
|
|||
],
|
||||
)
|
||||
|
||||
def _playNextSongCb(self):
|
||||
def _play_next_song_cb(self):
|
||||
"""Check if the message "play" has been sent by the referee
|
||||
and process the command with the profiles of each room users"""
|
||||
sent = self.host.getSentMessage(0)
|
||||
sent = self.host.get_sent_message(0)
|
||||
filename = self.playlist.pop(0)
|
||||
content = "<play xmlns='' filename='%s' />" % filename
|
||||
self.assertEqualXML(
|
||||
sent.toXml(), self._expectedMessage(ROOM_JID, "groupchat", content)
|
||||
self.assert_equal_xml(
|
||||
sent.toXml(), self._expected_message(ROOM_JID, "groupchat", content)
|
||||
)
|
||||
self._roomGameCmd(sent, ["radiocolPlay", ROOM_JID.full(), filename])
|
||||
self._room_game_cmd(sent, ["radiocol_play", ROOM_JID.full(), filename])
|
||||
|
||||
game_data = self.plugin.games[ROOM_JID]
|
||||
if len(game_data["queue"]) == plugin.QUEUE_LIMIT - 1:
|
||||
self._uploadOkCb()
|
||||
self._upload_ok_cb()
|
||||
|
||||
def _addSongCb(self, d, filepath, profile_index):
|
||||
def _add_song_cb(self, d, filepath, profile_index):
|
||||
"""Check if the message "song_added" has been sent by the uploader
|
||||
and process the command with the profile of the referee
|
||||
@param d: deferred value or failure got from self.plugin.radiocolSongAdded
|
||||
@param d: deferred value or failure got from self.plugin.radiocol_song_added
|
||||
@param filepath: full path to the sound file
|
||||
@param profile_index: the profile index of the uploader
|
||||
"""
|
||||
|
|
@ -250,9 +250,9 @@ class RadiocolTest(helpers.SatTestCase):
|
|||
content = "<song_added xmlns='' %s/>" % " ".join(
|
||||
["%s='%s'" % (attr, attrs[attr]) for attr in attrs]
|
||||
)
|
||||
sent = self.host.getSentMessage(profile_index)
|
||||
self.assertEqualXML(
|
||||
sent.toXml(), self._expectedMessage(REFEREE_FULL, "normal", content)
|
||||
sent = self.host.get_sent_message(profile_index)
|
||||
self.assert_equal_xml(
|
||||
sent.toXml(), self._expected_message(REFEREE_FULL, "normal", content)
|
||||
)
|
||||
|
||||
reject_song = len(game_data["queue"]) >= plugin.QUEUE_LIMIT
|
||||
|
|
@ -262,20 +262,20 @@ class RadiocolTest(helpers.SatTestCase):
|
|||
and len(game_data["queue"]) + 1 == plugin.QUEUE_TO_START
|
||||
)
|
||||
|
||||
self._roomGameCmd(sent, profile_index) # queue unchanged or +1
|
||||
self._room_game_cmd(sent, profile_index) # queue unchanged or +1
|
||||
if reject_song:
|
||||
self._rejectSongCb(profile_index)
|
||||
self._reject_song_cb(profile_index)
|
||||
return
|
||||
if no_upload:
|
||||
self._noUploadCb()
|
||||
self._preloadCb(attrs, profile_index)
|
||||
self._no_upload_cb()
|
||||
self._preload_cb(attrs, profile_index)
|
||||
self.playlist.append(attrs["filename"])
|
||||
if play_next:
|
||||
self._playNextSongCb() # queue -1
|
||||
self._play_next_song_cb() # queue -1
|
||||
|
||||
def _roomGameCmd(self, sent, from_index=0, call=[]):
|
||||
def _room_game_cmd(self, sent, from_index=0, call=[]):
|
||||
"""Process a command. It is also possible to call this method as
|
||||
_roomGameCmd(sent, call) instead of _roomGameCmd(sent, from_index, call).
|
||||
_room_game_cmd(sent, call) instead of _room_game_cmd(sent, from_index, call).
|
||||
If from index is a list, it is assumed that it is containing the value
|
||||
for call and from_index will take its default value.
|
||||
@param sent: the sent message that we need to process
|
||||
|
|
@ -287,14 +287,14 @@ class RadiocolTest(helpers.SatTestCase):
|
|||
call = from_index
|
||||
from_index = 0
|
||||
|
||||
sent["from"] = ROOM_JID.full() + "/" + self.plugin_0045.getNick(0, from_index)
|
||||
sent["from"] = ROOM_JID.full() + "/" + self.plugin_0045.get_nick(0, from_index)
|
||||
recipient = JID(sent["to"]).resource
|
||||
|
||||
# The message could have been sent to a room user (room_jid + '/' + nick),
|
||||
# but when it is received, the 'to' attribute of the message has been
|
||||
# changed to the recipient own JID. We need to simulate that here.
|
||||
if recipient:
|
||||
room = self.plugin_0045.getRoom(0, 0)
|
||||
room = self.plugin_0045.get_room(0, 0)
|
||||
sent["to"] = (
|
||||
Const.JID_STR[0]
|
||||
if recipient == room.nick
|
||||
|
|
@ -302,33 +302,33 @@ class RadiocolTest(helpers.SatTestCase):
|
|||
)
|
||||
|
||||
for index in range(0, len(Const.PROFILE)):
|
||||
nick = self.plugin_0045.getNick(0, index)
|
||||
nick = self.plugin_0045.get_nick(0, index)
|
||||
if nick:
|
||||
if not recipient or nick == recipient:
|
||||
if call and (
|
||||
self.plugin.isPlayer(ROOM_JID, nick)
|
||||
or call[0] == "radiocolStarted"
|
||||
self.plugin.is_player(ROOM_JID, nick)
|
||||
or call[0] == "radiocol_started"
|
||||
):
|
||||
args = copy.deepcopy(call)
|
||||
args.append(Const.PROFILE[index])
|
||||
self.host.bridge.expectCall(*args)
|
||||
self.host.bridge.expect_call(*args)
|
||||
self.plugin.room_game_cmd(sent, Const.PROFILE[index])
|
||||
|
||||
def _syncCb(self, sync_data, profile_index):
|
||||
def _sync_cb(self, sync_data, profile_index):
|
||||
"""Synchronize one player when he joins a running game.
|
||||
@param sync_data: result from self.plugin.getSyncData
|
||||
@param profile_index: index of the profile to be synchronized
|
||||
"""
|
||||
for nick in sync_data:
|
||||
expected = self._expectedMessage(
|
||||
expected = self._expected_message(
|
||||
JID(ROOM_JID.userhost() + "/" + nick), "normal", sync_data[nick]
|
||||
)
|
||||
sent = self.host.getSentMessage(0)
|
||||
self.assertEqualXML(sent.toXml(), expected)
|
||||
sent = self.host.get_sent_message(0)
|
||||
self.assert_equal_xml(sent.toXml(), expected)
|
||||
for elt in sync_data[nick]:
|
||||
if elt.name == "preload":
|
||||
self.host.bridge.expectCall(
|
||||
"radiocolPreload",
|
||||
self.host.bridge.expect_call(
|
||||
"radiocol_preload",
|
||||
ROOM_JID.full(),
|
||||
elt["timestamp"],
|
||||
elt["filename"],
|
||||
|
|
@ -339,48 +339,48 @@ class RadiocolTest(helpers.SatTestCase):
|
|||
Const.PROFILE[profile_index],
|
||||
)
|
||||
elif elt.name == "play":
|
||||
self.host.bridge.expectCall(
|
||||
"radiocolPlay",
|
||||
self.host.bridge.expect_call(
|
||||
"radiocol_play",
|
||||
ROOM_JID.full(),
|
||||
elt["filename"],
|
||||
Const.PROFILE[profile_index],
|
||||
)
|
||||
elif elt.name == "no_upload":
|
||||
self.host.bridge.expectCall(
|
||||
"radiocolNoUpload", ROOM_JID.full(), Const.PROFILE[profile_index]
|
||||
self.host.bridge.expect_call(
|
||||
"radiocol_no_upload", ROOM_JID.full(), Const.PROFILE[profile_index]
|
||||
)
|
||||
sync_data[nick]
|
||||
self._roomGameCmd(sent, [])
|
||||
self._room_game_cmd(sent, [])
|
||||
|
||||
def _joinRoom(self, room, nicks, player_index, sync=True):
|
||||
def _join_room(self, room, nicks, player_index, sync=True):
|
||||
"""Make a player join a room and update the list of nicks
|
||||
@param room: wokkel.muc.Room instance from the referee perspective
|
||||
@param nicks: list of the players which will be updated
|
||||
@param player_index: profile index of the new player
|
||||
@param sync: set to True to synchronize data
|
||||
"""
|
||||
user_nick = self.plugin_0045.joinRoom(0, player_index)
|
||||
self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE)
|
||||
user_nick = self.plugin_0045.join_room(0, player_index)
|
||||
self.plugin.user_joined_trigger(room, room.roster[user_nick], PROFILE)
|
||||
if player_index not in PLAYERS_INDICES:
|
||||
# this user is actually not a player
|
||||
self.assertFalse(self.plugin.isPlayer(ROOM_JID, user_nick))
|
||||
self.assertFalse(self.plugin.is_player(ROOM_JID, user_nick))
|
||||
to_jid, type_ = (JID(ROOM_JID.userhost() + "/" + user_nick), "normal")
|
||||
else:
|
||||
# this user is a player
|
||||
self.assertTrue(self.plugin.isPlayer(ROOM_JID, user_nick))
|
||||
self.assertTrue(self.plugin.is_player(ROOM_JID, user_nick))
|
||||
nicks.append(user_nick)
|
||||
to_jid, type_ = (ROOM_JID, "groupchat")
|
||||
|
||||
# Check that the message "players" has been sent by the referee
|
||||
expected = self._expectedMessage(to_jid, type_, self._buildPlayers(nicks))
|
||||
sent = self.host.getSentMessage(0)
|
||||
self.assertEqualXML(sent.toXml(), expected)
|
||||
expected = self._expected_message(to_jid, type_, self._build_players(nicks))
|
||||
sent = self.host.get_sent_message(0)
|
||||
self.assert_equal_xml(sent.toXml(), expected)
|
||||
|
||||
# Process the command with the profiles of each room users
|
||||
self._roomGameCmd(
|
||||
self._room_game_cmd(
|
||||
sent,
|
||||
[
|
||||
"radiocolStarted",
|
||||
"radiocol_started",
|
||||
ROOM_JID.full(),
|
||||
REFEREE_FULL.full(),
|
||||
nicks,
|
||||
|
|
@ -389,21 +389,21 @@ class RadiocolTest(helpers.SatTestCase):
|
|||
)
|
||||
|
||||
if sync:
|
||||
self._syncCb(self.plugin._getSyncData(ROOM_JID, [user_nick]), player_index)
|
||||
self._sync_cb(self.plugin._get_sync_data(ROOM_JID, [user_nick]), player_index)
|
||||
|
||||
def _leaveRoom(self, room, nicks, player_index):
|
||||
def _leave_room(self, room, nicks, player_index):
|
||||
"""Make a player leave a room and update the list of nicks
|
||||
@param room: wokkel.muc.Room instance from the referee perspective
|
||||
@param nicks: list of the players which will be updated
|
||||
@param player_index: profile index of the new player
|
||||
"""
|
||||
user_nick = self.plugin_0045.getNick(0, player_index)
|
||||
user_nick = self.plugin_0045.get_nick(0, player_index)
|
||||
user = room.roster[user_nick]
|
||||
self.plugin_0045.leaveRoom(0, player_index)
|
||||
self.plugin.userLeftTrigger(room, user, PROFILE)
|
||||
self.plugin_0045.leave_room(0, player_index)
|
||||
self.plugin.user_left_trigger(room, user, PROFILE)
|
||||
nicks.remove(user_nick)
|
||||
|
||||
def _uploadSong(self, song_index, profile_index):
|
||||
def _upload_song(self, song_index, profile_index):
|
||||
"""Upload the song of index song_index (modulo self.songs size) from the profile of index profile_index.
|
||||
|
||||
@param song_index: index of the song or None to test with non existing file
|
||||
|
|
@ -420,7 +420,7 @@ class RadiocolTest(helpers.SatTestCase):
|
|||
expect_io_error = False
|
||||
|
||||
try:
|
||||
d = self.plugin.radiocolSongAdded(
|
||||
d = self.plugin.radiocol_song_added(
|
||||
REFEREE_FULL, dst_filepath, Const.PROFILE[profile_index]
|
||||
)
|
||||
except IOError:
|
||||
|
|
@ -428,7 +428,7 @@ class RadiocolTest(helpers.SatTestCase):
|
|||
return
|
||||
|
||||
self.assertFalse(expect_io_error)
|
||||
cb = lambda defer: self._addSongCb(defer, dst_filepath, profile_index)
|
||||
cb = lambda defer: self._add_song_cb(defer, dst_filepath, profile_index)
|
||||
|
||||
def eb(failure):
|
||||
if not isinstance(failure, Failure):
|
||||
|
|
@ -451,20 +451,20 @@ class RadiocolTest(helpers.SatTestCase):
|
|||
self.reinit()
|
||||
|
||||
# create game
|
||||
self.plugin.prepareRoom(OTHER_PLAYERS, ROOM_JID, PROFILE)
|
||||
self.assertTrue(self.plugin._gameExists(ROOM_JID, True))
|
||||
room = self.plugin_0045.getRoom(0, 0)
|
||||
nicks = [self.plugin_0045.getNick(0, 0)]
|
||||
self.plugin.prepare_room(OTHER_PLAYERS, ROOM_JID, PROFILE)
|
||||
self.assertTrue(self.plugin._game_exists(ROOM_JID, True))
|
||||
room = self.plugin_0045.get_room(0, 0)
|
||||
nicks = [self.plugin_0045.get_nick(0, 0)]
|
||||
|
||||
sent = self.host.getSentMessage(0)
|
||||
self.assertEqualXML(
|
||||
sent = self.host.get_sent_message(0)
|
||||
self.assert_equal_xml(
|
||||
sent.toXml(),
|
||||
self._expectedMessage(ROOM_JID, "groupchat", self._buildPlayers(nicks)),
|
||||
self._expected_message(ROOM_JID, "groupchat", self._build_players(nicks)),
|
||||
)
|
||||
self._roomGameCmd(
|
||||
self._room_game_cmd(
|
||||
sent,
|
||||
[
|
||||
"radiocolStarted",
|
||||
"radiocol_started",
|
||||
ROOM_JID.full(),
|
||||
REFEREE_FULL.full(),
|
||||
nicks,
|
||||
|
|
@ -472,42 +472,42 @@ class RadiocolTest(helpers.SatTestCase):
|
|||
],
|
||||
)
|
||||
|
||||
self._joinRoom(room, nicks, 1) # player joins
|
||||
self._joinRoom(room, nicks, 4) # user not playing joins
|
||||
self._join_room(room, nicks, 1) # player joins
|
||||
self._join_room(room, nicks, 4) # user not playing joins
|
||||
|
||||
song_index = 0
|
||||
self._uploadSong(
|
||||
self._upload_song(
|
||||
song_index, 0
|
||||
) # ogg or mp3 file should exist in sat_media/test/song
|
||||
self._uploadSong(None, 0) # non existing file
|
||||
self._upload_song(None, 0) # non existing file
|
||||
|
||||
# another songs are added by Const.JID[1] until the radio starts + 1 to fill the queue
|
||||
# when the first song starts + 1 to be rejected because the queue is full
|
||||
for song_index in range(1, plugin.QUEUE_TO_START + 1):
|
||||
self._uploadSong(song_index, 1)
|
||||
self._upload_song(song_index, 1)
|
||||
|
||||
self.plugin.playNext(Const.MUC[0], PROFILE) # simulate the end of the first song
|
||||
self._playNextSongCb()
|
||||
self._uploadSong(
|
||||
self.plugin.play_next(Const.MUC[0], PROFILE) # simulate the end of the first song
|
||||
self._play_next_song_cb()
|
||||
self._upload_song(
|
||||
song_index, 1
|
||||
) # now the song is accepted and the queue is full again
|
||||
|
||||
self._joinRoom(room, nicks, 3) # new player joins
|
||||
self._join_room(room, nicks, 3) # new player joins
|
||||
|
||||
self.plugin.playNext(Const.MUC[0], PROFILE) # the second song finishes
|
||||
self._playNextSongCb()
|
||||
self._uploadSong(0, 3) # the player who recently joined re-upload the first file
|
||||
self.plugin.play_next(Const.MUC[0], PROFILE) # the second song finishes
|
||||
self._play_next_song_cb()
|
||||
self._upload_song(0, 3) # the player who recently joined re-upload the first file
|
||||
|
||||
self._leaveRoom(room, nicks, 1) # one player leaves
|
||||
self._joinRoom(room, nicks, 1) # and join again
|
||||
self._leave_room(room, nicks, 1) # one player leaves
|
||||
self._join_room(room, nicks, 1) # and join again
|
||||
|
||||
self.plugin.playNext(Const.MUC[0], PROFILE) # empty the queue
|
||||
self._playNextSongCb()
|
||||
self.plugin.playNext(Const.MUC[0], PROFILE)
|
||||
self._playNextSongCb()
|
||||
self.plugin.play_next(Const.MUC[0], PROFILE) # empty the queue
|
||||
self._play_next_song_cb()
|
||||
self.plugin.play_next(Const.MUC[0], PROFILE)
|
||||
self._play_next_song_cb()
|
||||
|
||||
for filename in self.playlist:
|
||||
self.plugin.deleteFile("/tmp/" + filename)
|
||||
self.plugin.delete_file("/tmp/" + filename)
|
||||
|
||||
return defer.succeed(None)
|
||||
|
||||
|
|
|
|||
|
|
@ -65,13 +65,13 @@ class RoomGameTest(helpers.SatTestCase):
|
|||
self.host
|
||||
)
|
||||
for profile in Const.PROFILE:
|
||||
self.host.getClient(profile) # init self.host.profiles[profile]
|
||||
self.host.get_client(profile) # init self.host.profiles[profile]
|
||||
|
||||
def initGame(self, muc_index, user_index):
|
||||
self.plugin_0045.joinRoom(user_index, muc_index)
|
||||
self.plugin._initGame(JID(Const.MUC_STR[muc_index]), Const.JID[user_index].user)
|
||||
def init_game(self, muc_index, user_index):
|
||||
self.plugin_0045.join_room(user_index, muc_index)
|
||||
self.plugin._init_game(JID(Const.MUC_STR[muc_index]), Const.JID[user_index].user)
|
||||
|
||||
def _expectedMessage(self, to, type_, tag, players=[]):
|
||||
def _expected_message(self, to, type_, tag, players=[]):
|
||||
content = "<%s" % tag
|
||||
if not players:
|
||||
content += "/>"
|
||||
|
|
@ -88,45 +88,45 @@ class RoomGameTest(helpers.SatTestCase):
|
|||
content,
|
||||
)
|
||||
|
||||
def test_createOrInvite_solo(self):
|
||||
def test_create_or_invite_solo(self):
|
||||
self.reinit()
|
||||
self.plugin_0045.joinRoom(0, 0)
|
||||
self.plugin._createOrInvite(self.plugin_0045.getRoom(0, 0), [], Const.PROFILE[0])
|
||||
self.assertTrue(self.plugin._gameExists(ROOM_JID, True))
|
||||
self.plugin_0045.join_room(0, 0)
|
||||
self.plugin._create_or_invite(self.plugin_0045.get_room(0, 0), [], Const.PROFILE[0])
|
||||
self.assertTrue(self.plugin._game_exists(ROOM_JID, True))
|
||||
|
||||
def test_createOrInvite_multi_not_waiting(self):
|
||||
def test_create_or_invite_multi_not_waiting(self):
|
||||
self.reinit()
|
||||
self.plugin_0045.joinRoom(0, 0)
|
||||
self.plugin_0045.join_room(0, 0)
|
||||
other_players = [Const.JID[1], Const.JID[2]]
|
||||
self.plugin._createOrInvite(
|
||||
self.plugin_0045.getRoom(0, 0), other_players, Const.PROFILE[0]
|
||||
self.plugin._create_or_invite(
|
||||
self.plugin_0045.get_room(0, 0), other_players, Const.PROFILE[0]
|
||||
)
|
||||
self.assertTrue(self.plugin._gameExists(ROOM_JID, True))
|
||||
self.assertTrue(self.plugin._game_exists(ROOM_JID, True))
|
||||
|
||||
def test_createOrInvite_multi_waiting(self):
|
||||
def test_create_or_invite_multi_waiting(self):
|
||||
self.reinit(player_init={"score": 0})
|
||||
self.plugin_0045.joinRoom(0, 0)
|
||||
self.plugin_0045.join_room(0, 0)
|
||||
other_players = [Const.JID[1], Const.JID[2]]
|
||||
self.plugin._createOrInvite(
|
||||
self.plugin_0045.getRoom(0, 0), other_players, Const.PROFILE[0]
|
||||
self.plugin._create_or_invite(
|
||||
self.plugin_0045.get_room(0, 0), other_players, Const.PROFILE[0]
|
||||
)
|
||||
self.assertTrue(self.plugin._gameExists(ROOM_JID, False))
|
||||
self.assertFalse(self.plugin._gameExists(ROOM_JID, True))
|
||||
self.assertTrue(self.plugin._game_exists(ROOM_JID, False))
|
||||
self.assertFalse(self.plugin._game_exists(ROOM_JID, True))
|
||||
|
||||
def test_initGame(self):
|
||||
def test_init_game(self):
|
||||
self.reinit()
|
||||
self.initGame(0, 0)
|
||||
self.assertTrue(self.plugin.isReferee(ROOM_JID, Const.JID[0].user))
|
||||
self.init_game(0, 0)
|
||||
self.assertTrue(self.plugin.is_referee(ROOM_JID, Const.JID[0].user))
|
||||
self.assertEqual([], self.plugin.games[ROOM_JID]["players"])
|
||||
|
||||
def test_checkJoinAuth(self):
|
||||
def test_check_join_auth(self):
|
||||
self.reinit()
|
||||
check = lambda value: getattr(self, "assert%s" % value)(
|
||||
self.plugin._checkJoinAuth(ROOM_JID, Const.JID[0], Const.JID[0].user)
|
||||
self.plugin._check_join_auth(ROOM_JID, Const.JID[0], Const.JID[0].user)
|
||||
)
|
||||
check(False)
|
||||
# to test the "invited" mode, the referee must be different than the user to test
|
||||
self.initGame(0, 1)
|
||||
self.init_game(0, 1)
|
||||
self.plugin.join_mode = self.plugin.ALL
|
||||
check(True)
|
||||
self.plugin.join_mode = self.plugin.INVITED
|
||||
|
|
@ -138,71 +138,71 @@ class RoomGameTest(helpers.SatTestCase):
|
|||
self.plugin.games[ROOM_JID]["players"].append(Const.JID[0].user)
|
||||
check(True)
|
||||
|
||||
def test_updatePlayers(self):
|
||||
def test_update_players(self):
|
||||
self.reinit()
|
||||
self.initGame(0, 0)
|
||||
self.init_game(0, 0)
|
||||
self.assertEqual(self.plugin.games[ROOM_JID]["players"], [])
|
||||
self.plugin._updatePlayers(ROOM_JID, [], True, Const.PROFILE[0])
|
||||
self.plugin._update_players(ROOM_JID, [], True, Const.PROFILE[0])
|
||||
self.assertEqual(self.plugin.games[ROOM_JID]["players"], [])
|
||||
self.plugin._updatePlayers(ROOM_JID, ["user1"], True, Const.PROFILE[0])
|
||||
self.plugin._update_players(ROOM_JID, ["user1"], True, Const.PROFILE[0])
|
||||
self.assertEqual(self.plugin.games[ROOM_JID]["players"], ["user1"])
|
||||
self.plugin._updatePlayers(ROOM_JID, ["user2", "user3"], True, Const.PROFILE[0])
|
||||
self.plugin._update_players(ROOM_JID, ["user2", "user3"], True, Const.PROFILE[0])
|
||||
self.assertEqual(
|
||||
self.plugin.games[ROOM_JID]["players"], ["user1", "user2", "user3"]
|
||||
)
|
||||
self.plugin._updatePlayers(
|
||||
self.plugin._update_players(
|
||||
ROOM_JID, ["user2", "user3"], True, Const.PROFILE[0]
|
||||
) # should not be stored twice
|
||||
self.assertEqual(
|
||||
self.plugin.games[ROOM_JID]["players"], ["user1", "user2", "user3"]
|
||||
)
|
||||
|
||||
def test_synchronizeRoom(self):
|
||||
def test_synchronize_room(self):
|
||||
self.reinit()
|
||||
self.initGame(0, 0)
|
||||
self.plugin._synchronizeRoom(ROOM_JID, [Const.MUC[0]], Const.PROFILE[0])
|
||||
self.init_game(0, 0)
|
||||
self.plugin._synchronize_room(ROOM_JID, [Const.MUC[0]], Const.PROFILE[0])
|
||||
self.assertEqual(
|
||||
self.host.getSentMessageXml(0),
|
||||
self._expectedMessage(ROOM_JID, "groupchat", "players", []),
|
||||
self.host.get_sent_message_xml(0),
|
||||
self._expected_message(ROOM_JID, "groupchat", "players", []),
|
||||
)
|
||||
self.plugin.games[ROOM_JID]["players"].append("test1")
|
||||
self.plugin._synchronizeRoom(ROOM_JID, [Const.MUC[0]], Const.PROFILE[0])
|
||||
self.plugin._synchronize_room(ROOM_JID, [Const.MUC[0]], Const.PROFILE[0])
|
||||
self.assertEqual(
|
||||
self.host.getSentMessageXml(0),
|
||||
self._expectedMessage(ROOM_JID, "groupchat", "players", ["test1"]),
|
||||
self.host.get_sent_message_xml(0),
|
||||
self._expected_message(ROOM_JID, "groupchat", "players", ["test1"]),
|
||||
)
|
||||
self.plugin.games[ROOM_JID]["started"] = True
|
||||
self.plugin.games[ROOM_JID]["players"].append("test2")
|
||||
self.plugin._synchronizeRoom(ROOM_JID, [Const.MUC[0]], Const.PROFILE[0])
|
||||
self.plugin._synchronize_room(ROOM_JID, [Const.MUC[0]], Const.PROFILE[0])
|
||||
self.assertEqual(
|
||||
self.host.getSentMessageXml(0),
|
||||
self._expectedMessage(ROOM_JID, "groupchat", "started", ["test1", "test2"]),
|
||||
self.host.get_sent_message_xml(0),
|
||||
self._expected_message(ROOM_JID, "groupchat", "started", ["test1", "test2"]),
|
||||
)
|
||||
self.plugin.games[ROOM_JID]["players"].append("test3")
|
||||
self.plugin.games[ROOM_JID]["players"].append("test4")
|
||||
user1 = JID(ROOM_JID.userhost() + "/" + Const.JID[0].user)
|
||||
user2 = JID(ROOM_JID.userhost() + "/" + Const.JID[1].user)
|
||||
self.plugin._synchronizeRoom(ROOM_JID, [user1, user2], Const.PROFILE[0])
|
||||
self.assertEqualXML(
|
||||
self.host.getSentMessageXml(0),
|
||||
self._expectedMessage(
|
||||
self.plugin._synchronize_room(ROOM_JID, [user1, user2], Const.PROFILE[0])
|
||||
self.assert_equal_xml(
|
||||
self.host.get_sent_message_xml(0),
|
||||
self._expected_message(
|
||||
user1, "normal", "started", ["test1", "test2", "test3", "test4"]
|
||||
),
|
||||
)
|
||||
self.assertEqualXML(
|
||||
self.host.getSentMessageXml(0),
|
||||
self._expectedMessage(
|
||||
self.assert_equal_xml(
|
||||
self.host.get_sent_message_xml(0),
|
||||
self._expected_message(
|
||||
user2, "normal", "started", ["test1", "test2", "test3", "test4"]
|
||||
),
|
||||
)
|
||||
|
||||
def test_invitePlayers(self):
|
||||
def test_invite_players(self):
|
||||
self.reinit()
|
||||
self.initGame(0, 0)
|
||||
self.plugin_0045.joinRoom(0, 1)
|
||||
self.init_game(0, 0)
|
||||
self.plugin_0045.join_room(0, 1)
|
||||
self.assertEqual(self.plugin.invitations[ROOM_JID], [])
|
||||
room = self.plugin_0045.getRoom(0, 0)
|
||||
nicks = self.plugin._invitePlayers(
|
||||
room = self.plugin_0045.get_room(0, 0)
|
||||
nicks = self.plugin._invite_players(
|
||||
room, [Const.JID[1], Const.JID[2]], Const.JID[0].user, Const.PROFILE[0]
|
||||
)
|
||||
self.assertEqual(
|
||||
|
|
@ -212,7 +212,7 @@ class RoomGameTest(helpers.SatTestCase):
|
|||
# the following assertion is True because Const.JID[1] and Const.JID[2] have the same userhost
|
||||
self.assertEqual(nicks, [Const.JID[1].user, Const.JID[2].user])
|
||||
|
||||
nicks = self.plugin._invitePlayers(
|
||||
nicks = self.plugin._invite_players(
|
||||
room, [Const.JID[1], Const.JID[3]], Const.JID[0].user, Const.PROFILE[0]
|
||||
)
|
||||
self.assertEqual(
|
||||
|
|
@ -222,11 +222,11 @@ class RoomGameTest(helpers.SatTestCase):
|
|||
# this time Const.JID[1] and Const.JID[3] have the same user but the host differs
|
||||
self.assertEqual(nicks, [Const.JID[1].user])
|
||||
|
||||
def test_checkInviteAuth(self):
|
||||
def test_check_invite_auth(self):
|
||||
def check(value, index):
|
||||
nick = self.plugin_0045.getNick(0, index)
|
||||
nick = self.plugin_0045.get_nick(0, index)
|
||||
getattr(self, "assert%s" % value)(
|
||||
self.plugin._checkInviteAuth(ROOM_JID, nick)
|
||||
self.plugin._check_invite_auth(ROOM_JID, nick)
|
||||
)
|
||||
|
||||
self.reinit()
|
||||
|
|
@ -240,7 +240,7 @@ class RoomGameTest(helpers.SatTestCase):
|
|||
self.plugin.invite_mode = mode
|
||||
check(True, 0)
|
||||
|
||||
self.initGame(0, 0)
|
||||
self.init_game(0, 0)
|
||||
self.plugin.invite_mode = self.plugin.FROM_ALL
|
||||
check(True, 0)
|
||||
check(True, 1)
|
||||
|
|
@ -250,37 +250,37 @@ class RoomGameTest(helpers.SatTestCase):
|
|||
self.plugin.invite_mode = self.plugin.FROM_REFEREE
|
||||
check(True, 0)
|
||||
check(False, 1)
|
||||
user_nick = self.plugin_0045.joinRoom(0, 1)
|
||||
user_nick = self.plugin_0045.join_room(0, 1)
|
||||
self.plugin.games[ROOM_JID]["players"].append(user_nick)
|
||||
self.plugin.invite_mode = self.plugin.FROM_PLAYERS
|
||||
check(True, 0)
|
||||
check(True, 1)
|
||||
check(False, 2)
|
||||
|
||||
def test_isReferee(self):
|
||||
def test_is_referee(self):
|
||||
self.reinit()
|
||||
self.initGame(0, 0)
|
||||
self.assertTrue(self.plugin.isReferee(ROOM_JID, self.plugin_0045.getNick(0, 0)))
|
||||
self.assertFalse(self.plugin.isReferee(ROOM_JID, self.plugin_0045.getNick(0, 1)))
|
||||
self.init_game(0, 0)
|
||||
self.assertTrue(self.plugin.is_referee(ROOM_JID, self.plugin_0045.get_nick(0, 0)))
|
||||
self.assertFalse(self.plugin.is_referee(ROOM_JID, self.plugin_0045.get_nick(0, 1)))
|
||||
|
||||
def test_isPlayer(self):
|
||||
def test_is_player(self):
|
||||
self.reinit()
|
||||
self.initGame(0, 0)
|
||||
self.assertTrue(self.plugin.isPlayer(ROOM_JID, self.plugin_0045.getNick(0, 0)))
|
||||
user_nick = self.plugin_0045.joinRoom(0, 1)
|
||||
self.init_game(0, 0)
|
||||
self.assertTrue(self.plugin.is_player(ROOM_JID, self.plugin_0045.get_nick(0, 0)))
|
||||
user_nick = self.plugin_0045.join_room(0, 1)
|
||||
self.plugin.games[ROOM_JID]["players"].append(user_nick)
|
||||
self.assertTrue(self.plugin.isPlayer(ROOM_JID, user_nick))
|
||||
self.assertFalse(self.plugin.isPlayer(ROOM_JID, self.plugin_0045.getNick(0, 2)))
|
||||
self.assertTrue(self.plugin.is_player(ROOM_JID, user_nick))
|
||||
self.assertFalse(self.plugin.is_player(ROOM_JID, self.plugin_0045.get_nick(0, 2)))
|
||||
|
||||
def test_checkWaitAuth(self):
|
||||
def test_check_wait_auth(self):
|
||||
def check(value, other_players, confirmed, rest):
|
||||
room = self.plugin_0045.getRoom(0, 0)
|
||||
room = self.plugin_0045.get_room(0, 0)
|
||||
self.assertEqual(
|
||||
(value, confirmed, rest), self.plugin._checkWaitAuth(room, other_players)
|
||||
(value, confirmed, rest), self.plugin._check_wait_auth(room, other_players)
|
||||
)
|
||||
|
||||
self.reinit()
|
||||
self.initGame(0, 0)
|
||||
self.init_game(0, 0)
|
||||
other_players = [Const.JID[1], Const.JID[3]]
|
||||
self.plugin.wait_mode = self.plugin.FOR_NONE
|
||||
check(True, [], [], [])
|
||||
|
|
@ -292,22 +292,22 @@ class RoomGameTest(helpers.SatTestCase):
|
|||
check(True, [], [], [])
|
||||
check(False, [Const.JID[0]], [], [Const.JID[0]])
|
||||
check(False, other_players, [], other_players)
|
||||
self.plugin_0045.joinRoom(0, 1)
|
||||
self.plugin_0045.join_room(0, 1)
|
||||
check(False, other_players, [], other_players)
|
||||
self.plugin_0045.joinRoom(0, 4)
|
||||
self.plugin_0045.join_room(0, 4)
|
||||
check(
|
||||
False,
|
||||
other_players,
|
||||
[self.plugin_0045.getNickOfUser(0, 1, 0)],
|
||||
[self.plugin_0045.get_nick_of_user(0, 1, 0)],
|
||||
[Const.JID[3]],
|
||||
)
|
||||
self.plugin_0045.joinRoom(0, 3)
|
||||
self.plugin_0045.join_room(0, 3)
|
||||
check(
|
||||
True,
|
||||
other_players,
|
||||
[
|
||||
self.plugin_0045.getNickOfUser(0, 1, 0),
|
||||
self.plugin_0045.getNickOfUser(0, 3, 0),
|
||||
self.plugin_0045.get_nick_of_user(0, 1, 0),
|
||||
self.plugin_0045.get_nick_of_user(0, 3, 0),
|
||||
],
|
||||
[],
|
||||
)
|
||||
|
|
@ -318,189 +318,189 @@ class RoomGameTest(helpers.SatTestCase):
|
|||
True,
|
||||
other_players,
|
||||
[
|
||||
self.plugin_0045.getNickOfUser(0, 1, 0),
|
||||
self.plugin_0045.getNickOfUser(0, 3, 0),
|
||||
self.plugin_0045.getNickOfUser(0, 2, 0),
|
||||
self.plugin_0045.get_nick_of_user(0, 1, 0),
|
||||
self.plugin_0045.get_nick_of_user(0, 3, 0),
|
||||
self.plugin_0045.get_nick_of_user(0, 2, 0),
|
||||
],
|
||||
[],
|
||||
)
|
||||
|
||||
def test_prepareRoom_trivial(self):
|
||||
def test_prepare_room_trivial(self):
|
||||
self.reinit()
|
||||
other_players = []
|
||||
self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE)
|
||||
self.assertTrue(self.plugin._gameExists(ROOM_JID, True))
|
||||
self.plugin.prepare_room(other_players, ROOM_JID, PROFILE)
|
||||
self.assertTrue(self.plugin._game_exists(ROOM_JID, True))
|
||||
self.assertTrue(
|
||||
self.plugin._checkJoinAuth(ROOM_JID, Const.JID[0], Const.JID[0].user)
|
||||
self.plugin._check_join_auth(ROOM_JID, Const.JID[0], Const.JID[0].user)
|
||||
)
|
||||
self.assertTrue(self.plugin._checkInviteAuth(ROOM_JID, Const.JID[0].user))
|
||||
self.assertEqual((True, [], []), self.plugin._checkWaitAuth(ROOM_JID, []))
|
||||
self.assertTrue(self.plugin.isReferee(ROOM_JID, Const.JID[0].user))
|
||||
self.assertTrue(self.plugin.isPlayer(ROOM_JID, Const.JID[0].user))
|
||||
self.assertTrue(self.plugin._check_invite_auth(ROOM_JID, Const.JID[0].user))
|
||||
self.assertEqual((True, [], []), self.plugin._check_wait_auth(ROOM_JID, []))
|
||||
self.assertTrue(self.plugin.is_referee(ROOM_JID, Const.JID[0].user))
|
||||
self.assertTrue(self.plugin.is_player(ROOM_JID, Const.JID[0].user))
|
||||
self.assertEqual(
|
||||
(False, True), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE)
|
||||
(False, True), self.plugin._check_create_game_and_init(ROOM_JID, PROFILE)
|
||||
)
|
||||
|
||||
def test_prepareRoom_invite(self):
|
||||
def test_prepare_room_invite(self):
|
||||
self.reinit()
|
||||
other_players = [Const.JID[1], Const.JID[2]]
|
||||
self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE)
|
||||
room = self.plugin_0045.getRoom(0, 0)
|
||||
self.plugin.prepare_room(other_players, ROOM_JID, PROFILE)
|
||||
room = self.plugin_0045.get_room(0, 0)
|
||||
|
||||
self.assertTrue(self.plugin._gameExists(ROOM_JID, True))
|
||||
self.assertTrue(self.plugin._game_exists(ROOM_JID, True))
|
||||
self.assertTrue(
|
||||
self.plugin._checkJoinAuth(ROOM_JID, Const.JID[1], Const.JID[1].user)
|
||||
self.plugin._check_join_auth(ROOM_JID, Const.JID[1], Const.JID[1].user)
|
||||
)
|
||||
self.assertFalse(
|
||||
self.plugin._checkJoinAuth(ROOM_JID, Const.JID[3], Const.JID[3].user)
|
||||
self.plugin._check_join_auth(ROOM_JID, Const.JID[3], Const.JID[3].user)
|
||||
)
|
||||
self.assertFalse(self.plugin._checkInviteAuth(ROOM_JID, Const.JID[1].user))
|
||||
self.assertFalse(self.plugin._check_invite_auth(ROOM_JID, Const.JID[1].user))
|
||||
self.assertEqual(
|
||||
(True, [], other_players), self.plugin._checkWaitAuth(room, other_players)
|
||||
(True, [], other_players), self.plugin._check_wait_auth(room, other_players)
|
||||
)
|
||||
|
||||
player2_nick = self.plugin_0045.joinRoom(0, 1)
|
||||
self.plugin.userJoinedTrigger(room, room.roster[player2_nick], PROFILE)
|
||||
self.assertTrue(self.plugin.isPlayer(ROOM_JID, player2_nick))
|
||||
self.assertTrue(self.plugin._checkInviteAuth(ROOM_JID, player2_nick))
|
||||
self.assertFalse(self.plugin.isReferee(ROOM_JID, player2_nick))
|
||||
self.assertTrue(self.plugin.isPlayer(ROOM_JID, player2_nick))
|
||||
player2_nick = self.plugin_0045.join_room(0, 1)
|
||||
self.plugin.user_joined_trigger(room, room.roster[player2_nick], PROFILE)
|
||||
self.assertTrue(self.plugin.is_player(ROOM_JID, player2_nick))
|
||||
self.assertTrue(self.plugin._check_invite_auth(ROOM_JID, player2_nick))
|
||||
self.assertFalse(self.plugin.is_referee(ROOM_JID, player2_nick))
|
||||
self.assertTrue(self.plugin.is_player(ROOM_JID, player2_nick))
|
||||
self.assertTrue(
|
||||
self.plugin.isPlayer(ROOM_JID, self.plugin_0045.getNickOfUser(0, 2, 0))
|
||||
self.plugin.is_player(ROOM_JID, self.plugin_0045.get_nick_of_user(0, 2, 0))
|
||||
)
|
||||
self.assertFalse(self.plugin.isPlayer(ROOM_JID, "xxx"))
|
||||
self.assertFalse(self.plugin.is_player(ROOM_JID, "xxx"))
|
||||
self.assertEqual(
|
||||
(False, False),
|
||||
self.plugin._checkCreateGameAndInit(ROOM_JID, Const.PROFILE[1]),
|
||||
self.plugin._check_create_game_and_init(ROOM_JID, Const.PROFILE[1]),
|
||||
)
|
||||
|
||||
def test_prepareRoom_score1(self):
|
||||
def test_prepare_room_score_1(self):
|
||||
self.reinit(player_init={"score": 0})
|
||||
other_players = [Const.JID[1], Const.JID[2]]
|
||||
self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE)
|
||||
room = self.plugin_0045.getRoom(0, 0)
|
||||
self.plugin.prepare_room(other_players, ROOM_JID, PROFILE)
|
||||
room = self.plugin_0045.get_room(0, 0)
|
||||
|
||||
self.assertFalse(self.plugin._gameExists(ROOM_JID, True))
|
||||
self.assertFalse(self.plugin._game_exists(ROOM_JID, True))
|
||||
self.assertTrue(
|
||||
self.plugin._checkJoinAuth(ROOM_JID, Const.JID[1], Const.JID[1].user)
|
||||
self.plugin._check_join_auth(ROOM_JID, Const.JID[1], Const.JID[1].user)
|
||||
)
|
||||
self.assertFalse(
|
||||
self.plugin._checkJoinAuth(ROOM_JID, Const.JID[3], Const.JID[3].user)
|
||||
self.plugin._check_join_auth(ROOM_JID, Const.JID[3], Const.JID[3].user)
|
||||
)
|
||||
self.assertFalse(self.plugin._checkInviteAuth(ROOM_JID, Const.JID[1].user))
|
||||
self.assertFalse(self.plugin._check_invite_auth(ROOM_JID, Const.JID[1].user))
|
||||
self.assertEqual(
|
||||
(False, [], other_players), self.plugin._checkWaitAuth(room, other_players)
|
||||
(False, [], other_players), self.plugin._check_wait_auth(room, other_players)
|
||||
)
|
||||
|
||||
user_nick = self.plugin_0045.joinRoom(0, 1)
|
||||
self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE)
|
||||
self.assertTrue(self.plugin.isPlayer(ROOM_JID, user_nick))
|
||||
self.assertFalse(self.plugin._checkInviteAuth(ROOM_JID, user_nick))
|
||||
self.assertFalse(self.plugin.isReferee(ROOM_JID, user_nick))
|
||||
self.assertTrue(self.plugin.isPlayer(ROOM_JID, user_nick))
|
||||
user_nick = self.plugin_0045.join_room(0, 1)
|
||||
self.plugin.user_joined_trigger(room, room.roster[user_nick], PROFILE)
|
||||
self.assertTrue(self.plugin.is_player(ROOM_JID, user_nick))
|
||||
self.assertFalse(self.plugin._check_invite_auth(ROOM_JID, user_nick))
|
||||
self.assertFalse(self.plugin.is_referee(ROOM_JID, user_nick))
|
||||
self.assertTrue(self.plugin.is_player(ROOM_JID, user_nick))
|
||||
# the following assertion is True because Const.JID[1] and Const.JID[2] have the same userhost
|
||||
self.assertTrue(
|
||||
self.plugin.isPlayer(ROOM_JID, self.plugin_0045.getNickOfUser(0, 2, 0))
|
||||
self.plugin.is_player(ROOM_JID, self.plugin_0045.get_nick_of_user(0, 2, 0))
|
||||
)
|
||||
# the following assertion is True because Const.JID[1] nick in the room is equal to Const.JID[3].user
|
||||
self.assertTrue(self.plugin.isPlayer(ROOM_JID, Const.JID[3].user))
|
||||
self.assertTrue(self.plugin.is_player(ROOM_JID, Const.JID[3].user))
|
||||
# but Const.JID[3] is actually not in the room
|
||||
self.assertEqual(self.plugin_0045.getNickOfUser(0, 3, 0), None)
|
||||
self.assertEqual(self.plugin_0045.get_nick_of_user(0, 3, 0), None)
|
||||
self.assertEqual(
|
||||
(True, False), self.plugin._checkCreateGameAndInit(ROOM_JID, Const.PROFILE[0])
|
||||
(True, False), self.plugin._check_create_game_and_init(ROOM_JID, Const.PROFILE[0])
|
||||
)
|
||||
|
||||
def test_prepareRoom_score2(self):
|
||||
def test_prepare_room_score_2(self):
|
||||
self.reinit(player_init={"score": 0})
|
||||
other_players = [Const.JID[1], Const.JID[4]]
|
||||
self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE)
|
||||
room = self.plugin_0045.getRoom(0, 0)
|
||||
self.plugin.prepare_room(other_players, ROOM_JID, PROFILE)
|
||||
room = self.plugin_0045.get_room(0, 0)
|
||||
|
||||
user_nick = self.plugin_0045.joinRoom(0, 1)
|
||||
self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE)
|
||||
user_nick = self.plugin_0045.join_room(0, 1)
|
||||
self.plugin.user_joined_trigger(room, room.roster[user_nick], PROFILE)
|
||||
self.assertEqual(
|
||||
(True, False), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE)
|
||||
(True, False), self.plugin._check_create_game_and_init(ROOM_JID, PROFILE)
|
||||
)
|
||||
user_nick = self.plugin_0045.joinRoom(0, 4)
|
||||
self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE)
|
||||
user_nick = self.plugin_0045.join_room(0, 4)
|
||||
self.plugin.user_joined_trigger(room, room.roster[user_nick], PROFILE)
|
||||
self.assertEqual(
|
||||
(False, True), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE)
|
||||
(False, True), self.plugin._check_create_game_and_init(ROOM_JID, PROFILE)
|
||||
)
|
||||
|
||||
def test_userJoinedTrigger(self):
|
||||
def test_user_joined_trigger(self):
|
||||
self.reinit(player_init={"xxx": "xyz"})
|
||||
other_players = [Const.JID[1], Const.JID[3]]
|
||||
self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE)
|
||||
nicks = [self.plugin_0045.getNick(0, 0)]
|
||||
self.plugin.prepare_room(other_players, ROOM_JID, PROFILE)
|
||||
nicks = [self.plugin_0045.get_nick(0, 0)]
|
||||
|
||||
self.assertEqual(
|
||||
self.host.getSentMessageXml(0),
|
||||
self._expectedMessage(ROOM_JID, "groupchat", "players", nicks),
|
||||
self.host.get_sent_message_xml(0),
|
||||
self._expected_message(ROOM_JID, "groupchat", "players", nicks),
|
||||
)
|
||||
self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 1)
|
||||
|
||||
# wrong profile
|
||||
user_nick = self.plugin_0045.joinRoom(0, 1)
|
||||
room = self.plugin_0045.getRoom(0, 1)
|
||||
self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), OTHER_PROFILE)
|
||||
user_nick = self.plugin_0045.join_room(0, 1)
|
||||
room = self.plugin_0045.get_room(0, 1)
|
||||
self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[1]), OTHER_PROFILE)
|
||||
self.assertEqual(
|
||||
self.host.getSentMessage(0), None
|
||||
self.host.get_sent_message(0), None
|
||||
) # no new message has been sent
|
||||
self.assertFalse(self.plugin._gameExists(ROOM_JID, True)) # game not started
|
||||
self.assertFalse(self.plugin._game_exists(ROOM_JID, True)) # game not started
|
||||
|
||||
# referee profile, user is allowed, wait for one more
|
||||
room = self.plugin_0045.getRoom(0, 0)
|
||||
self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE)
|
||||
room = self.plugin_0045.get_room(0, 0)
|
||||
self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[1]), PROFILE)
|
||||
nicks.append(user_nick)
|
||||
self.assertEqual(
|
||||
self.host.getSentMessageXml(0),
|
||||
self._expectedMessage(ROOM_JID, "groupchat", "players", nicks),
|
||||
self.host.get_sent_message_xml(0),
|
||||
self._expected_message(ROOM_JID, "groupchat", "players", nicks),
|
||||
)
|
||||
self.assertFalse(self.plugin._gameExists(ROOM_JID, True)) # game not started
|
||||
self.assertFalse(self.plugin._game_exists(ROOM_JID, True)) # game not started
|
||||
|
||||
# referee profile, user is not allowed
|
||||
user_nick = self.plugin_0045.joinRoom(0, 4)
|
||||
self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE)
|
||||
user_nick = self.plugin_0045.join_room(0, 4)
|
||||
self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[4]), PROFILE)
|
||||
self.assertEqual(
|
||||
self.host.getSentMessageXml(0),
|
||||
self._expectedMessage(
|
||||
self.host.get_sent_message_xml(0),
|
||||
self._expected_message(
|
||||
JID(ROOM_JID.userhost() + "/" + user_nick), "normal", "players", nicks
|
||||
),
|
||||
)
|
||||
self.assertFalse(self.plugin._gameExists(ROOM_JID, True)) # game not started
|
||||
self.assertFalse(self.plugin._game_exists(ROOM_JID, True)) # game not started
|
||||
|
||||
# referee profile, user is allowed, everybody here
|
||||
user_nick = self.plugin_0045.joinRoom(0, 3)
|
||||
self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE)
|
||||
user_nick = self.plugin_0045.join_room(0, 3)
|
||||
self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[3]), PROFILE)
|
||||
nicks.append(user_nick)
|
||||
self.assertEqual(
|
||||
self.host.getSentMessageXml(0),
|
||||
self._expectedMessage(ROOM_JID, "groupchat", "started", nicks),
|
||||
self.host.get_sent_message_xml(0),
|
||||
self._expected_message(ROOM_JID, "groupchat", "started", nicks),
|
||||
)
|
||||
self.assertTrue(self.plugin._gameExists(ROOM_JID, True)) # game started
|
||||
self.assertTrue(self.plugin._game_exists(ROOM_JID, True)) # game started
|
||||
self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 0)
|
||||
|
||||
# wait for none
|
||||
self.reinit()
|
||||
self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE)
|
||||
self.assertNotEqual(self.host.getSentMessage(0), None) # init messages
|
||||
room = self.plugin_0045.getRoom(0, 0)
|
||||
nicks = [self.plugin_0045.getNick(0, 0)]
|
||||
user_nick = self.plugin_0045.joinRoom(0, 3)
|
||||
self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE)
|
||||
self.plugin.prepare_room(other_players, ROOM_JID, PROFILE)
|
||||
self.assertNotEqual(self.host.get_sent_message(0), None) # init messages
|
||||
room = self.plugin_0045.get_room(0, 0)
|
||||
nicks = [self.plugin_0045.get_nick(0, 0)]
|
||||
user_nick = self.plugin_0045.join_room(0, 3)
|
||||
self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[3]), PROFILE)
|
||||
nicks.append(user_nick)
|
||||
self.assertEqual(
|
||||
self.host.getSentMessageXml(0),
|
||||
self._expectedMessage(ROOM_JID, "groupchat", "started", nicks),
|
||||
self.host.get_sent_message_xml(0),
|
||||
self._expected_message(ROOM_JID, "groupchat", "started", nicks),
|
||||
)
|
||||
self.assertTrue(self.plugin._gameExists(ROOM_JID, True))
|
||||
self.assertTrue(self.plugin._game_exists(ROOM_JID, True))
|
||||
|
||||
def test_userLeftTrigger(self):
|
||||
def test_user_left_trigger(self):
|
||||
self.reinit(player_init={"xxx": "xyz"})
|
||||
other_players = [Const.JID[1], Const.JID[3], Const.JID[4]]
|
||||
self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE)
|
||||
room = self.plugin_0045.getRoom(0, 0)
|
||||
nicks = [self.plugin_0045.getNick(0, 0)]
|
||||
self.plugin.prepare_room(other_players, ROOM_JID, PROFILE)
|
||||
room = self.plugin_0045.get_room(0, 0)
|
||||
nicks = [self.plugin_0045.get_nick(0, 0)]
|
||||
self.assertEqual(
|
||||
self.plugin.invitations[ROOM_JID][0][1],
|
||||
[
|
||||
|
|
@ -511,50 +511,50 @@ class RoomGameTest(helpers.SatTestCase):
|
|||
)
|
||||
|
||||
# one user joins
|
||||
user_nick = self.plugin_0045.joinRoom(0, 1)
|
||||
self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE)
|
||||
user_nick = self.plugin_0045.join_room(0, 1)
|
||||
self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[1]), PROFILE)
|
||||
nicks.append(user_nick)
|
||||
|
||||
# the user leaves
|
||||
self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks)
|
||||
room = self.plugin_0045.getRoom(0, 1)
|
||||
# to not call self.plugin_0045.leaveRoom(0, 1) here, we are testing the trigger with a wrong profile
|
||||
self.plugin.userLeftTrigger(
|
||||
room = self.plugin_0045.get_room(0, 1)
|
||||
# to not call self.plugin_0045.leave_room(0, 1) here, we are testing the trigger with a wrong profile
|
||||
self.plugin.user_left_trigger(
|
||||
room, User(user_nick, Const.JID[1]), Const.PROFILE[1]
|
||||
) # not the referee
|
||||
self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks)
|
||||
room = self.plugin_0045.getRoom(0, 0)
|
||||
user_nick = self.plugin_0045.leaveRoom(0, 1)
|
||||
self.plugin.userLeftTrigger(
|
||||
room = self.plugin_0045.get_room(0, 0)
|
||||
user_nick = self.plugin_0045.leave_room(0, 1)
|
||||
self.plugin.user_left_trigger(
|
||||
room, User(user_nick, Const.JID[1]), PROFILE
|
||||
) # referee
|
||||
nicks.pop()
|
||||
self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks)
|
||||
|
||||
# all the users join
|
||||
user_nick = self.plugin_0045.joinRoom(0, 1)
|
||||
self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE)
|
||||
user_nick = self.plugin_0045.join_room(0, 1)
|
||||
self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[1]), PROFILE)
|
||||
nicks.append(user_nick)
|
||||
user_nick = self.plugin_0045.joinRoom(0, 3)
|
||||
self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE)
|
||||
user_nick = self.plugin_0045.join_room(0, 3)
|
||||
self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[3]), PROFILE)
|
||||
nicks.append(user_nick)
|
||||
user_nick = self.plugin_0045.joinRoom(0, 4)
|
||||
self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE)
|
||||
user_nick = self.plugin_0045.join_room(0, 4)
|
||||
self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[4]), PROFILE)
|
||||
nicks.append(user_nick)
|
||||
self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks)
|
||||
self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 0)
|
||||
|
||||
# one user leaves
|
||||
user_nick = self.plugin_0045.leaveRoom(0, 4)
|
||||
self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[4]), PROFILE)
|
||||
user_nick = self.plugin_0045.leave_room(0, 4)
|
||||
self.plugin.user_left_trigger(room, User(user_nick, Const.JID[4]), PROFILE)
|
||||
nicks.pop()
|
||||
self.assertEqual(
|
||||
self.plugin.invitations[ROOM_JID][0][1], [Const.JID[4].userhostJID()]
|
||||
)
|
||||
|
||||
# another leaves
|
||||
user_nick = self.plugin_0045.leaveRoom(0, 3)
|
||||
self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[3]), PROFILE)
|
||||
user_nick = self.plugin_0045.leave_room(0, 3)
|
||||
self.plugin.user_left_trigger(room, User(user_nick, Const.JID[3]), PROFILE)
|
||||
nicks.pop()
|
||||
self.assertEqual(
|
||||
self.plugin.invitations[ROOM_JID][0][1],
|
||||
|
|
@ -562,64 +562,64 @@ class RoomGameTest(helpers.SatTestCase):
|
|||
)
|
||||
|
||||
# they can join again
|
||||
user_nick = self.plugin_0045.joinRoom(0, 3)
|
||||
self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE)
|
||||
user_nick = self.plugin_0045.join_room(0, 3)
|
||||
self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[3]), PROFILE)
|
||||
nicks.append(user_nick)
|
||||
user_nick = self.plugin_0045.joinRoom(0, 4)
|
||||
self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE)
|
||||
user_nick = self.plugin_0045.join_room(0, 4)
|
||||
self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[4]), PROFILE)
|
||||
nicks.append(user_nick)
|
||||
self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks)
|
||||
self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 0)
|
||||
|
||||
def test__checkCreateGameAndInit(self):
|
||||
def test_check_create_game_and_init(self):
|
||||
self.reinit()
|
||||
helpers.muteLogging()
|
||||
helpers.mute_logging()
|
||||
self.assertEqual(
|
||||
(False, False), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE)
|
||||
(False, False), self.plugin._check_create_game_and_init(ROOM_JID, PROFILE)
|
||||
)
|
||||
helpers.unmuteLogging()
|
||||
helpers.unmute_logging()
|
||||
|
||||
nick = self.plugin_0045.joinRoom(0, 0)
|
||||
nick = self.plugin_0045.join_room(0, 0)
|
||||
self.assertEqual(
|
||||
(True, False), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE)
|
||||
(True, False), self.plugin._check_create_game_and_init(ROOM_JID, PROFILE)
|
||||
)
|
||||
self.assertTrue(self.plugin._gameExists(ROOM_JID, False))
|
||||
self.assertFalse(self.plugin._gameExists(ROOM_JID, True))
|
||||
self.assertTrue(self.plugin.isReferee(ROOM_JID, nick))
|
||||
self.assertTrue(self.plugin._game_exists(ROOM_JID, False))
|
||||
self.assertFalse(self.plugin._game_exists(ROOM_JID, True))
|
||||
self.assertTrue(self.plugin.is_referee(ROOM_JID, nick))
|
||||
|
||||
helpers.muteLogging()
|
||||
helpers.mute_logging()
|
||||
self.assertEqual(
|
||||
(False, False), self.plugin._checkCreateGameAndInit(ROOM_JID, OTHER_PROFILE)
|
||||
(False, False), self.plugin._check_create_game_and_init(ROOM_JID, OTHER_PROFILE)
|
||||
)
|
||||
helpers.unmuteLogging()
|
||||
helpers.unmute_logging()
|
||||
|
||||
self.plugin_0045.joinRoom(0, 1)
|
||||
self.plugin_0045.join_room(0, 1)
|
||||
self.assertEqual(
|
||||
(False, False), self.plugin._checkCreateGameAndInit(ROOM_JID, OTHER_PROFILE)
|
||||
(False, False), self.plugin._check_create_game_and_init(ROOM_JID, OTHER_PROFILE)
|
||||
)
|
||||
|
||||
self.plugin.createGame(ROOM_JID, [Const.JID[1]], PROFILE)
|
||||
self.plugin.create_game(ROOM_JID, [Const.JID[1]], PROFILE)
|
||||
self.assertEqual(
|
||||
(False, True), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE)
|
||||
(False, True), self.plugin._check_create_game_and_init(ROOM_JID, PROFILE)
|
||||
)
|
||||
self.assertEqual(
|
||||
(False, False), self.plugin._checkCreateGameAndInit(ROOM_JID, OTHER_PROFILE)
|
||||
(False, False), self.plugin._check_create_game_and_init(ROOM_JID, OTHER_PROFILE)
|
||||
)
|
||||
|
||||
def test_createGame(self):
|
||||
def test_create_game(self):
|
||||
|
||||
self.reinit(player_init={"xxx": "xyz"})
|
||||
nicks = []
|
||||
for i in [0, 1, 3, 4]:
|
||||
nicks.append(self.plugin_0045.joinRoom(0, i))
|
||||
nicks.append(self.plugin_0045.join_room(0, i))
|
||||
|
||||
# game not exists
|
||||
self.plugin.createGame(ROOM_JID, nicks, PROFILE)
|
||||
self.assertTrue(self.plugin._gameExists(ROOM_JID, True))
|
||||
self.plugin.create_game(ROOM_JID, nicks, PROFILE)
|
||||
self.assertTrue(self.plugin._game_exists(ROOM_JID, True))
|
||||
self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks)
|
||||
self.assertEqual(
|
||||
self.host.getSentMessageXml(0),
|
||||
self._expectedMessage(ROOM_JID, "groupchat", "started", nicks),
|
||||
self.host.get_sent_message_xml(0),
|
||||
self._expected_message(ROOM_JID, "groupchat", "started", nicks),
|
||||
)
|
||||
for nick in nicks:
|
||||
self.assertEqual("init", self.plugin.games[ROOM_JID]["status"][nick])
|
||||
|
|
@ -635,20 +635,20 @@ class RoomGameTest(helpers.SatTestCase):
|
|||
|
||||
# game exists, current profile is referee
|
||||
self.reinit(player_init={"xxx": "xyz"})
|
||||
self.initGame(0, 0)
|
||||
self.init_game(0, 0)
|
||||
self.plugin.games[ROOM_JID]["started"] = True
|
||||
self.plugin.createGame(ROOM_JID, nicks, PROFILE)
|
||||
self.plugin.create_game(ROOM_JID, nicks, PROFILE)
|
||||
self.assertEqual(
|
||||
self.host.getSentMessageXml(0),
|
||||
self._expectedMessage(ROOM_JID, "groupchat", "started", nicks),
|
||||
self.host.get_sent_message_xml(0),
|
||||
self._expected_message(ROOM_JID, "groupchat", "started", nicks),
|
||||
)
|
||||
|
||||
# game exists, current profile is not referee
|
||||
self.reinit(player_init={"xxx": "xyz"})
|
||||
self.initGame(0, 0)
|
||||
self.init_game(0, 0)
|
||||
self.plugin.games[ROOM_JID]["started"] = True
|
||||
self.plugin_0045.joinRoom(0, 1)
|
||||
self.plugin.createGame(ROOM_JID, nicks, OTHER_PROFILE)
|
||||
self.plugin_0045.join_room(0, 1)
|
||||
self.plugin.create_game(ROOM_JID, nicks, OTHER_PROFILE)
|
||||
self.assertEqual(
|
||||
self.host.getSentMessage(0), None
|
||||
self.host.get_sent_message(0), None
|
||||
) # no sync message has been sent by other_profile
|
||||
|
|
|
|||
|
|
@ -78,15 +78,15 @@ class SanitisationTest(helpers.SatTestCase):
|
|||
</img></body>
|
||||
</div>"""
|
||||
|
||||
d = self.text_syntaxes.cleanXHTML(self.EVIL_HTML1)
|
||||
d.addCallback(self.assertEqualXML, expected, ignore_blank=True)
|
||||
d = self.text_syntaxes.clean_xhtml(self.EVIL_HTML1)
|
||||
d.addCallback(self.assert_equal_xml, expected, ignore_blank=True)
|
||||
return d
|
||||
|
||||
def test_styles_sanitise(self):
|
||||
expected = """<p style="color: blue">test <strong>retest</strong><br/><span style="color: #cf2828; font-size: 3px; color: red; color: red !important; font-size: 100px !important; font-size: 100%; font-size: 100px; font-size: 100; font-size: 100 %; color: rgba(0, 0, 0, 0.1); color: rgb(35,79,255); background-color: no-repeat"> toto </span></p>"""
|
||||
|
||||
d = self.text_syntaxes.cleanXHTML(self.EVIL_HTML2)
|
||||
d.addCallback(self.assertEqualXML, expected)
|
||||
d = self.text_syntaxes.clean_xhtml(self.EVIL_HTML2)
|
||||
d.addCallback(self.assert_equal_xml, expected)
|
||||
return d
|
||||
|
||||
def test_html2text(self):
|
||||
|
|
@ -105,11 +105,11 @@ class SanitisationTest(helpers.SatTestCase):
|
|||
d.addCallback(self.assertEqual, expected)
|
||||
return d
|
||||
|
||||
def test_removeXHTMLMarkups(self):
|
||||
def test_remove_xhtml_markups(self):
|
||||
expected = """ a link another link a paragraph secret EVIL! of EVIL! Password: annoying EVIL! spam spam SPAM! """
|
||||
result = self.text_syntaxes._removeMarkups(self.EVIL_HTML1)
|
||||
result = self.text_syntaxes._remove_markups(self.EVIL_HTML1)
|
||||
self.assertEqual(re.sub(r"\s+", " ", result).rstrip(), expected.rstrip())
|
||||
|
||||
expected = """test retest toto"""
|
||||
result = self.text_syntaxes._removeMarkups(self.EVIL_HTML2)
|
||||
result = self.text_syntaxes._remove_markups(self.EVIL_HTML2)
|
||||
self.assertEqual(re.sub(r"\s+", " ", result).rstrip(), expected.rstrip())
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class XEP_0033Test(helpers.SatTestCase):
|
|||
self.host = helpers.FakeSAT()
|
||||
self.plugin = plugin.XEP_0033(self.host)
|
||||
|
||||
def test_messageReceived(self):
|
||||
def test_message_received(self):
|
||||
self.host.memory.reinit()
|
||||
xml = """
|
||||
<message type="chat" from="%s" to="%s" id="test_1">
|
||||
|
|
@ -64,8 +64,8 @@ class XEP_0033Test(helpers.SatTestCase):
|
|||
)
|
||||
stanza = parseXml(xml.encode("utf-8"))
|
||||
treatments = defer.Deferred()
|
||||
self.plugin.messageReceivedTrigger(
|
||||
self.host.getClient(PROFILE), stanza, treatments
|
||||
self.plugin.message_received_trigger(
|
||||
self.host.get_client(PROFILE), stanza, treatments
|
||||
)
|
||||
data = {"extra": {}}
|
||||
|
||||
|
|
@ -98,7 +98,7 @@ class XEP_0033Test(helpers.SatTestCase):
|
|||
mess_data["xml"] = parseXml(original_stanza.encode("utf-8"))
|
||||
return mess_data
|
||||
|
||||
def _assertAddresses(self, mess_data):
|
||||
def _assert_addresses(self, mess_data):
|
||||
"""The mess_data that we got here has been modified by self.plugin.messageSendTrigger,
|
||||
check that the addresses element has been added to the stanza."""
|
||||
expected = self._get_mess_data()["xml"]
|
||||
|
|
@ -113,13 +113,13 @@ class XEP_0033Test(helpers.SatTestCase):
|
|||
)
|
||||
addresses_element = parseXml(addresses_extra.encode("utf-8"))
|
||||
expected.addChild(addresses_element)
|
||||
self.assertEqualXML(
|
||||
self.assert_equal_xml(
|
||||
mess_data["xml"].toXml().encode("utf-8"), expected.toXml().encode("utf-8")
|
||||
)
|
||||
|
||||
def _checkSentAndStored(self):
|
||||
def _check_sent_and_stored(self):
|
||||
"""Check that all the recipients got their messages and that the history has been filled.
|
||||
/!\ see the comments in XEP_0033.sendAndStoreMessage"""
|
||||
/!\ see the comments in XEP_0033.send_and_store_message"""
|
||||
sent = []
|
||||
stored = []
|
||||
d_list = []
|
||||
|
|
@ -135,23 +135,23 @@ class XEP_0033Test(helpers.SatTestCase):
|
|||
else: # feature not supported, use normal behavior
|
||||
sent.append(to_jid)
|
||||
stored.append(to_jid)
|
||||
helpers.unmuteLogging()
|
||||
helpers.unmute_logging()
|
||||
|
||||
for to_s in (JID_STR_X_TO, JID_STR_X_CC, JID_STR_X_BCC):
|
||||
to_jid = JID(to_s)
|
||||
host = JID(to_jid.host)
|
||||
helpers.muteLogging()
|
||||
d = self.host.findFeaturesSet([plugin.NS_ADDRESS], jid_=host, profile=PROFILE)
|
||||
helpers.mute_logging()
|
||||
d = self.host.find_features_set([plugin.NS_ADDRESS], jid_=host, profile=PROFILE)
|
||||
d.addCallback(cb, to_jid)
|
||||
d_list.append(d)
|
||||
|
||||
def cb_list(__):
|
||||
msg = "/!\ see the comments in XEP_0033.sendAndStoreMessage"
|
||||
msg = "/!\ see the comments in XEP_0033.send_and_store_message"
|
||||
sent_recipients = [
|
||||
JID(elt["to"]) for elt in self.host.getSentMessages(PROFILE_INDEX)
|
||||
JID(elt["to"]) for elt in self.host.get_sent_messages(PROFILE_INDEX)
|
||||
]
|
||||
self.assertEqualUnsortedList(sent_recipients, sent, msg)
|
||||
self.assertEqualUnsortedList(self.host.stored_messages, stored, msg)
|
||||
self.assert_equal_unsorted_list(sent_recipients, sent, msg)
|
||||
self.assert_equal_unsorted_list(self.host.stored_messages, stored, msg)
|
||||
|
||||
return defer.DeferredList(d_list).addCallback(cb_list)
|
||||
|
||||
|
|
@ -164,48 +164,48 @@ class XEP_0033Test(helpers.SatTestCase):
|
|||
"""
|
||||
pre_treatments = defer.Deferred()
|
||||
post_treatments = defer.Deferred()
|
||||
helpers.muteLogging()
|
||||
helpers.mute_logging()
|
||||
self.plugin.messageSendTrigger(
|
||||
self.host.getClient[PROFILE], data, pre_treatments, post_treatments
|
||||
self.host.get_client[PROFILE], data, pre_treatments, post_treatments
|
||||
)
|
||||
post_treatments.callback(data)
|
||||
helpers.unmuteLogging()
|
||||
helpers.unmute_logging()
|
||||
post_treatments.addCallbacks(
|
||||
self._assertAddresses, lambda failure: failure.trap(CancelError)
|
||||
self._assert_addresses, lambda failure: failure.trap(CancelError)
|
||||
)
|
||||
return post_treatments
|
||||
|
||||
def test_messageSendTriggerFeatureNotSupported(self):
|
||||
def test_message_send_trigger_feature_not_supported(self):
|
||||
# feature is not supported, abort the message
|
||||
self.host.memory.reinit()
|
||||
data = self._get_mess_data()
|
||||
return self._trigger(data)
|
||||
|
||||
def test_messageSendTriggerFeatureSupported(self):
|
||||
def test_message_send_trigger_feature_supported(self):
|
||||
# feature is supported by the main target server
|
||||
self.host.reinit()
|
||||
self.host.addFeature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE)
|
||||
self.host.add_feature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE)
|
||||
data = self._get_mess_data()
|
||||
d = self._trigger(data)
|
||||
return d.addCallback(lambda __: self._checkSentAndStored())
|
||||
return d.addCallback(lambda __: self._check_sent_and_stored())
|
||||
|
||||
def test_messageSendTriggerFeatureFullySupported(self):
|
||||
def test_message_send_trigger_feature_fully_supported(self):
|
||||
# feature is supported by all target servers
|
||||
self.host.reinit()
|
||||
self.host.addFeature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE)
|
||||
self.host.add_feature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE)
|
||||
for dest in (JID_STR_X_TO, JID_STR_X_CC, JID_STR_X_BCC):
|
||||
self.host.addFeature(JID(JID(dest).host), plugin.NS_ADDRESS, PROFILE)
|
||||
self.host.add_feature(JID(JID(dest).host), plugin.NS_ADDRESS, PROFILE)
|
||||
data = self._get_mess_data()
|
||||
d = self._trigger(data)
|
||||
return d.addCallback(lambda __: self._checkSentAndStored())
|
||||
return d.addCallback(lambda __: self._check_sent_and_stored())
|
||||
|
||||
def test_messageSendTriggerFixWrongEntity(self):
|
||||
def test_message_send_trigger_fix_wrong_entity(self):
|
||||
# check that a wrong recipient entity is fixed by the backend
|
||||
self.host.reinit()
|
||||
self.host.addFeature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE)
|
||||
self.host.add_feature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE)
|
||||
for dest in (JID_STR_X_TO, JID_STR_X_CC, JID_STR_X_BCC):
|
||||
self.host.addFeature(JID(JID(dest).host), plugin.NS_ADDRESS, PROFILE)
|
||||
self.host.add_feature(JID(JID(dest).host), plugin.NS_ADDRESS, PROFILE)
|
||||
data = self._get_mess_data()
|
||||
data["to"] = JID(JID_STR_X_TO)
|
||||
d = self._trigger(data)
|
||||
return d.addCallback(lambda __: self._checkSentAndStored())
|
||||
return d.addCallback(lambda __: self._check_sent_and_stored())
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class XEP_0085Test(helpers.SatTestCase):
|
|||
def setUp(self):
|
||||
self.host = helpers.FakeSAT()
|
||||
self.plugin = plugin.XEP_0085(self.host)
|
||||
self.host.memory.setParam(
|
||||
self.host.memory.param_set(
|
||||
plugin.PARAM_NAME,
|
||||
True,
|
||||
plugin.PARAM_KEY,
|
||||
|
|
@ -41,7 +41,7 @@ class XEP_0085Test(helpers.SatTestCase):
|
|||
Const.PROFILE[0],
|
||||
)
|
||||
|
||||
def test_messageReceived(self):
|
||||
def test_message_received(self):
|
||||
for state in plugin.CHAT_STATES:
|
||||
xml = """
|
||||
<message type="chat" from="%s" to="%s" id="test_1">
|
||||
|
|
@ -56,17 +56,17 @@ class XEP_0085Test(helpers.SatTestCase):
|
|||
plugin.NS_CHAT_STATES,
|
||||
)
|
||||
stanza = parseXml(xml.encode("utf-8"))
|
||||
self.host.bridge.expectCall(
|
||||
"chatStateReceived", Const.JID_STR[1], state, Const.PROFILE[0]
|
||||
self.host.bridge.expect_call(
|
||||
"chat_state_received", Const.JID_STR[1], state, Const.PROFILE[0]
|
||||
)
|
||||
self.plugin.messageReceivedTrigger(
|
||||
self.host.getClient(Const.PROFILE[0]), stanza, None
|
||||
self.plugin.message_received_trigger(
|
||||
self.host.get_client(Const.PROFILE[0]), stanza, None
|
||||
)
|
||||
|
||||
def test_messageSendTrigger(self):
|
||||
def test_message_send_trigger(self):
|
||||
def cb(data):
|
||||
xml = data["xml"].toXml().encode("utf-8")
|
||||
self.assertEqualXML(xml, expected.toXml().encode("utf-8"))
|
||||
self.assert_equal_xml(xml, expected.toXml().encode("utf-8"))
|
||||
|
||||
d_list = []
|
||||
|
||||
|
|
@ -91,7 +91,7 @@ class XEP_0085Test(helpers.SatTestCase):
|
|||
expected.addElement(state, plugin.NS_CHAT_STATES)
|
||||
post_treatments = defer.Deferred()
|
||||
self.plugin.messageSendTrigger(
|
||||
self.host.getClient(Const.PROFILE[0]), mess_data, None, post_treatments
|
||||
self.host.get_client(Const.PROFILE[0]), mess_data, None, post_treatments
|
||||
)
|
||||
|
||||
post_treatments.addCallback(cb)
|
||||
|
|
|
|||
|
|
@ -63,5 +63,5 @@ class XEP_0203Test(helpers.SatTestCase):
|
|||
parent.addElement("body", None, "text")
|
||||
stamp = datetime.datetime(2002, 9, 10, 23, 8, 25, tzinfo=tzutc())
|
||||
elt = self.plugin.delay(stamp, JID("capulet.com"), "Offline Storage", parent)
|
||||
self.assertEqualXML(elt.toXml(), delay_xml, True)
|
||||
self.assertEqualXML(parent.toXml(), message_xml, True)
|
||||
self.assert_equal_xml(elt.toXml(), delay_xml, True)
|
||||
self.assert_equal_xml(parent.toXml(), message_xml, True)
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ class XEP_0277Test(helpers.SatTestCase):
|
|||
def __init__(self, host):
|
||||
pass
|
||||
|
||||
def addPEPEvent(self, *args):
|
||||
def add_pep_event(self, *args):
|
||||
pass
|
||||
|
||||
self.host.plugins["XEP-0060"] = plugin_xep_0060.XEP_0060(self.host)
|
||||
|
|
|
|||
|
|
@ -82,8 +82,8 @@ class XEP_0297Test(helpers.SatTestCase):
|
|||
profile_key=C.PROFILE[0],
|
||||
)
|
||||
d.addCallback(
|
||||
lambda __: self.assertEqualXML(
|
||||
self.host.getSentMessageXml(0), output, True
|
||||
lambda __: self.assert_equal_xml(
|
||||
self.host.get_sent_message_xml(0), output, True
|
||||
)
|
||||
)
|
||||
return d
|
||||
|
|
|
|||
|
|
@ -42,11 +42,11 @@ class XEP_0313Test(helpers.SatTestCase):
|
|||
def setUp(self):
|
||||
self.host = helpers.FakeSAT()
|
||||
self.plugin = XEP_0313(self.host)
|
||||
self.client = self.host.getClient(C.PROFILE[0])
|
||||
mam_client = self.plugin.getHandler(C.PROFILE[0])
|
||||
mam_client.makeConnection(self.host.getClient(C.PROFILE[0]).xmlstream)
|
||||
self.client = self.host.get_client(C.PROFILE[0])
|
||||
mam_client = self.plugin.get_handler(C.PROFILE[0])
|
||||
mam_client.makeConnection(self.host.get_client(C.PROFILE[0]).xmlstream)
|
||||
|
||||
def test_queryArchive(self):
|
||||
def test_query_archive(self):
|
||||
xml = """
|
||||
<iq type='set' id='%s' to='%s'>
|
||||
<query xmlns='urn:xmpp:mam:1'/>
|
||||
|
|
@ -57,11 +57,11 @@ class XEP_0313Test(helpers.SatTestCase):
|
|||
)
|
||||
d = self.plugin.queryArchive(self.client, MAMRequest(), SERVICE_JID)
|
||||
d.addCallback(
|
||||
lambda __: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)
|
||||
lambda __: self.assert_equal_xml(self.host.get_sent_message_xml(0), xml, True)
|
||||
)
|
||||
return d
|
||||
|
||||
def test_queryArchivePubsub(self):
|
||||
def test_query_archive_pubsub(self):
|
||||
xml = """
|
||||
<iq type='set' id='%s' to='%s'>
|
||||
<query xmlns='urn:xmpp:mam:1' node='fdp/submitted/capulet.lit/sonnets' />
|
||||
|
|
@ -74,11 +74,11 @@ class XEP_0313Test(helpers.SatTestCase):
|
|||
self.client, MAMRequest(node="fdp/submitted/capulet.lit/sonnets"), SERVICE_JID
|
||||
)
|
||||
d.addCallback(
|
||||
lambda __: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)
|
||||
lambda __: self.assert_equal_xml(self.host.get_sent_message_xml(0), xml, True)
|
||||
)
|
||||
return d
|
||||
|
||||
def test_queryArchiveWith(self):
|
||||
def test_query_archive_with(self):
|
||||
xml = """
|
||||
<iq type='set' id='%s' to='%s'>
|
||||
<query xmlns='urn:xmpp:mam:1'>
|
||||
|
|
@ -99,11 +99,11 @@ class XEP_0313Test(helpers.SatTestCase):
|
|||
form = buildForm(with_jid=JID("juliet@capulet.lit"))
|
||||
d = self.plugin.queryArchive(self.client, MAMRequest(form), SERVICE_JID)
|
||||
d.addCallback(
|
||||
lambda __: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)
|
||||
lambda __: self.assert_equal_xml(self.host.get_sent_message_xml(0), xml, True)
|
||||
)
|
||||
return d
|
||||
|
||||
def test_queryArchiveStartEnd(self):
|
||||
def test_query_archive_start_end(self):
|
||||
xml = """
|
||||
<iq type='set' id='%s' to='%s'>
|
||||
<query xmlns='urn:xmpp:mam:1'>
|
||||
|
|
@ -129,11 +129,11 @@ class XEP_0313Test(helpers.SatTestCase):
|
|||
form = buildForm(start=start, end=end)
|
||||
d = self.plugin.queryArchive(self.client, MAMRequest(form), SERVICE_JID)
|
||||
d.addCallback(
|
||||
lambda __: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)
|
||||
lambda __: self.assert_equal_xml(self.host.get_sent_message_xml(0), xml, True)
|
||||
)
|
||||
return d
|
||||
|
||||
def test_queryArchiveStart(self):
|
||||
def test_query_archive_start(self):
|
||||
xml = """
|
||||
<iq type='set' id='%s' to='%s'>
|
||||
<query xmlns='urn:xmpp:mam:1'>
|
||||
|
|
@ -155,11 +155,11 @@ class XEP_0313Test(helpers.SatTestCase):
|
|||
form = buildForm(start=start)
|
||||
d = self.plugin.queryArchive(self.client, MAMRequest(form), SERVICE_JID)
|
||||
d.addCallback(
|
||||
lambda __: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)
|
||||
lambda __: self.assert_equal_xml(self.host.get_sent_message_xml(0), xml, True)
|
||||
)
|
||||
return d
|
||||
|
||||
def test_queryArchiveRSM(self):
|
||||
def test_query_archive_rsm(self):
|
||||
xml = """
|
||||
<iq type='set' id='%s' to='%s'>
|
||||
<query xmlns='urn:xmpp:mam:1'>
|
||||
|
|
@ -185,11 +185,11 @@ class XEP_0313Test(helpers.SatTestCase):
|
|||
rsm = RSMRequest(max_=10)
|
||||
d = self.plugin.queryArchive(self.client, MAMRequest(form, rsm), SERVICE_JID)
|
||||
d.addCallback(
|
||||
lambda __: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)
|
||||
lambda __: self.assert_equal_xml(self.host.get_sent_message_xml(0), xml, True)
|
||||
)
|
||||
return d
|
||||
|
||||
def test_queryArchiveRSMPaging(self):
|
||||
def test_query_archive_rsm_paging(self):
|
||||
xml = """
|
||||
<iq type='set' id='%s' to='%s'>
|
||||
<query xmlns='urn:xmpp:mam:1'>
|
||||
|
|
@ -212,11 +212,11 @@ class XEP_0313Test(helpers.SatTestCase):
|
|||
rsm = RSMRequest(max_=10, after="09af3-cc343-b409f")
|
||||
d = self.plugin.queryArchive(self.client, MAMRequest(form, rsm), SERVICE_JID)
|
||||
d.addCallback(
|
||||
lambda __: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)
|
||||
lambda __: self.assert_equal_xml(self.host.get_sent_message_xml(0), xml, True)
|
||||
)
|
||||
return d
|
||||
|
||||
def test_queryFields(self):
|
||||
def test_query_fields(self):
|
||||
xml = """
|
||||
<iq type='get' id="%s" to='%s'>
|
||||
<query xmlns='urn:xmpp:mam:1'/>
|
||||
|
|
@ -227,11 +227,11 @@ class XEP_0313Test(helpers.SatTestCase):
|
|||
)
|
||||
d = self.plugin.queryFields(self.client, SERVICE_JID)
|
||||
d.addCallback(
|
||||
lambda __: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)
|
||||
lambda __: self.assert_equal_xml(self.host.get_sent_message_xml(0), xml, True)
|
||||
)
|
||||
return d
|
||||
|
||||
def test_queryArchiveFields(self):
|
||||
def test_query_archive_fields(self):
|
||||
xml = """
|
||||
<iq type='set' id='%s' to='%s'>
|
||||
<query xmlns='urn:xmpp:mam:1'>
|
||||
|
|
@ -267,11 +267,11 @@ class XEP_0313Test(helpers.SatTestCase):
|
|||
form = buildForm(extra_fields=extra_fields)
|
||||
d = self.plugin.queryArchive(self.client, MAMRequest(form), SERVICE_JID)
|
||||
d.addCallback(
|
||||
lambda __: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)
|
||||
lambda __: self.assert_equal_xml(self.host.get_sent_message_xml(0), xml, True)
|
||||
)
|
||||
return d
|
||||
|
||||
def test_queryPrefs(self):
|
||||
def test_query_prefs(self):
|
||||
xml = """
|
||||
<iq type='get' id='%s' to='%s'>
|
||||
<prefs xmlns='urn:xmpp:mam:1'>
|
||||
|
|
@ -283,13 +283,13 @@ class XEP_0313Test(helpers.SatTestCase):
|
|||
("H_%d" % domish.Element._idCounter),
|
||||
SERVICE,
|
||||
)
|
||||
d = self.plugin.getPrefs(self.client, SERVICE_JID)
|
||||
d = self.plugin.get_prefs(self.client, SERVICE_JID)
|
||||
d.addCallback(
|
||||
lambda __: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)
|
||||
lambda __: self.assert_equal_xml(self.host.get_sent_message_xml(0), xml, True)
|
||||
)
|
||||
return d
|
||||
|
||||
def test_setPrefs(self):
|
||||
def test_set_prefs(self):
|
||||
xml = """
|
||||
<iq type='set' id='%s' to='%s'>
|
||||
<prefs xmlns='urn:xmpp:mam:1' default='roster'>
|
||||
|
|
@ -309,6 +309,6 @@ class XEP_0313Test(helpers.SatTestCase):
|
|||
never = [JID("montague@montague.lit")]
|
||||
d = self.plugin.setPrefs(self.client, SERVICE_JID, always=always, never=never)
|
||||
d.addCallback(
|
||||
lambda __: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)
|
||||
lambda __: self.assert_equal_xml(self.host.get_sent_message_xml(0), xml, True)
|
||||
)
|
||||
return d
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class XEP_0334Test(helpers.SatTestCase):
|
|||
self.host = helpers.FakeSAT()
|
||||
self.plugin = XEP_0334(self.host)
|
||||
|
||||
def test_messageSendTrigger(self):
|
||||
def test_message_send_trigger(self):
|
||||
template_xml = """
|
||||
<message
|
||||
from='romeo@montague.net/orchard'
|
||||
|
|
@ -51,7 +51,7 @@ class XEP_0334Test(helpers.SatTestCase):
|
|||
|
||||
def cb(data, expected_xml):
|
||||
result_xml = data["xml"].toXml().encode("utf-8")
|
||||
self.assertEqualXML(result_xml, expected_xml, True)
|
||||
self.assert_equal_xml(result_xml, expected_xml, True)
|
||||
|
||||
for key in HINTS + ("", "dummy_hint"):
|
||||
mess_data = {
|
||||
|
|
@ -60,7 +60,7 @@ class XEP_0334Test(helpers.SatTestCase):
|
|||
}
|
||||
treatments = defer.Deferred()
|
||||
self.plugin.messageSendTrigger(
|
||||
self.host.getClient(C.PROFILE[0]), mess_data, defer.Deferred(), treatments
|
||||
self.host.get_client(C.PROFILE[0]), mess_data, defer.Deferred(), treatments
|
||||
)
|
||||
if treatments.callbacks: # the trigger added a callback
|
||||
expected_xml = template_xml % ('<%s xmlns="urn:xmpp:hints"/>' % key)
|
||||
|
|
@ -70,7 +70,7 @@ class XEP_0334Test(helpers.SatTestCase):
|
|||
|
||||
return defer.DeferredList(d_list)
|
||||
|
||||
def test_messageReceivedTrigger(self):
|
||||
def test_message_received_trigger(self):
|
||||
template_xml = """
|
||||
<message
|
||||
from='romeo@montague.net/orchard'
|
||||
|
|
@ -92,8 +92,8 @@ class XEP_0334Test(helpers.SatTestCase):
|
|||
for key in HINTS + ("dummy_hint",):
|
||||
message = parseXml(template_xml % ('<%s xmlns="urn:xmpp:hints"/>' % key))
|
||||
post_treat = defer.Deferred()
|
||||
self.plugin.messageReceivedTrigger(
|
||||
self.host.getClient(C.PROFILE[0]), message, post_treat
|
||||
self.plugin.message_received_trigger(
|
||||
self.host.get_client(C.PROFILE[0]), message, post_treat
|
||||
)
|
||||
if post_treat.callbacks:
|
||||
assert key in ("no-permanent-storage", "no-storage")
|
||||
|
|
|
|||
Loading…
Reference in a new issue