core, plugin XEP-0115: discovery refactoring:

- hashing algorithm of XEP-0115 has been including in core
    - our own hash is still calculated by XEP-0115 and can be regenerated with XEP_0115.recalculateHash
    - old discovery methods have been removed. Now the following methods are used:
        - hasFeature: tell if a feature is available for an entity
        - getDiscoInfos: self explaining
        - getDiscoItems: self explaining
        - findServiceEntities: return all available items of an entity which given (category, type)
        - findFeaturesSet: search for a set of features in entity + entity's items
      all these methods are asynchronous, and manage cache automatically
    - XEP-0115 manage in a better way hashes, and now use a trigger for presence instead of monkey patch
    - new FeatureNotFound exception, when we want to do something which is not available
    - refactored client initialisation sequence, removed client.initialized Deferred
    - added constant APP_URL
    - test_plugin_xep_0033.py has been temporarly deactivated, the time to adapt it
    - lot of cleaning
This commit is contained in:
Goffi 2014-03-28 18:07:22 +01:00
commit 95678d7967
3 changed files with 431 additions and 479 deletions

View file

@ -90,26 +90,6 @@ class FakeSAT(object):
self.stored_messages.append(mess_data["to"])
pass
def requestServerDisco(self, feature, jid_=None, cache_only=False, profile_key="@NONE"):
"""Discover if a server or its items offer a given feature
@param feature: the feature to check
@param jid_: the jid of the server, local server if None
@param cache_only: expect the result to be in cache and don't actually
make any request. This can be used anytime for requesting a feature on
the local server because the data are cached for sure.
@result: the Deferred entity jid offering the feature, or None
"""
profile = self.memory.getProfileName(profile_key)
self.memory.server_features.setdefault(profile, {})
if jid_ is None:
jid_ = self.getClientHostJid(profile_key)
# call FakeMemory.init and FakeMemory.addServerFeature
# in your tests to change the return value of this method
return defer.succeed(jid_ if self.memory.hasServerFeature(feature, jid_, profile_key) else None)
def getClientHostJid(self, profile_key):
return Const.PROFILE_DICT[profile_key].host
def getClient(self, profile_key):
"""Convenient method to get client from profile key
@return: client or None if it doesn't exist"""
@ -118,7 +98,6 @@ class FakeSAT(object):
raise exceptions.ProfileKeyUnknownError
if profile not in self.profiles:
self.profiles[profile] = FakeClient(self, profile)
self.profiles[profile].client_initialized.callback(None)
return self.profiles[profile]
def getJidNStream(self, profile_key):
@ -241,7 +220,6 @@ class FakeMemory(Memory):
self.params.params.clear()
self.params.frontends_cache = []
self.entities_data = {}
self.server_features = {}
def getProfileName(self, profile_key, return_profile_keys=False):
return self.params.getProfileName(profile_key, return_profile_keys)
@ -323,7 +301,6 @@ class FakeClient(object):
self.profile = profile if profile else Const.PROFILE[0]
self.jid = Const.PROFILE_DICT[self.profile]
self.roster = FakeRosterProtocol(host, self)
self.client_initialized = defer.Deferred()
self.xmlstream = FakeXmlStream()
def send(self, obj):

View file

@ -20,9 +20,7 @@
from sat.test import helpers
from constants import Const
from twisted.trial import unittest
from sat.core.sat_main import SAT
from sat.core import xmpp
from twisted.internet import defer
from twisted.words.protocols.jabber.jid import JID
from wokkel.generic import parseXml
from wokkel.xmppim import RosterItem
@ -39,7 +37,6 @@ class SatXMPPClientTest(unittest.TestCase):
self.assertEqual(self.client.profile, Const.PROFILE[0])
print self.client.host
self.assertEqual(self.client.host_app, self.host)
self.assertTrue(isinstance(self.client.client_initialized, defer.Deferred))
class SatMessageProtocolTest(unittest.TestCase):

View file

@ -32,6 +32,7 @@ import logging
class XEP_0033Test(helpers.SatTestCase):
skip = "Must be fixed after disco changes"
def setUp(self):
self.host = helpers.FakeSAT()
@ -151,7 +152,6 @@ class XEP_0033Test(helpers.SatTestCase):
# feature is supported
self.host.init()
self.host.memory.init()
self.host.memory.addServerFeature(plugin.NS_ADDRESS, self.host.getClientHostJid(Const.PROFILE[0]), Const.PROFILE[0])
data = deepcopy(mess_data)
trigger(data, MessageSentAndStored)
checkSentAndStored()
@ -159,7 +159,6 @@ class XEP_0033Test(helpers.SatTestCase):
# check that a wrong recipient entity is fixed by the backend
self.host.init()
self.host.memory.init()
self.host.memory.addServerFeature(plugin.NS_ADDRESS, self.host.getClientHostJid(Const.PROFILE[0]), Const.PROFILE[0])
data = deepcopy(mess_data)
data["to"] = Const.JID[0]
trigger(data, MessageSentAndStored)