예제 #1
0
    def test_setItemIgnoreAttributes(self):
        """
        Certain attributes should be rendered for roster set.
        """
        item = xmppim.RosterItem(JID('*****@*****.**'),
                                 subscriptionTo=True,
                                 subscriptionFrom=False,
                                 name='Joe User',
                                 groups=set(['Friends', 'Jabber']))
        item.pendingOut = True
        item.approved = True
        d = self.service.setItem(item)

        # Inspect outgoing iq request

        iq = self.stub.output[-1]
        self.assertEqual('set', iq.getAttribute('type'))
        self.assertNotIdentical(None, iq.query)
        self.assertEqual(NS_ROSTER, iq.query.uri)

        children = list(
            domish.generateElementsQNamed(iq.query.children, 'item',
                                          NS_ROSTER))
        self.assertEqual(1, len(children))
        child = children[0]
        self.assertIdentical(None, child.getAttribute('ask'))
        self.assertIdentical(None, child.getAttribute('approved'))
        self.assertIdentical(None, child.getAttribute('subscription'))

        # Fake successful response

        response = toResponse(iq, 'result')
        d.callback(response)
        return d
예제 #2
0
 def test_toElementName(self):
     """
     A roster item's name is rendered to the 'name' attribute.
     """
     item = xmppim.RosterItem(JID('*****@*****.**'), name='Joe User')
     element = item.toElement()
     self.assertEqual(u'Joe User', element.getAttribute('name'))
예제 #3
0
    def test_setItem(self):
        """
        Setting a roster item renders the item and sends it out.
        """
        item = xmppim.RosterItem(JID('*****@*****.**'),
                                 name='Joe User',
                                 groups=set(['Friends', 'Jabber']))
        d = self.service.setItem(item)

        # Inspect outgoing iq request

        iq = self.stub.output[-1]
        self.assertEqual('set', iq.getAttribute('type'))
        self.assertNotIdentical(None, iq.query)
        self.assertEqual(NS_ROSTER, iq.query.uri)

        children = list(
            domish.generateElementsQNamed(iq.query.children, 'item',
                                          NS_ROSTER))
        self.assertEqual(1, len(children))
        child = children[0]
        self.assertEqual('*****@*****.**', child['jid'])
        self.assertIdentical(None, child.getAttribute('subscription'))

        # Fake successful response

        response = toResponse(iq, 'result')
        d.callback(response)
        return d
예제 #4
0
 def test_toElementMinimal(self):
     """
     A bare roster item only has a jid attribute.
     """
     item = xmppim.RosterItem(JID('*****@*****.**'))
     element = item.toElement()
     self.assertEqual(u'*****@*****.**', element.getAttribute('jid'))
예제 #5
0
 def test_toElementApproved(self):
     """
     A pre-approved subscription for a roster item has an 'approved' flag.
     """
     item = xmppim.RosterItem(JID('*****@*****.**'))
     item.approved = True
     element = item.toElement()
     self.assertEqual(u'true', element.getAttribute('approved'))
예제 #6
0
 def test_toElementAsk(self):
     """
     A roster item with pendingOut set has subscription 'ask'.
     """
     item = xmppim.RosterItem(JID('*****@*****.**'))
     item.pendingOut = True
     element = item.toElement()
     self.assertEqual('subscribe', element.getAttribute('ask'))
예제 #7
0
 def test_toElementSubscriptionRemove(self):
     """
     A roster item with remove set has subscription 'remove'.
     """
     item = xmppim.RosterItem(JID('*****@*****.**'))
     item.remove = True
     element = item.toElement()
     self.assertEqual('remove', element.getAttribute('subscription'))
예제 #8
0
 def test_toElementSubscriptionBoth(self):
     """
     A roster item with mutual subscription has subscription 'both'.
     """
     item = xmppim.RosterItem(JID('*****@*****.**'),
                              subscriptionTo=True,
                              subscriptionFrom=True)
     element = item.toElement()
     self.assertEqual('both', element.getAttribute('subscription'))
