예제 #1
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')