Exemplo n.º 1
0
    def setUp(self):
        unittest.TestCase.setUp(self)
        self.p = IncrStreamParser()

        pjs.conf.conf.launcher.run()

        self.oldhandlers = copy.deepcopy(handlers.handlers)
Exemplo n.º 2
0
 def setUp(self):
     unittest.TestCase.setUp(self)
     self.p = IncrStreamParser()
     
     pjs.conf.conf.launcher.run()
     
     self.oldhandlers = copy.deepcopy(handlers.handlers)
Exemplo n.º 3
0
class TestParser(unittest.TestCase):
    """Test tree-building of the incremental parser"""
    def setUp(self):
        unittest.TestCase.setUp(self)
        self.p = IncrStreamParser()

        pjs.conf.conf.launcher.run()

        self.oldhandlers = copy.deepcopy(handlers.handlers)

    def tearDown(self):
        unittest.TestCase.tearDown(self)

        try:
            self.p.close()
        except xml.parsers.expat.ExpatError:
            pass

        handlers.handlers = self.oldhandlers

        pjs.conf.conf.launcher.stop()

    def testOpenStream(self):
        """Depth should increase at stream element"""
        self.p.feed(streamStart)
        self.assert_(self.p.depth == 1)
        self.assert_(self.p.tree is None)

    def testOpenCloseStream(self):
        """Testing depth and initialization of tree"""
        self.p.feed(streamStart)
        self.p.feed(streamEnd)
        self.assert_(self.p.depth == 0)
        self.assert_(self.p.tree is None)

    def testSimpleStanza(self):
        """Single-level empty stanza"""
        self.p.feed(streamStart)

        self.p.feed('<stream:features>')
        self.assert_(self.p.depth == 2)
        self.assert_(self.p.tree is not None)

        self.p.feed('</stream:features>')

        # copying for our own use
        self.assert_(
            self.p.tree.tag == '{http://etherx.jabber.org/streams}features')
        self.assert_(self.p.depth == 1)

    def testDeepStanza(self):
        """Multi-level stanza"""
        self.p.feed(streamStart)

        self.p.feed("""<iq type='result' id='bind_2'>\
                      <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'>\
                        <jid>[email protected]/someresource""")
        self.assert_(self.p.depth == 4)

        self.p.feed("</jid></bind></iq>")
        self.assert_(self.p.depth == 1)
        self.assert_(self.p.tree.tag == '{jabber:client}iq')
        self.assert_(
            self.p.tree[0].tag == '{urn:ietf:params:xml:ns:xmpp-bind}bind')
        self.assert_(
            self.p.tree[0][0].text == u'[email protected]/someresource')

    def testNamespacedXPath(self):
        """Should be able to refer to elements using namespaces in XPath"""
        self.p.feed(streamStart)
        self.p.feed('<stream:features></stream:features>')

        stream = Element('dummy')
        stream.insert(0, self.p.tree)

        self.assert_(
            stream.find('{http://etherx.jabber.org/streams}features')
            is not None)
Exemplo n.º 4
0
 def __init__(self):
     IncrStreamParser.__init__(self)
     self.startCalled = False
     self.endCalled = False
     self.textCalled = False
Exemplo n.º 5
0
class TestParser(unittest.TestCase):
    """Test tree-building of the incremental parser"""

    def setUp(self):
        unittest.TestCase.setUp(self)
        self.p = IncrStreamParser()
        
        pjs.conf.conf.launcher.run()
        
        self.oldhandlers = copy.deepcopy(handlers.handlers)
        
    def tearDown(self):
        unittest.TestCase.tearDown(self)
        
        try:
            self.p.close()
        except xml.parsers.expat.ExpatError:
            pass
        
        handlers.handlers = self.oldhandlers
        
        pjs.conf.conf.launcher.stop()
        
    def testOpenStream(self):
        """Depth should increase at stream element"""
        self.p.feed(streamStart)
        self.assert_(self.p.depth == 1)
        self.assert_(self.p.tree is None)
        
    def testOpenCloseStream(self):
        """Testing depth and initialization of tree"""
        self.p.feed(streamStart)
        self.p.feed(streamEnd)
        self.assert_(self.p.depth == 0)
        self.assert_(self.p.tree is None)
        
    def testSimpleStanza(self):
        """Single-level empty stanza"""
        self.p.feed(streamStart)
        
        self.p.feed('<stream:features>')
        self.assert_(self.p.depth == 2)
        self.assert_(self.p.tree is not None)
        
        self.p.feed('</stream:features>')
        
        # copying for our own use
        self.assert_(self.p.tree.tag == '{http://etherx.jabber.org/streams}features')
        self.assert_(self.p.depth == 1)
        
    def testDeepStanza(self):
        """Multi-level stanza"""
        self.p.feed(streamStart)
        
        self.p.feed("""<iq type='result' id='bind_2'>\
                      <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'>\
                        <jid>[email protected]/someresource""")
        self.assert_(self.p.depth == 4)
        
        self.p.feed("</jid></bind></iq>")
        self.assert_(self.p.depth == 1)
        self.assert_(self.p.tree.tag == '{jabber:client}iq')
        self.assert_(self.p.tree[0].tag == '{urn:ietf:params:xml:ns:xmpp-bind}bind')
        self.assert_(self.p.tree[0][0].text == u'[email protected]/someresource')

    def testNamespacedXPath(self):
        """Should be able to refer to elements using namespaces in XPath"""
        self.p.feed(streamStart)
        self.p.feed('<stream:features></stream:features>')
        
        stream = Element('dummy')
        stream.insert(0, self.p.tree)
        
        self.assert_(stream.find('{http://etherx.jabber.org/streams}features') is not None)
Exemplo n.º 6
0
 def __init__(self):
     IncrStreamParser.__init__(self)
     self.startCalled = False
     self.endCalled = False
     self.textCalled = False