def test_header_unmarshalling(self): client = scio.Client( helpers.support('adwords_trafficestimatorservice.wsdl', 'r')) response = helpers.support('adwords_response_example.xml', 'r').read() result, headers = client.handle_response( client.service.estimateKeywordList.method, response) print result print headers assert headers['operations'] == 1 assert headers['responseTime'] == 10636 assert headers['units'] == 1 assert 'eb21e6667abb131c117b58086f75abbd' in headers['requestId']
def test_list_unmarshalling(): lw = scio.Client(helpers.support('lyrics.wsdl', 'r')) rsp = etree.fromstring(helpers.support('lyric_rsp.xml', 'r').read())[0][0] print rsp artist, albums = lw.service.getArtist.method.output(rsp) print artist, albums assert albums eq_(len(albums), 22) boy = albums[0] eq_(boy.album, u'Boy') eq_(boy.year, 1980) eq_(len(boy.songs), 11) eq_(boy.songs[0], u'I Will Follow') eq_(boy.songs[10], u'Shadows And Tall Trees')
def test_list_unmarshalling(): lw = scio.Client(helpers.support('lyrics.wsdl', 'r')) rsp = etree.fromstring(helpers.support('lyric_rsp.xml', 'r').read())[0][0] print rsp artist, albums = lw.service.getArtist.method.output(rsp) print artist, albums assert albums eq_(len(albums), 22) boy = albums[0] eq_(boy.album, u'Boy'); eq_(boy.year, 1980) eq_(len(boy.songs), 11) eq_(boy.songs[0], u'I Will Follow') eq_(boy.songs[10], u'Shadows And Tall Trees')
def test_iter_empty(): lw = scio.Client(helpers.support('lyrics.wsdl')) song = lw.type.SongResult() c = 0 for p in song: c += 1 assert c == 0, "Empty type iter yielded items"
def test_iter_over_self(): lw = scio.Client(helpers.support('lyrics.wsdl')) song = lw.type.SongResult(artist='Prince', song='Nothing Compares 2 U') c = 0 for s in song: assert s.song == 'Nothing Compares 2 U' c += 1 assert c == 1, "Self iter yield <> 1 item"
def test_fault_includes_detail_if_set(): try: lw = scio.Client(helpers.support('lyrics.wsdl', 'r')) fr = """<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><env:Header></env:Header><env:Body><env:Fault xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><faultcode>env:Server</faultcode><faultstring>java.lang.NullPointerException</faultstring><detail>Got bitten by monkey</detail></env:Fault></env:Body></env:Envelope>""" e = HTTPError("http://foo", 500, "Server Error", {}, StringIO(fr)) lw.handle_error(lw.service.getArtist.method, e) except scio.Fault, f: print str(f) assert f.detail
def test_instantiate_complex_type_with_dict(): lw = scio.Client(helpers.support('lyrics.wsdl')) album = lw.type.AlbumResult({ 'artist': 'Wilco', 'album': 'Summerteeth', 'year': 1999 }) assert album.artist == 'Wilco' assert album.album == 'Summerteeth' assert album.year == 1999
def test_rpc_enc_includes_type_attrib(): lw = scio.Client(helpers.support("lyrics.wsdl", "r")) req = lw.service.checkSongExists.method.input("prince", "1999").toxml() c = etree.Element("c") for e in req: c.append(e) req_xml = etree.tostring(c) print req_xml artist = c[0][0] print artist.attrib assert artist.attrib
def test_rpc_enc_includes_type_attrib(): lw = scio.Client(helpers.support('lyrics.wsdl', 'r')) req = lw.service.checkSongExists.method.input('prince', '1999').toxml() c = etree.Element('c') for e in req: c.append(e) req_xml = etree.tostring(c) print req_xml artist = c[0][0] print artist.attrib assert artist.attrib
def test_pickle_unpickle_array(): rsp = etree.fromstring(helpers.support("lyric_rsp.xml", "r").read())[0][0] print rsp artist, albums = lw.service.getArtist.method.output(rsp) boy = albums[0] pickled_boy = dumps(boy) unpickled_boy = loads(pickled_boy) eq_(unpickled_boy.album, u"Boy") eq_(unpickled_boy.year, 1980) eq_(len(unpickled_boy.songs), 11) eq_(unpickled_boy.songs[0], u"I Will Follow") eq_(unpickled_boy.songs[10], u"Shadows And Tall Trees")
def test_pickle_unpickle_array(): rsp = etree.fromstring(helpers.support('lyric_rsp.xml', 'r').read())[0][0] print rsp artist, albums = lw.service.getArtist.method.output(rsp) boy = albums[0] pickled_boy = dumps(boy) unpickled_boy = loads(pickled_boy) eq_(unpickled_boy.album, u'Boy'); eq_(unpickled_boy.year, 1980) eq_(len(unpickled_boy.songs), 11) eq_(unpickled_boy.songs[0], u'I Will Follow') eq_(unpickled_boy.songs[10], u'Shadows And Tall Trees')
def test_serviced_accounts_service(self): # checking that elements in request are produced with # the correct namespaces attached. client = self.clientClass( helpers.support('ServicedAccountService.wsdl', 'r')) asel = client.type.ServicedAccountSelector( enablePaging=False) client.service.get(selector=asel, **self.headers) request = StubClient.sent[0][1].data print request parsed = etree.fromstring(request) assert parsed.find('.//{%s}authToken' % self.cm_tns) is not None assert parsed.find('.//{%s}authToken' % self.cm_tns).text == self.auth_token assert parsed.find('.//{%s}RequestHeader' % self.mcm_tns) is not None
def test_get_all_campaigns(self): client = self.clientClass(helpers.support('adwords_campaignservice.wsdl', 'r')) client.service.getAllAdWordsCampaigns(dummy=0, useragent="foo (mozilla)", email="*****@*****.**", clientEmail="*****@*****.**", clientCustomerId="5", developerToken="99dt", applicationToken="12at") request = StubClient.sent[0][1].data print request assert 'getAllAdWordsCampaigns' in request parsed = etree.fromstring(request) assert parsed[1][0][0].tag == '{https://adwords.google.com/api/adwords/v12}dummy'
def test_infoservice_daterange_namespace(self): client = self.clientClass(helpers.support('InfoService.wsdl', 'r')) isel = client.type.InfoSelector( dateRange=client.type.DateRange( min='20111101', max='20111130'), apiUsageType='UNIT_COUNT') eq_(client.type.InfoSelector._namespace, "https://adwords.google.com/api/adwords/info/v201101") # container assigned to part in new namespace takes on # namespace from the context it is assigned to eq_(isel.dateRange._namespace, "https://adwords.google.com/api/adwords/info/v201101") # ... items in the type container keep their namespace eq_(isel.dateRange.min._namespace, "https://adwords.google.com/api/adwords/cm/v201101")
def test_method_call_with_headers(self): client = self.clientClass(helpers.support('adwords_campaignservice.wsdl', 'r')) client.service.getCampaign(id=1, useragent="foo (mozilla)", email="*****@*****.**", clientEmail="*****@*****.**", clientCustomerId="5", developerToken="99dt", applicationToken="12at" ) print StubClient.sent request = StubClient.sent[0][1].data print request assert 'email>' in request assert '*****@*****.**' in request assert '99dt' in request assert '12at' in request assert 'foo (mozilla)'
def test_handle_error_raises_fault(): lw = scio.Client(helpers.support('lyrics.wsdl', 'r')) fr = """<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><env:Header></env:Header><env:Body><env:Fault xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><faultcode>env:Server</faultcode><faultstring>java.lang.NullPointerException</faultstring></env:Fault></env:Body></env:Envelope>""" e = HTTPError("http://foo", 500, "Server Error", {}, StringIO(fr)) lw.handle_error(lw.service.getArtist.method, e)
def test_array_detection(): lw = scio.client.Factory(helpers.support('lyrics.wsdl', 'r')) aos = lw.wsdl.xpath("//*[@name='ArrayOfstring']")[0] print aos assert lw._is_array(aos)
def test_empty_complextype_not_true(): lw = scio.Client(helpers.support('lyrics.wsdl')) song = lw.type.SongResult() assert not song
def mock_urlopen(url): fn = url.split('/')[-1] return helpers.support(fn, 'r')
def test_deserialize_boyzoid_response(): response = etree.parse(helpers.support('bz_response.xml', 'r')).getroot() quote = M['bz'].Client().service.getQuote.method.output(response) print quote, quote.item print quote.item[1].value
def test_handle_error_with_blank_body(): lw = scio.Client(helpers.support('lyrics.wsdl', 'r')) fr = "<a/>" e = HTTPError("http://foo", 500, "Server Error", {}, StringIO(fr)) lw.handle_error(lw.service.getArtist.method, e)
def test_parse_adwords(self): self.clientClass(helpers.support('adwords_campaignservice.wsdl', 'r'))
def test_instantiate_complex_type_with_string(): snx = scio.Client(helpers.support('synxis.wsdl')) price = snx.type.MarketSegment('Irate organists', MarketSegmentCode='IRO') assert price._content == 'Irate organists' assert price.MarketSegmentCode == 'IRO'
def check(wsdl): code = gen.gen(client.Client(helpers.support(wsdl))) ns = {} print code exec code in ns
def transport(req): return helpers.support('NilDateResp.xml', 'r')
def test_no_soap_body_in_xml_response_raises_notsoap(): lw = scio.Client(helpers.support('lyrics.wsdl', 'r')) er = "<a/>" lw.handle_response(None, er)
def setUp(self): self.urlopen = scio.client.urlopen scio.client.urlopen = mock_urlopen self.client = scio.client.Client( helpers.support('CampaignManagementService.wsdl', 'r'))
def test_parse_jira(): client = scio.Client(helpers.support('jira.wsdl', 'r'))
e = HTTPError("http://foo", 500, "Server Error", {}, StringIO(fr)) lw.handle_error(lw.service.getArtist.method, e) def test_fault_includes_detail_if_set(): try: lw = scio.Client(helpers.support('lyrics.wsdl', 'r')) fr = """<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><env:Header></env:Header><env:Body><env:Fault xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><faultcode>env:Server</faultcode><faultstring>java.lang.NullPointerException</faultstring><detail>Got bitten by monkey</detail></env:Fault></env:Body></env:Envelope>""" e = HTTPError("http://foo", 500, "Server Error", {}, StringIO(fr)) lw.handle_error(lw.service.getArtist.method, e) except scio.Fault, f: print str(f) assert f.detail try: lw = scio.Client(helpers.support('lyrics.wsdl', 'r')) fr = """<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><env:Header></env:Header><env:Body><env:Fault xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><faultcode>env:Server</faultcode><faultstring>java.lang.NullPointerException</faultstring></env:Fault></env:Body></env:Envelope>""" e = HTTPError("http://foo", 500, "Server Error", {}, StringIO(fr)) lw.handle_error(lw.service.getArtist.method, e) except scio.Fault, f: print str(f) assert not f.detail def test_instantiate_complex_type_with_string(): snx = scio.Client(helpers.support('synxis.wsdl')) price = snx.type.MarketSegment('Irate organists', MarketSegmentCode='IRO') assert price._content == 'Irate organists' assert price.MarketSegmentCode == 'IRO'
def test_calls_get_foo(): c = FooingClient(helpers.support('lyrics.wsdl')) c.service.getArtist('U2', foo='electric!')
def test_enum_restriction_not_first_element(): zf = scio.Client(helpers.support('zfapi.wsdl', 'r')) print zf.type.ApiAccessMask._values assert zf.type.ApiAccessMask._values
def test_deserialize_boyzoid_response(): client = scio.Client(helpers.support('boyzoid.wsdl', 'r')) response = etree.parse(helpers.support('bz_response.xml', 'r')).getroot() quote = client.service.getQuote.method.output(response) print quote, quote.item print quote.item[1].value
def test_parse_shoppingservice(): client = scio.Client(helpers.support('shoppingservice.wsdl', 'r'))
def test_parse_ebaysvc(): st = time.time() client = scio.Client(helpers.support('eBaySvc.wsdl', 'r')) taken = time.time() - st print "parsed 4.2mb wsdl in", taken
import scio import helpers from lxml import etree def transport(req): return helpers.support('NilDateResp.xml', 'r') client = scio.Client(helpers.support('NilDate.wsdl', 'r'), transport=transport) def test_simple_date(): notnil = client.type.getNilDateResponse('2013-03-05') assert notnil.year == 2013 assert notnil.month == 3 assert notnil.day == 5 def test_nil_simple_date(): nil = client.type.getNilDateResponse() assert nil is None def test_simple_datetime(): notnil = client.type.getNilDateTimeResponse('2013-03-05T12:01:02') assert notnil.year == 2013 assert notnil.month == 3 assert notnil.day == 5 assert notnil.hour == 12
def test_instantiate_complex_type_with_dict(): lw = scio.Client(helpers.support('lyrics.wsdl')) album = lw.type.AlbumResult({'artist': 'Wilco', 'album': 'Summerteeth', 'year': 1999}) assert album.artist == 'Wilco' assert album.album == 'Summerteeth' assert album.year == 1999