Changeset 212:af4ef4a0fd7f for wokkel


Ignore:
Timestamp:
Oct 3, 2016, 9:33:18 AM (4 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Replace basestring with StringType and add tests.

Location:
wokkel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wokkel/pubsub.py

    r202 r212  
    1717from twisted.internet import defer
    1818from twisted.python import log
    19 from twisted.python.compat import iteritems, unicode
     19from twisted.python.compat import StringType, iteritems, unicode
    2020from twisted.words.protocols.jabber import jid, error
    2121from twisted.words.xish import domish
     
    182182            self['id'] = id
    183183        if payload is not None:
    184             if isinstance(payload, basestring):
     184            if isinstance(payload, StringType):
    185185                self.addRawXml(payload)
    186186            else:
  • wokkel/test/test_pubsub.py

    r202 r212  
    115115        element = subscription.toElement()
    116116        self.assertEqual('1234', element.getAttribute('subid'))
     117
     118
     119
     120class ItemTests(unittest.TestCase):
     121    """
     122    Tests for L{pubsub.Item}.
     123    """
     124
     125    def test_payloadRaw(self):
     126        """
     127        Adding a payload as a string assumes serialized XML.
     128        """
     129        payload = "<test xmlns='foo'/>"
     130        item = pubsub.Item(payload=payload)
     131        self.assertEqual(payload, item.children[0])
     132
     133
     134    def test_payloadElement(self):
     135        """
     136        Adding a payload as an domish Element, just adds that element as child.
     137        """
     138        payload = domish.Element(('foo', 'test'))
     139        item = pubsub.Item(payload=payload)
     140        self.assertIs(payload, item.children[0])
    117141
    118142
Note: See TracChangeset for help on using the changeset viewer.