예제 #1
0
    def test_soap_scpd(self):
        from shtoom.soapsucks import SOAPRequestFactory, BeautifulSax
        ae = self.assertEquals
        ar = self.assertRaises
        schema = "urn:schemas-upnp-org:service:WANIPConnection:1"
        soap = SOAPRequestFactory('http://127.0.0.1:5533/', schema)
        soap.setSCPD(canned_scpd)
        request = soap.GetGenericPortMappingEntry(NewPortMappingIndex=12)
        for k, v in request.headers.items():
            if k.lower() == 'soapaction':
                ae(v, '"%s#GetGenericPortMappingEntry"' % schema)
        body = request.get_data()
        bs = BeautifulSax(body)
        meth = bs.fetch('u:GetGenericPortMappingEntry')
        ae(len(meth), 1)
        meth = meth[0]
        ae(meth['xmlns:u'], schema)
        # strip stupid whitespace text nodes
        meth.contents = [x for x in meth.contents if str(x).strip()]
        ae(len(meth.contents), 1)
        m = meth.contents[0]
        ae(m.name, 'NewPortMappingIndex')
        ae(len(m.contents), 1)
        ae(str(m.contents[0]), '12')

        ar(
            NameError,
            soap.GetNonExistentMethod,
        )
        ar(TypeError, soap.GetGenericPortMappingEntry, a=1, b=2)
        ar(TypeError,
           soap.GetGenericPortMappingEntry,
           NewPortMappingIndex=1,
           b=2)
예제 #2
0
 def handleWanServiceDesc(self, body):
     log.msg("got WANServiceDesc from %s"%(self.urlbase,), system='UPnP')
     data = body.read()
     self.soap = SOAPRequestFactory(self.controlURL,
                         "urn:schemas-upnp-org:service:WANIPConnection:1")
     self.soap.setSCPD(data)
     self.completedDiscovery()
예제 #3
0
파일: test_soap.py 프로젝트: bmxp/shtoom
    def test_soaprequest(self):
        from shtoom.soapsucks import SOAPRequestFactory, BeautifulSax
        ae = self.assertEqual
        schema = "urn:schemas-upnp-org:service:WANIPConnection:1"
        s = SOAPRequestFactory('http://127.0.0.1:5533/', schema)
        request = s.GetGenericPortMappingEntry(NewPortMappingIndex=12)

        for k, v in request.headers.items():
            if k.lower() == 'soapaction':
                ae(v, '"%s#GetGenericPortMappingEntry"' % schema)
        #old body = request.get_data()
        body = request.data
        bs = BeautifulSax(body)
        meth = bs.fetch('u:GetGenericPortMappingEntry')
        ae(len(meth), 1)
        meth = meth[0]
        ae(meth['xmlns:u'], schema)
        # strip stupid whitespace text nodes
        meth.contents = [x for x in meth.contents if str(x).strip()]
        ae(len(meth.contents), 1)
        m = meth.contents[0]
        ae(m.name, 'NewPortMappingIndex')
        ae(len(m.contents), 1)
        ae(str(m.contents[0]), '12')

        request = s.GetTotallyBogusRequest(a='hello', b='goodbye', c=None)
        for k, v in request.headers.items():
            if k.lower() == 'soapaction':
                ae(v, '"%s#GetTotallyBogusRequest"' % schema)
        #old body = request.get_data()
        body = request.data
        bs = BeautifulSax(body)
        meth = bs.fetch('u:GetTotallyBogusRequest')
        ae(len(meth), 1)
        meth = meth[0]
        ae(meth['xmlns:u'], schema)
        # strip stupid whitespace text nodes
        meth.contents = [x for x in meth.contents if str(x).strip()]
        ae(len(meth.contents), 3)
        for m in meth.contents:
            # Argument ordering doesn't matter
            if m.name == 'a':
                ae(len(m.contents), 1)
                ae(str(m.contents[0]), 'hello')
            elif m.name == 'b':
                ae(len(m.contents), 1)
                ae(str(m.contents[0]), 'goodbye')
            elif m.name == 'c':
                ae(len(m.contents), 0)
            else:
                # XXX
                ae('test failed', '%s not one of a,b,c' % (m.name))
        #old ae(request.get_host(), '127.0.0.1:5533')
        ae(request.host, '127.0.0.1:5533')