Changeset 89:2a23913093ec


Ignore:
Timestamp:
Feb 25, 2010, 10:42:19 AM (11 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Complete test coverage for Service Discovery.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/test/test_disco.py

    r67 r89  
    1010from twisted.internet import defer
    1111from twisted.trial import unittest
     12from twisted.words.protocols.jabber.error import StanzaError
    1213from twisted.words.protocols.jabber.jid import JID
    1314from twisted.words.protocols.jabber.xmlstream import toResponse
    14 from twisted.words.xish import domish
     15from twisted.words.xish import domish, utility
    1516
    1617from wokkel import data_form, disco
     
    597598
    598599
     600    def test_connectionInitializedObserveInfo(self):
     601        """
     602        An observer for Disco Info requests is setup on stream initialization.
     603        """
     604        xml = """<iq from='test@example.com' to='example.com'
     605                     type='get'>
     606                   <query xmlns='%s'/>
     607                 </iq>""" % NS_DISCO_INFO
     608
     609        def handleRequest(iq):
     610            called.append(iq)
     611
     612        called = []
     613        self.service.xmlstream = utility.EventDispatcher()
     614        self.service.handleRequest = handleRequest
     615        self.service.connectionInitialized()
     616        self.service.xmlstream.dispatch(parseXml(xml))
     617        self.assertEqual(1, len(called))
     618
     619
     620    def test_connectionInitializedObserveItems(self):
     621        """
     622        An observer for Disco Items requests is setup on stream initialization.
     623        """
     624        xml = """<iq from='test@example.com' to='example.com'
     625                     type='get'>
     626                   <query xmlns='%s'/>
     627                 </iq>""" % NS_DISCO_ITEMS
     628
     629        def handleRequest(iq):
     630            called.append(iq)
     631
     632        called = []
     633        self.service.xmlstream = utility.EventDispatcher()
     634        self.service.handleRequest = handleRequest
     635        self.service.connectionInitialized()
     636        self.service.xmlstream.dispatch(parseXml(xml))
     637        self.assertEqual(1, len(called))
     638
     639
    599640    def test_onDiscoInfo(self):
    600641        """
     
    662703
    663704
     705    def test_onDiscoInfoWithNodeNoResults(self):
     706        """
     707        An info request for a node with no results returns items-not-found.
     708        """
     709        xml = """<iq from='test@example.com' to='example.com'
     710                     type='get'>
     711                   <query xmlns='%s' node='test'/>
     712                 </iq>""" % NS_DISCO_INFO
     713
     714        def cb(exc):
     715            self.assertEquals('item-not-found', exc.condition)
     716
     717        def info(requestor, target, nodeIdentifier):
     718            self.assertEqual('test', nodeIdentifier)
     719
     720            return defer.succeed([])
     721
     722        self.service.info = info
     723        d = self.handleRequest(xml)
     724        self.assertFailure(d, StanzaError)
     725        d.addCallback(cb)
     726        return d
     727
     728
    664729    def test_onDiscoItems(self):
    665730        """
Note: See TracChangeset for help on using the changeset viewer.