예제 #9
0
 def test_toElementSubscriptionFrom(self):
     """
     A roster item with subscriptionFrom set has subscription 'to'.
     """
     item = xmppim.RosterItem(JID('*****@*****.**'),
                              subscriptionTo=False,
                              subscriptionFrom=True)
     element = item.toElement()
     self.assertEqual('from', element.getAttribute('subscription'))
예제 #10
0
 def test_toElementSubscriptionNone(self):
     """
     A roster item with no subscription has no subscription attribute.
     """
     item = xmppim.RosterItem(JID('*****@*****.**'),
                              subscriptionTo=False,
                              subscriptionFrom=False)
     element = item.toElement()
     self.assertIdentical(None, element.getAttribute('subscription'))
예제 #11
0
 def test_toElementItem(self):
     """
     If an item is set, it is rendered as a child of the query.
     """
     request = xmppim.RosterRequest()
     request.item = xmppim.RosterItem(JID('*****@*****.**'))
     element = request.toElement()
     children = element.query.elements()
     child = next(children)
     self.assertEqual(NS_ROSTER, child.uri)
     self.assertEqual('item', child.name)
예제 #12
0
 def test_askDeprecationSet(self):
     """
     Setting the ask attribute works as entity and warns deprecation.
     """
     item = xmppim.RosterItem(JID('*****@*****.**'))
     self.assertWarns(
         DeprecationWarning, "wokkel.xmppim.RosterItem.ask was "
         "deprecated in Wokkel 0.7.1; "
         "please use RosterItem.pendingOut instead.", xmppim.__file__,
         setattr, item, 'ask', True)
     self.assertTrue(item.pendingOut)
예제 #13
0
 def test_jidDeprecationSet(self):
     """
     Setting the jid attribute works as entity and warns deprecation.
     """
     item = xmppim.RosterItem(JID('*****@*****.**'))
     self.assertWarns(
         DeprecationWarning, "wokkel.xmppim.RosterItem.jid was deprecated "
         "in Wokkel 0.7.1; "
         "please use RosterItem.entity instead.", xmppim.__file__, setattr,
         item, 'jid', JID('*****@*****.**'))
     self.assertEqual(JID('*****@*****.**'), item.entity)
예제 #14
0
 def test_jidDeprecationGet(self):
     """
     Getting the jid attribute works as entity and warns deprecation.
     """
     item = xmppim.RosterItem(JID('*****@*****.**'))
     entity = self.assertWarns(
         DeprecationWarning, "wokkel.xmppim.RosterItem.jid was "
         "deprecated in Wokkel 0.7.1; "
         "please use RosterItem.entity instead.", xmppim.__file__, getattr,
         item, 'jid')
     self.assertIdentical(entity, item.entity)
예제 #15
0
 def test_toElement(self):
     """
     A roster item has the correct namespace/name, lacks unset attributes.
     """
     item = xmppim.RosterItem(JID('*****@*****.**'))
     element = item.toElement()
     self.assertEqual('item', element.name)
     self.assertEqual(NS_ROSTER, element.uri)
     self.assertFalse(element.hasAttribute('subscription'))
     self.assertFalse(element.hasAttribute('ask'))
     self.assertEqual(u"", element.getAttribute('name', u""))
     self.assertFalse(element.hasAttribute('approved'))
     self.assertEquals(0, len(list(element.elements())))
예제 #16
0
    def test_toElementGroups(self):
        """
        A roster item's groups are rendered as 'group' child elements.
        """
        groups = set(['Friends', 'Jabber'])
        item = xmppim.RosterItem(JID('*****@*****.**'), groups=groups)

        element = item.toElement()
        foundGroups = set()
        for child in element.elements():
            if child.uri == NS_ROSTER and child.name == 'group':
                foundGroups.add(unicode(child))

        self.assertEqual(groups, foundGroups)