core (tests): fixed bad use of reserved name
This commit is contained in:
parent
0ad78c5072
commit
af3ec67047
2 changed files with 39 additions and 39 deletions
|
|
@ -26,7 +26,7 @@ from twisted.words.protocols.jabber import jid
|
|||
from twisted.words.xish.domish import Element, generateElementsNamed
|
||||
from sat.core import exceptions
|
||||
from wokkel import disco, data_form, iwokkel
|
||||
from wokkel import rsm as wokkel_rsm
|
||||
from wokkel import rsm
|
||||
from zope.interface import implements
|
||||
from feed import date
|
||||
import uuid
|
||||
|
|
@ -515,8 +515,8 @@ class GroupBlog(object):
|
|||
d_list = []
|
||||
for entry in items:
|
||||
if entry.get('comments', False):
|
||||
comments_rsm = {'max': max_}
|
||||
d = self.getGroupBlogComments(entry['comments_service'], entry['comments_node'], rsm=comments_rsm, profile_key=profile_key)
|
||||
comments_rsm = {'max_': max_}
|
||||
d = self.getGroupBlogComments(entry['comments_service'], entry['comments_node'], rsm_data=comments_rsm, profile_key=profile_key)
|
||||
d.addCallback(comments_cb, entry)
|
||||
d_list.append(d)
|
||||
else:
|
||||
|
|
@ -528,12 +528,12 @@ class GroupBlog(object):
|
|||
deferred_list.addCallback(lambda result: [value for (success, value) in result if success])
|
||||
return deferred_list
|
||||
|
||||
def _getGroupBlogs(self, pub_jid_s, item_ids=None, rsm=None, max_comments=0, profile_key=C.PROF_KEY_NONE):
|
||||
def _getGroupBlogs(self, pub_jid_s, item_ids=None, rsm_data=None, max_comments=0, profile_key=C.PROF_KEY_NONE):
|
||||
"""Retrieve previously published items from a publish subscribe node.
|
||||
|
||||
@param pub_jid_s: jid of the publisher
|
||||
@param item_ids: list of microblogs items IDs
|
||||
@param rsm (dict): RSM request data
|
||||
@param rsm_data (dict): RSM request data
|
||||
@param max_comments (int): maximum number of comments to retrieve
|
||||
@param profile_key (str): %(doc_profile_key)s
|
||||
@return: a deferred couple (list, dict) containing:
|
||||
|
|
@ -552,16 +552,16 @@ class GroupBlog(object):
|
|||
return d
|
||||
return d.addCallback(self._getOrCountComments, max_comments, profile_key)
|
||||
|
||||
return DeferredItems(self, cb, None, profile_key).get(self.getNodeName(pub_jid), item_ids, rsm=rsm)
|
||||
return DeferredItems(self, cb, None, profile_key).get(self.getNodeName(pub_jid), item_ids, rsm_data=rsm_data)
|
||||
|
||||
def getGroupBlogs(self, pub_jid_s, item_ids=None, rsm=None, count_comments=True, profile_key=C.PROF_KEY_NONE):
|
||||
def getGroupBlogs(self, pub_jid_s, item_ids=None, rsm_data=None, count_comments=True, profile_key=C.PROF_KEY_NONE):
|
||||
"""Get the published microblogs of the specified IDs. If item_ids is
|
||||
None, the result would be the same than calling getGroupBlogs
|
||||
with the default value for the attribute max_items.
|
||||
|
||||
@param pub_jid_s: jid of the publisher
|
||||
@param item_ids: list of microblogs items IDs
|
||||
@param rsm (dict): RSM request data
|
||||
@param rsm_data (dict): RSM request data
|
||||
@param count_comments (bool): also count the comments if True
|
||||
@param profile_key (str): %(doc_profile_key)s
|
||||
@return: a deferred couple (list, dict) containing:
|
||||
|
|
@ -569,9 +569,9 @@ class GroupBlog(object):
|
|||
- RSM response data
|
||||
"""
|
||||
max_comments = 0 if count_comments else DO_NOT_COUNT_COMMENTS
|
||||
return self._getGroupBlogs(pub_jid_s, item_ids=item_ids, rsm=rsm, max_comments=max_comments, profile_key=profile_key)
|
||||
return self._getGroupBlogs(pub_jid_s, item_ids=item_ids, rsm_data=rsm_data, max_comments=max_comments, profile_key=profile_key)
|
||||
|
||||
def getGroupBlogsWithComments(self, pub_jid_s, item_ids=None, rsm=None, max_comments=None, profile_key=C.PROF_KEY_NONE):
|
||||
def getGroupBlogsWithComments(self, pub_jid_s, item_ids=None, rsm_data=None, max_comments=None, profile_key=C.PROF_KEY_NONE):
|
||||
"""Get the published microblogs of the specified IDs and their comments. If
|
||||
item_ids is None, returns the last published microblogs and their comments.
|
||||
|
||||
|
|
@ -589,9 +589,9 @@ class GroupBlog(object):
|
|||
if max_comments is None:
|
||||
max_comments = MAX_COMMENTS
|
||||
assert max_comments > 0 # otherwise the return signature is not the same
|
||||
return self._getGroupBlogs(pub_jid_s, item_ids=item_ids, rsm=rsm, max_comments=max_comments, profile_key=profile_key)
|
||||
return self._getGroupBlogs(pub_jid_s, item_ids=item_ids, rsm_data=rsm_data, max_comments=max_comments, profile_key=profile_key)
|
||||
|
||||
def getGroupBlogsAtom(self, pub_jid_s, rsm=None, profile_key=C.PROF_KEY_NONE):
|
||||
def getGroupBlogsAtom(self, pub_jid_s, rsm_data=None, profile_key=C.PROF_KEY_NONE):
|
||||
"""Get the atom feed of the last published microblogs
|
||||
@param pub_jid: jid of the publisher
|
||||
@param profile_key: profile key
|
||||
|
|
@ -629,10 +629,10 @@ class GroupBlog(object):
|
|||
def cb(items, client):
|
||||
return items2feed(items, pub_jid, client)
|
||||
|
||||
d = DeferredItems(self, cb, lambda dummy: [''], profile_key).get(self.getNodeName(pub_jid), rsm=rsm)
|
||||
d = DeferredItems(self, cb, lambda dummy: [''], profile_key).get(self.getNodeName(pub_jid), rsm_data=rsm_data)
|
||||
return d.addCallback(lambda res: res[0])
|
||||
|
||||
def getGroupBlogComments(self, service_s, node, rsm=None, profile_key=C.PROF_KEY_NONE):
|
||||
def getGroupBlogComments(self, service_s, node, rsm_data=None, profile_key=C.PROF_KEY_NONE):
|
||||
"""Get all comments of given node
|
||||
@param service_s: service hosting the node
|
||||
@param node: comments node
|
||||
|
|
@ -646,14 +646,14 @@ class GroupBlog(object):
|
|||
def cb(items, client):
|
||||
return self._handleCommentsItems(items, service, node)
|
||||
|
||||
return DeferredItems(self, cb, None, profile_key).get(node, rsm=rsm)
|
||||
return DeferredItems(self, cb, None, profile_key).get(node, rsm_data=rsm_data)
|
||||
|
||||
def _getMassiveGroupBlogs(self, publishers_type, publishers, rsm=None, profile_key=C.PROF_KEY_NONE):
|
||||
def _getMassiveGroupBlogs(self, publishers_type, publishers, rsm_data=None, profile_key=C.PROF_KEY_NONE):
|
||||
if publishers_type == 'JID':
|
||||
publishers_jids = [jid.JID(publisher) for publisher in publishers]
|
||||
else:
|
||||
publishers_jids = publishers
|
||||
return self.getMassiveGroupBlogs(publishers_type, publishers_jids, rsm, profile_key)
|
||||
return self.getMassiveGroupBlogs(publishers_type, publishers_jids, rsm_data, profile_key)
|
||||
|
||||
def _getPublishersJIDs(self, publishers_type, publishers, client):
|
||||
#TODO: custom exception
|
||||
|
|
@ -675,11 +675,11 @@ class GroupBlog(object):
|
|||
raise UnknownType
|
||||
return jids
|
||||
|
||||
def getMassiveGroupBlogs(self, publishers_type, publishers, rsm=None, profile_key=C.PROF_KEY_NONE):
|
||||
def getMassiveGroupBlogs(self, publishers_type, publishers, rsm_data=None, profile_key=C.PROF_KEY_NONE):
|
||||
"""Get the last published microblogs for a list of groups or jids
|
||||
@param publishers_type (str): type of the list of publishers (one of "GROUP" or "JID" or "ALL")
|
||||
@param publishers (list): list of publishers, according to publishers_type (list of groups or list of jids)
|
||||
@param rsm (dict): RSM request data, common to all publishers
|
||||
@param rsm_data (dict): RSM request data, common to all publishers
|
||||
@param profile_key: profile key
|
||||
@return: a deferred dict with:
|
||||
- key: publisher (unicode)
|
||||
|
|
@ -692,7 +692,7 @@ class GroupBlog(object):
|
|||
return d.addCallback(self._getOrCountComments, False, profile_key)
|
||||
|
||||
#TODO: we need to use the server corresponding to the host of the jid
|
||||
return DeferredItemsFromMany(self, cb, profile_key).get(publishers_type, publishers, rsm=rsm)
|
||||
return DeferredItemsFromMany(self, cb, profile_key).get(publishers_type, publishers, rsm_data=rsm_data)
|
||||
|
||||
## subscribe ##
|
||||
|
||||
|
|
@ -899,26 +899,26 @@ class DeferredItems():
|
|||
self.eb = (lambda dummy: ([], {})) if eb is None else eb
|
||||
self.profile_key = profile_key
|
||||
|
||||
def get(self, node, item_ids=None, sub_id=None, rsm=None):
|
||||
def get(self, node, item_ids=None, sub_id=None, rsm_data=None):
|
||||
"""Retrieve and process a page of pubsub items
|
||||
|
||||
@param node (str): node identifier.
|
||||
@param item_ids (list[str]): list of items identifiers.
|
||||
@param sub_id (str): optional subscription identifier.
|
||||
@param rsm (dict): RSM request data
|
||||
@param rsm_data (dict): RSM request data
|
||||
@return: a deferred couple (list, dict) containing:
|
||||
- list of microblog data
|
||||
- RSM response data
|
||||
"""
|
||||
if rsm is None:
|
||||
rsm = {'max': (len(item_ids) if item_ids else MAX_ITEMS)}
|
||||
if rsm_data is None:
|
||||
rsm_data = {'max_': (len(item_ids) if item_ids else MAX_ITEMS)}
|
||||
|
||||
def initialised(result):
|
||||
profile, client = result
|
||||
rsm_ = wokkel_rsm.RSMRequest(**rsm)
|
||||
rsm_request = rsm.RSMRequest(**rsm_data)
|
||||
d = self.parent.host.plugins["XEP-0060"].getItems(client.item_access_pubsub,
|
||||
node, rsm_.max,
|
||||
item_ids, sub_id, rsm_,
|
||||
node, rsm_request.max,
|
||||
item_ids, sub_id, rsm_request,
|
||||
profile_key=profile)
|
||||
|
||||
def cb(result):
|
||||
|
|
@ -947,30 +947,30 @@ class DeferredItemsFromMany():
|
|||
jids = self.parent._getPublishersJIDs(publishers_type, publishers, client)
|
||||
return {publisher: self.parent.getNodeName(publisher) for publisher in jids}
|
||||
|
||||
def get(self, publishers_type, publishers, sub_id=None, rsm=None):
|
||||
def get(self, publishers_type, publishers, sub_id=None, rsm_data=None):
|
||||
"""Retrieve and process a page of pubsub items
|
||||
|
||||
@param publishers_type (str): type of the list of publishers (one of "GROUP" or "JID" or "ALL")
|
||||
@param publishers (list): list of publishers, according to publishers_type (list of groups or list of jids)
|
||||
@param sub_id (str): optional subscription identifier.
|
||||
@param rsm (dict): RSM request data
|
||||
@param rsm_data (dict): RSM request data
|
||||
@return: a deferred dict with:
|
||||
- key: publisher (unicode)
|
||||
- value: couple (list[dict], dict) with:
|
||||
- the microblogs data
|
||||
- RSM response data
|
||||
"""
|
||||
if rsm is None:
|
||||
rsm = {'max': MAX_ITEMS}
|
||||
if rsm_data is None:
|
||||
rsm_data = {'max_': MAX_ITEMS}
|
||||
|
||||
def initialised(result):
|
||||
profile, client = result
|
||||
|
||||
data = self._buildData(publishers_type, publishers, client)
|
||||
rsm_ = wokkel_rsm.RSMRequest(**rsm)
|
||||
rsm_request = rsm.RSMRequest(**rsm_data)
|
||||
d = self.parent.host.plugins["XEP-0060"].getItemsFromMany(client.item_access_pubsub,
|
||||
data, rsm_.max, sub_id,
|
||||
rsm_, profile_key=profile)
|
||||
data, rsm_request.max, sub_id,
|
||||
rsm_request, profile_key=profile)
|
||||
|
||||
def cb(publisher):
|
||||
def callback(result):
|
||||
|
|
|
|||
|
|
@ -223,7 +223,7 @@ class XEP_groupblogTest(helpers.SatTestCase):
|
|||
def test_getGroupBlogsWithRSM(self):
|
||||
self._initialise(C.PROFILE[0])
|
||||
d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1])
|
||||
d.addCallback(lambda dummy: self.plugin.getGroupBlogs(PUBLISHER, rsm={'max': 1}, profile_key=C.PROFILE[0]))
|
||||
d.addCallback(lambda dummy: self.plugin.getGroupBlogs(PUBLISHER, rsm_data={'max_': 1}, profile_key=C.PROFILE[0]))
|
||||
result = ([ITEM_DATA_1()], {'count': '1', 'index': '0', 'first': ITEM_ID_1, 'last': ITEM_ID_1})
|
||||
return d.addCallback(self.assertEqual, result)
|
||||
|
||||
|
|
@ -251,7 +251,7 @@ class XEP_groupblogTest(helpers.SatTestCase):
|
|||
def test_getGroupBlogsAtom(self):
|
||||
self._initialise(C.PROFILE[0])
|
||||
d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1])
|
||||
d.addCallback(lambda dummy: self.plugin.getGroupBlogsAtom(PUBLISHER, {'max': 1}, profile_key=C.PROFILE[0]))
|
||||
d.addCallback(lambda dummy: self.plugin.getGroupBlogsAtom(PUBLISHER, {'max_': 1}, profile_key=C.PROFILE[0]))
|
||||
|
||||
def cb(atom):
|
||||
self.assertIsInstance(atom, unicode)
|
||||
|
|
@ -262,7 +262,7 @@ class XEP_groupblogTest(helpers.SatTestCase):
|
|||
def test_getMassiveGroupBlogs(self):
|
||||
self._initialise(C.PROFILE[0])
|
||||
d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1])
|
||||
d.addCallback(lambda dummy: self.plugin.getMassiveGroupBlogs('JID', [jid.JID(PUBLISHER)], {'max': 1}, profile_key=C.PROFILE[0]))
|
||||
d.addCallback(lambda dummy: self.plugin.getMassiveGroupBlogs('JID', [jid.JID(PUBLISHER)], {'max_': 1}, profile_key=C.PROFILE[0]))
|
||||
result = {PUBLISHER: ([ITEM_DATA_1()], {'count': '1', 'index': '0', 'first': ITEM_ID_1, 'last': ITEM_ID_1})}
|
||||
|
||||
def clean(res):
|
||||
|
|
@ -276,7 +276,7 @@ class XEP_groupblogTest(helpers.SatTestCase):
|
|||
self._initialise(C.PROFILE[0])
|
||||
d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1])
|
||||
d.addCallback(lambda dummy: self.psclient.publish(SERVICE, COMMENTS_NODE_ID_1, [COMMENT_1, COMMENT_2]))
|
||||
d.addCallback(lambda dummy: self.plugin.getMassiveGroupBlogs('JID', [jid.JID(PUBLISHER)], {'max': 1}, profile_key=C.PROFILE[0]))
|
||||
d.addCallback(lambda dummy: self.plugin.getMassiveGroupBlogs('JID', [jid.JID(PUBLISHER)], {'max_': 1}, profile_key=C.PROFILE[0]))
|
||||
result = {PUBLISHER: ([ITEM_DATA_1(2)], {'count': '1', 'index': '0', 'first': ITEM_ID_1, 'last': ITEM_ID_1})}
|
||||
|
||||
def clean(res):
|
||||
|
|
@ -290,7 +290,7 @@ class XEP_groupblogTest(helpers.SatTestCase):
|
|||
self._initialise(C.PROFILE[0])
|
||||
d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1])
|
||||
d.addCallback(lambda dummy: self.psclient.publish(SERVICE, COMMENTS_NODE_ID_1, [COMMENT_1]))
|
||||
d.addCallback(lambda dummy: self.plugin.getGroupBlogComments(SERVICE, COMMENTS_NODE_ID_1, {'max': 1}, profile_key=C.PROFILE[0]))
|
||||
d.addCallback(lambda dummy: self.plugin.getGroupBlogComments(SERVICE, COMMENTS_NODE_ID_1, {'max_': 1}, profile_key=C.PROFILE[0]))
|
||||
result = ([COMMENT_DATA_1], {'count': '1', 'index': '0', 'first': COMMENT_ID_1, 'last': COMMENT_ID_1})
|
||||
return d.addCallback(self.assertEqual, result)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue