Source

osa / tests / test_wsdl.py

#!/usr/bin/env python
# test_wsdl.py - test WSDLParser class, part of osa.
# Copyright 2013 Sergey Bozhenkov, boz at ipp.mpg.de
# Licensed under GPLv3 or later, see the COPYING file.

import sys
for x in sys.path:
    if x.find("osa") != -1:
        sys.path.remove(x)
sys.path.append("../")

import unittest
import xml.etree.cElementTree as etree
from osa.wsdl import *
from osa.method import * 
from osa.message import * 
from osa.xmltypes import *

wsdl_url = 'test.wsdl'
ns1 = "de.mpg.ipp.hgw.boz.gsoap.helloworld"
ns2 = "de.mpg.ipp.hgw.boz.gsoap.helloworld.types"

class TestWSDL(unittest.TestCase):
    def test_reading(self):
        w = WSDLParser(wsdl_url)
        self.assertEquals(w.wsdl_url, wsdl_url)
        self.assertEquals(w.tns, "de.mpg.ipp.hgw.boz.gsoap.helloworld")
        self.assertEquals(type(w.wsdl), type(etree.Element('root')))

    def test_get_types(self):
        w = WSDLParser(wsdl_url)
        types = w.get_types()
        self.assertTrue('{%s}Name' %ns2 in types.keys())
        self.assertTrue('{%s}Person' %ns2 in types.keys())
        self.assertTrue('{%s}echoString' %ns1 in types.keys())
        self.assertTrue('{%s}faultyThing' %ns1 in types.keys())
        self.assertTrue('{%s}testMe' %ns1 in types.keys())
        self.assertTrue('{%s}sayHello' %ns1 in types.keys())
        self.assertTrue('{%s}echoStringResponse' %ns1 in types.keys())
        self.assertTrue('{%s}faultyThingResponse' %ns1 in types.keys())
        self.assertTrue('{%s}sayHelloResponse' %ns1 in types.keys())
        self.assertTrue(types['{%s}Name' %ns2], 'firstName')
        self.assertTrue(types['{%s}Name' %ns2], 'lastName')
        self.assertTrue(types['{%s}Person' %ns2], 'name')
        self.assertTrue(types['{%s}Person' %ns2], 'age')
        self.assertTrue(types['{%s}Person' %ns2], 'height')
        self.assertTrue(types['{%s}Person' %ns2], 'weight')
        self.assertTrue(types['{%s}Person' %ns2]._children[3]['name'] == "name")
        self.assertTrue(types['{%s}Person' %ns2]._children[0]['name'] == "age")
        self.assertTrue(types['{%s}Person' %ns2]._children[3]['type'] == types['{%s}Name' %ns2])
        self.assertTrue(types['{%s}Person' %ns2]._children[0]['type'] == xmltypes.XMLInteger)
        self.assertTrue(types['{%s}sayHello' %ns1], 'person')
        self.assertTrue(types['{%s}sayHello' %ns1], 'times')
        self.assertTrue(types['{%s}sayHello' %ns1]._children[0]['name'] == "person")
        self.assertTrue(types['{%s}sayHello' %ns1]._children[1]['name'] == "times")
        self.assertTrue(types['{%s}sayHello' %ns1]._children[0]['type'] == types['{%s}Person' %ns2])
        self.assertTrue(types['{%s}sayHello' %ns1]._children[1]['type'] == xmltypes.XMLInteger)

    def test_get_messages(self):
        w = WSDLParser(wsdl_url)
        types = w.get_types()
        msgs = w.get_messages(types)
        names = ("testMe", "giveMessageRequest",
                 "giveMessageResponse", "echoStringRequest",
                 "echoStringResponse", "faultyThingRequest",
                 "faultyThingResponse", "sayHello",
                 "sayHelloResponse")
        for n in names:
            self.assertTrue(msgs.has_key("{%s}%s" %(ns1, n)))
            m = msgs["{%s}%s" %(ns1, n)]
            self.assertTrue(isinstance(m, Message))
            self.assertEquals(m.name, "{%s}%s" %(ns1, n))
            self.assertEquals(len(m.parts), 1)
            self.assertEquals(len(m.parts[0]), 2)
            self.assertEquals(m.parts[0][0], "parameters")

    def test_get_operations(self):
        w = WSDLParser(wsdl_url)
        types = w.get_types()
        msgs = w.get_messages(types)
        ops = w.get_operations(msgs)
        self.assertTrue(ops.has_key("{%s}HelloWorldServicePortType" %ns1))
        ops = ops["{%s}HelloWorldServicePortType" %ns1]
        names = ("testMe", "giveMessage", "echoString", "faultyThing", "sayHello")
        for n in names:
            self.assertTrue(ops.has_key(n))
            op = ops[n]
            self.assertTrue(isinstance(op, Method))
            self.assertTrue(isinstance(op.input, Message))
            if n != "testMe":
                self.assertTrue(isinstance(op.output, Message))

        self.assertTrue(ops["testMe"].input is msgs["{%s}testMe" %ns1])
        self.assertTrue(ops["giveMessage"].input is msgs["{%s}giveMessageRequest" %ns1])
        self.assertTrue(ops["giveMessage"].output is msgs["{%s}giveMessageResponse" %ns1])
        self.assertTrue(ops["echoString"].input is msgs["{%s}echoStringRequest" %ns1])
        self.assertTrue(ops["echoString"].output is msgs["{%s}echoStringResponse" %ns1])
        self.assertTrue(ops["faultyThing"].input is msgs["{%s}faultyThingRequest" %ns1])
        self.assertTrue(ops["faultyThing"].output is msgs["{%s}faultyThingResponse" %ns1])
        self.assertTrue(ops["sayHello"].input is msgs["{%s}sayHello" %ns1])
        self.assertTrue(ops["sayHello"].output is msgs["{%s}sayHelloResponse" %ns1])

    def test_get_bindings(self):
        w = WSDLParser(wsdl_url)
        types = w.get_types()
        msgs = w.get_messages(types)
        ops = w.get_operations(msgs)
        bs = w.get_bindings(ops)
        ops = ops["{%s}HelloWorldServicePortType" %ns1]
        self.assertTrue(bs.has_key("{%s}HelloWorldService" %ns1))
        bs = bs["{%s}HelloWorldService" %ns1]
        names = ("testMe", "giveMessage", "echoString", "faultyThing", "sayHello")
        for n in names:
            self.assertTrue(bs.has_key(n))
            b = bs[n]
            op = ops[n]
            self.assertTrue(b is op)
            self.assertTrue(b.input.use_parts is not None)
            self.assertEquals(len(b.input.use_parts), 1)
            self.assertEquals(b.input.use_parts[0][0], "parameters")
            if n != "testMe":
                self.assertEquals(len(b.output.use_parts), 1)
                self.assertEquals(b.output.use_parts[0][0], "parameters")
            self.assertEquals(b.action, "")

    def test_get_services(self):
        w = WSDLParser(wsdl_url)
        types = w.get_types()
        msgs = w.get_messages(types)
        ops = w.get_operations(msgs)
        bs = w.get_bindings(ops)
        ss = w.get_services(bs)
        bs = bs["{%s}HelloWorldService" %ns1]
        self.assertTrue(ss.has_key("HelloWorldService"))
        ss = ss["HelloWorldService"]
        names = ("testMe", "giveMessage", "echoString", "faultyThing", "sayHello")
        for n in names:
            self.assertTrue(ss.has_key(n))
            s = ss[n]
            b = bs[n]
            self.assertTrue(s is b)
            self.assertEquals(s.location, "http://lxpowerboz:88/services/cpp/HelloWorldService")


if __name__ == '__main__':
    unittest.main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.