import sys sys path append import logging import traceback as tb impor

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import sys
sys.path.append('../')
import logging
import traceback as tb
import suds.metrics as metrics
from tests import *
from suds import WebFault
from suds.client import Client
from suds.sudsobject import Object
from suds.transport.https import HttpAuthenticated
errors = 0
credentials = dict(username='jortel', password='abc123')
setup_logging()
#logging.getLogger('suds.transport').setLevel(logging.DEBUG)
def start(url):
global errors
print '\n________________________________________________________________\n'
print 'Test @ ( %s )\nerrors = %d\n' % (url, errors)
try:
url = 'http://localhost:8081/axis/services/basic-rpc-encoded?wsdl'
start(url)
t = HttpAuthenticated(**credentials)
client = Client(url, transport=t)
print client
#
# create a name object using the wsdl
#
print 'create name'
name = client.factory.create('ns0:Name')
name.first = u'jeff'+unichr(1234)
name.last = 'ortel'
print name
#
# create a phone object using the wsdl
#
print 'create phone'
phoneA = client.factory.create('ns0:Phone')
phoneA.npa = 410
phoneA.nxx = 555
phoneA.number = 5138
phoneB = client.factory.create('ns0:Phone')
phoneB.npa = 919
phoneB.nxx = 555
phoneB.number = 4406
#
# create a dog
#
dog = client.factory.create('ns0:Dog')
dog.name = 'Chance'
dog.trained = True
#
# create a person object using the wsdl
#
person = client.factory.create('ns0:Person')
print '{empty} person=\n%s' % person
person.name = name
person.age = 43
person.phone = [phoneA,phoneB]
person.pets = [dog]
print 'person=\n%s' % person
#
# add the person (using the webservice)
#
print 'addPersion()'
result = client.service.addPerson(person)
print '\nreply(\n%s\n)\n' % str(result)
#
# create a new name object used to update the person
#
newname = client.factory.create('ns0:Name')
newname.first = 'Todd'
newname.last = None
#
# create AnotherPerson using Person
#
ap = client.factory.create('ns0:AnotherPerson')
ap.name = person.name
ap.age = person.age
ap.phone = person.phone
ap.pets = person.pets
print 'AnotherPerson\n%s' % ap
#
# update the person's name (using the webservice)
#
print 'updatePersion()'
result = client.service.updatePerson(ap, newname)
print '\nreply(\n%s\n)\n' % str(result)
result = client.service.updatePerson(ap, None)
print '\nreply(\n%s\n)\n' % str(result)
except WebFault, f:
errors += 1
print f
print f.fault
except Exception, e:
errors += 1
print e
tb.print_exc()
try:
print "echo('this is cool')"
result = client.service.echo('this is cool')
print '\nreply( %s )\n' % str(result)
print 'echo(None)'
result = client.service.echo(None)
print '\nreply( %s )\n' % str(result)
except WebFault, f:
errors += 1
print f
print f.fault
except Exception, e:
errors += 1
print e
tb.print_exc()
try:
print 'hello()'
result = client.service.hello()
print '\nreply( %s )\n' % str(result)
except WebFault, f:
errors += 1
print f
print f.fault
except Exception, e:
errors += 1
print e
tb.print_exc()
try:
print 'testVoid()'
result = client.service.getVoid()
print '\nreply( %s )\n' % str(result)
except WebFault, f:
errors += 1
print f
print f.fault
except Exception, e:
errors += 1
print e
tb.print_exc()
try:
array = client.factory.create('ArrayOf_xsd_string')
print 'ArrayOf_xsd_string=\n%s' % array
array.item = ['my', 'dog', 'likes', 'steak']
result = client.service.printList(array)
print '\nreply( %s )\n' % str(result)
array = Object()
print 'ArrayOf_xsd_string=\n%s' % array
array.item = ['my', 'dog', 'likes', 'steak']
result = client.service.printList(array)
print '\nreply( %s )\n' % str(result)
except WebFault, f:
errors += 1
print f
print f.fault
except Exception, e:
errors += 1
print e
tb.print_exc()
try:
s = 'hello'
for n in range(0, 3):
print 'getList(%s, %d)' % (s, n)
result = client.service.getList(s, n)
print '\nreply( %s )\n' % str(result)
except WebFault, f:
errors += 1
print f
print f.fault
except Exception, e:
errors += 1
print e
tb.print_exc()
try:
print 'testExceptions()'
result = client.service.throwException()
print '\nreply( %s )\n' % tostr(result)
raise Exception('Fault expected and not raised')
except WebFault, f:
print f
print f.fault
except Exception, e:
errors += 1
print e
tb.print_exc()
try:
url = 'http://localhost:8081/axis/services/basic-rpc-encoded?wsdl'
start(url)
client = Client(url, faults=False, **credentials)
print 'testExceptions()'
result = client.service.throwException()
print '\nreply( %s )\n' % str(result)
except WebFault, f:
errors += 1
print f
print f.fault
except Exception, e:
errors += 1
print e
tb.print_exc()
print '\nFinished: errors=%d' % errors