From: <em...@us...> - 2012-03-29 10:46:33
|
Revision: 1502 http://pywebsvcs.svn.sourceforge.net/pywebsvcs/?rev=1502&view=rev Author: emmebi Date: 2012-03-29 10:46:23 +0000 (Thu, 29 Mar 2012) Log Message: ----------- Just a little clean-up of the existing tests, plus the removal of a few warnings. Modified Paths: -------------- trunk/zsi/ZSI/digest_auth.py trunk/zsi/ZSI/resolvers.py trunk/zsi/test/test_AnyType.py trunk/zsi/test/test_QName.py trunk/zsi/test/test_TCtimes.py trunk/zsi/test/test_URI.py trunk/zsi/test/test_callhome.py trunk/zsi/test/test_list.py trunk/zsi/test/test_rfc2617.py trunk/zsi/test/test_t1.py trunk/zsi/test/test_t2.py trunk/zsi/test/test_t3.py trunk/zsi/test/test_t4.py trunk/zsi/test/test_t5.py trunk/zsi/test/test_t6.py trunk/zsi/test/test_t7.py trunk/zsi/test/test_t9.py trunk/zsi/test/test_union.py trunk/zsi/test/test_zsi.py trunk/zsi/test/test_zsi_net.py Modified: trunk/zsi/ZSI/digest_auth.py =================================================================== --- trunk/zsi/ZSI/digest_auth.py 2011-12-01 08:17:02 UTC (rev 1501) +++ trunk/zsi/ZSI/digest_auth.py 2012-03-29 10:46:23 UTC (rev 1502) @@ -2,11 +2,14 @@ # $Header$ '''Utilities for HTTP Digest Authentication ''' +import httplib +import random import re -from md5 import md5 -import random import time -import httplib +try: + from hashlib import md5 +except ImportError: + from md5 import md5 random.seed(int(time.time()*10)) Modified: trunk/zsi/ZSI/resolvers.py =================================================================== --- trunk/zsi/ZSI/resolvers.py 2011-12-01 08:17:02 UTC (rev 1501) +++ trunk/zsi/ZSI/resolvers.py 2012-03-29 10:46:23 UTC (rev 1502) @@ -3,12 +3,18 @@ '''SOAP messaging parsing. ''' -from ZSI import _copyright, _child_elements, EvaluateException, TC -import multifile, mimetools, urllib +try: + import cStringIO as StringIO +except ImportError: + import StringIO +import multifile +import mimetools +import urllib from base64 import decodestring as b64decode -import cStringIO as StringIO +from ZSI import _copyright, _child_elements, EvaluateException, TC + def Opaque(uri, tc, ps, **keywords): '''Resolve a URI and return its content as a string. ''' Modified: trunk/zsi/test/test_AnyType.py =================================================================== --- trunk/zsi/test/test_AnyType.py 2011-12-01 08:17:02 UTC (rev 1501) +++ trunk/zsi/test/test_AnyType.py 2012-03-29 10:46:23 UTC (rev 1502) @@ -1,11 +1,9 @@ #!/usr/bin/env python -import unittest, sys, tests_good, tests_bad, time -from ZSI import * -try: - import cStringIO as StringIO -except ImportError: - import StringIO +import unittest + +from ZSI import schema, ParsedSoap, TC + """Bug [ 1520092 ] URI Bug: urllib.quote escaping reserved chars Bug [ 2748314 ] Malformed type attribute (bad NS) with 2.1a1 but not with 2. """ Modified: trunk/zsi/test/test_QName.py =================================================================== --- trunk/zsi/test/test_QName.py 2011-12-01 08:17:02 UTC (rev 1501) +++ trunk/zsi/test/test_QName.py 2012-03-29 10:46:23 UTC (rev 1502) @@ -1,12 +1,9 @@ #!/usr/bin/env python -import unittest, sys, tests_good, tests_bad, time -from ZSI import * -try: - import cStringIO as StringIO -except ImportError: - import StringIO +import unittest +from ZSI import ParsedSoap, TC, FaultFromFaultMessage + """Bug [ 1520092 ] URI Bug: urllib.quote escaping reserved chars Bug [ 2748314 ] Malformed type attribute (bad NS) with 2.1a1 but not with 2. """ @@ -33,7 +30,6 @@ </soapenv:Body> </soapenv:Envelope>""" - from ZSI import ParsedSoap, FaultFromFaultMessage ps = ParsedSoap(msg) fault = FaultFromFaultMessage(ps) self.failUnless(fault.code == ('','ServerFaultCode'), 'faultcode should be (namespace,name) tuple') Modified: trunk/zsi/test/test_TCtimes.py =================================================================== --- trunk/zsi/test/test_TCtimes.py 2011-12-01 08:17:02 UTC (rev 1501) +++ trunk/zsi/test/test_TCtimes.py 2012-03-29 10:46:23 UTC (rev 1502) @@ -1,8 +1,11 @@ #!/usr/bin/env python # vim: sts=4 sw=4 et -import unittest, sys, tests_good, tests_bad, time, os -from ZSI import * +import os +import time +import unittest + +from ZSI import TC try: import cStringIO as StringIO except ImportError: Modified: trunk/zsi/test/test_URI.py =================================================================== --- trunk/zsi/test/test_URI.py 2011-12-01 08:17:02 UTC (rev 1501) +++ trunk/zsi/test/test_URI.py 2012-03-29 10:46:23 UTC (rev 1502) @@ -1,12 +1,9 @@ #!/usr/bin/env python -import unittest, sys, tests_good, tests_bad, time -from ZSI import * -try: - import cStringIO as StringIO -except ImportError: - import StringIO +import unittest +from ZSI import ParsedSoap, SoapWriter, TC + """Bug [ 1520092 ] URI Bug: urllib.quote escaping reserved chars From rfc2396: @@ -45,8 +42,8 @@ sw2.serialize(orig, typecode=tc2, typed=False) s2 = str(sw2) - print s1 - print s2 +# print s1 +# print s2 self.failUnless(s1 == s2, 'reserved characters used for reserved purpose should not be escaped.') Modified: trunk/zsi/test/test_callhome.py =================================================================== --- trunk/zsi/test/test_callhome.py 2011-12-01 08:17:02 UTC (rev 1501) +++ trunk/zsi/test/test_callhome.py 2012-03-29 10:46:23 UTC (rev 1502) @@ -1,5 +1,8 @@ #!/usr/bin/env python -import os,unittest + +import os +import unittest + from ZSI import version from ZSI.wstools.logging import gridLog @@ -9,7 +12,8 @@ class TestCase(unittest.TestCase): def ping(self): - gridLog(event="zsi.test.test_callhome.ping", zsi="v%d.%d.%d" % version.Version, prog="test_callhome.py") + gridLog(event="zsi.test.test_callhome.ping", zsi="v%d.%d.%d" % version.Version, + prog="test_callhome.py") def makeTestSuite(): suite = unittest.TestSuite() Modified: trunk/zsi/test/test_list.py =================================================================== --- trunk/zsi/test/test_list.py 2011-12-01 08:17:02 UTC (rev 1501) +++ trunk/zsi/test/test_list.py 2012-03-29 10:46:23 UTC (rev 1502) @@ -1,13 +1,15 @@ #!/usr/bin/env python -import unittest, time, datetime + +import time +import unittest +from cStringIO import StringIO + import ZSI from ZSI.writer import SoapWriter from ZSI import _get_element_nsuri_name from ZSI.schema import GED, TypeDefinition, ElementDeclaration from ZSI.parse import ParsedSoap -from cStringIO import StringIO - class TestList1_Def(ZSI.TC.List, TypeDefinition): itemType = (u'http://www.w3.org/2001/XMLSchema', u'dateTime') schema = "urn:test" @@ -15,7 +17,6 @@ def __init__(self, pname, **kw): ZSI.TC.List.__init__(self, pname, **kw) - class TestList2_Def(ZSI.TC.List, TypeDefinition): itemType = ZSI.TC.gDateTime() schema = "urn:test" @@ -23,7 +24,6 @@ def __init__(self, pname, **kw): ZSI.TC.List.__init__(self, pname, **kw) - class ListTestCase(unittest.TestCase): "test List TypeCode" @@ -44,7 +44,7 @@ sw = SoapWriter() sw.serialize(data, typecode) s = str(sw) - print s + #print s ps = ParsedSoap(s); pyobj = ps.Parse(typecode) assert pyobj == data, 'Data corruption expected "%s", got "%s"' %(str(data),str(pyobj)) if data is None: @@ -57,7 +57,6 @@ utc = list(time.gmtime(i)[:-3]) + [999,0,0] data.append(tuple(utc)) - def makeTestSuite(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(ListTestCase, "check")) Modified: trunk/zsi/test/test_rfc2617.py =================================================================== --- trunk/zsi/test/test_rfc2617.py 2011-12-01 08:17:02 UTC (rev 1501) +++ trunk/zsi/test/test_rfc2617.py 2012-03-29 10:46:23 UTC (rev 1502) @@ -4,19 +4,19 @@ HTTP Authentication: Basic and Digest Access Authentication """ + import unittest + from ZSI import digest_auth -from ZSI.wstools.logging import setBasicLoggerDEBUG -setBasicLoggerDEBUG() class DATestCase(unittest.TestCase): "test Union TypeCode" def check_challenge_single_www_authenticate_header(self): challenge='Basic realm="WallyWorld"' - print "=="*30 - print challenge - print "=="*30 + #print "=="*30 + #print challenge + #print "=="*30 cd = digest_auth.fetch_challenge(challenge) expect = {'challenge': 'Basic', 'realm': 'WallyWorld'} self.failUnless(cd == expect, 'Expected equivalent') Modified: trunk/zsi/test/test_t1.py =================================================================== --- trunk/zsi/test/test_t1.py 2011-12-01 08:17:02 UTC (rev 1501) +++ trunk/zsi/test/test_t1.py 2012-03-29 10:46:23 UTC (rev 1502) @@ -1,11 +1,18 @@ #!/usr/bin/env python -import unittest, sys, tests_good, tests_bad, time -from ZSI import * try: import cStringIO as StringIO except ImportError: import StringIO +import unittest +import sys +import time +from ZSI import * + +import tests_good +import tests_bad + + class t1TestCase(unittest.TestCase): "Test case wrapper for old ZSI t1 test case" @@ -35,10 +42,10 @@ def checkt1(self): for key,val in self.badTests: - print "\n", "." * 60, key + #print "\n", "." * 60, key self.failUnlessRaises(ParseException, ParsedSoap, val) for key,val in self.goodTests: - print "\n", "." * 60, key + #print "\n", "." * 60, key ps = ParsedSoap(val) ps = ParsedSoap(datatest) @@ -141,13 +148,13 @@ a = bar() except Exception, e: f = FaultFromException(e, 0, sys.exc_info()[2]) - print f.AsSOAP() - print - print - print FaultFromNotUnderstood('myuri', 'dalocalname', actor='cher').AsSOAP() - print - print - print FaultFromActor('actor:i:dont:understand').AsSOAP() + #print f.AsSOAP() + #print + #print + #print FaultFromNotUnderstood('myuri', 'dalocalname', actor='cher').AsSOAP() + #print + #print + #print FaultFromActor('actor:i:dont:understand').AsSOAP() def makeTestSuite(): @@ -163,12 +170,15 @@ def bar(): return foo() + 2 -class zParseException: pass +class zParseException: + pass class myclass: + def __init__(self, name=None): self.name = name or id(self) self.z = 'z value' + def __str__(self): return 'myclass-%s-(%d,"%s")' % (self.name, self.i, self.t) + \ str(self.z) @@ -229,7 +239,7 @@ def main(): unittest.main(defaultTest="makeTestSuite") +if __name__ == "__main__" : + main() -if __name__ == "__main__" : main() - Modified: trunk/zsi/test/test_t2.py =================================================================== --- trunk/zsi/test/test_t2.py 2011-12-01 08:17:02 UTC (rev 1501) +++ trunk/zsi/test/test_t2.py 2012-03-29 10:46:23 UTC (rev 1502) @@ -1,8 +1,11 @@ #!/usr/bin/env python -import unittest, sys -from ZSI import * +import sys +import unittest +from ZSI import TC, ParsedSoap, ParseException, FaultFromZSIException, FaultFromException, SoapWriter + + class t2TestCase(unittest.TestCase): "Test case wrapper for old ZSI t2 test case" @@ -40,8 +43,9 @@ import operator total = reduce(operator.add, player.Scores, 0) result = Average(foo(total, len(player.Scores))) - sw = SoapWriter().serialize(result) - print >>OUT, str(sw) + sw = SoapWriter().serialize(result) + str(sw) + #print >>OUT, str(sw) except Exception, e: print >>OUT, FaultFromException(e, 0, sys.exc_info()[2]).AsSOAP() self.fail() Modified: trunk/zsi/test/test_t3.py =================================================================== --- trunk/zsi/test/test_t3.py 2011-12-01 08:17:02 UTC (rev 1501) +++ trunk/zsi/test/test_t3.py 2012-03-29 10:46:23 UTC (rev 1502) @@ -1,8 +1,8 @@ #!/usr/bin/env python import unittest from ZSI import * -from ZSI.wstools.logging import setBasicLoggerDEBUG -setBasicLoggerDEBUG() +#from ZSI.wstools.logging import setBasicLoggerDEBUG +#setBasicLoggerDEBUG() class t3TestCase(unittest.TestCase): "Test case wrapper for old ZSI t3 test case" @@ -17,14 +17,14 @@ text = f.AsSOAP() i = 0 for l in text.split('\n'): - print i, l + #print i, l i += 1 ps = ParsedSoap(text) if ps.IsAFault(): f = FaultFromFaultMessage(ps) - print f.AsSOAP() + #print f.AsSOAP() self.failUnless(f.AsSOAP().find(str(a)) > 0) - print '--'*20 + #print '--'*20 def makeTestSuite(): Modified: trunk/zsi/test/test_t4.py =================================================================== --- trunk/zsi/test/test_t4.py 2011-12-01 08:17:02 UTC (rev 1501) +++ trunk/zsi/test/test_t4.py 2012-03-29 10:46:23 UTC (rev 1502) @@ -32,7 +32,7 @@ # Faulted while processing; assume it's in the header. print >>OUT, FaultFromException(e, 1, sys.exc_info()[2]).AsSOAP() self.fail() - print 'resolving' + #print 'resolving' typecode = TC.Struct(None, [ TC.XML('xmltest'), TC.String('stringtest', resolver=r.Opaque), ]) try: @@ -45,7 +45,7 @@ print >>OUT, FaultFromException(e, 0, sys.exc_info()[2]).AsSOAP() self.fail() ##PrettyPrint(dict['xmltest']) - print '**', dict['stringtest'], '**' + #print '**', dict['stringtest'], '**' def makeTestSuite(): suite = unittest.TestSuite() Modified: trunk/zsi/test/test_t5.py =================================================================== --- trunk/zsi/test/test_t5.py 2011-12-01 08:17:02 UTC (rev 1501) +++ trunk/zsi/test/test_t5.py 2012-03-29 10:46:23 UTC (rev 1502) @@ -1,17 +1,16 @@ #!/usr/bin/env python -import unittest, multifile, mimetools -from ZSI import * -from ZSI import resolvers -from xml.dom import Node -#from xml.dom.ext.reader import PyExpat -from ZSI.parse import DefaultReader as Reader - +import mimetools +import unittest try: import cStringIO as StringIO except ImportError: import StringIO +from ZSI import resolvers +from ZSI.parse import DefaultReader as Reader + + class t5TestCase(unittest.TestCase): "Test case wrapper for old ZSI t5 test case" @@ -21,11 +20,11 @@ if m.gettype()[0:10] == "multipart/": cid = resolvers.MIMEResolver(m['content-type'], istr) xml = cid.GetSOAPPart() - print 'xml=', xml.getvalue() - for h,b in cid.parts: - print h, b.read() + #print 'xml=', xml.getvalue() +# for h,b in cid.parts: +# print h, b.read() dom = Reader.fromStream(xml) - print dom + #print dom def makeTestSuite(): suite = unittest.TestSuite() Modified: trunk/zsi/test/test_t6.py =================================================================== --- trunk/zsi/test/test_t6.py 2011-12-01 08:17:02 UTC (rev 1501) +++ trunk/zsi/test/test_t6.py 2012-03-29 10:46:23 UTC (rev 1502) @@ -1,6 +1,11 @@ #!/usr/bin/env python -import unittest, sys, multifile, mimetools, base64 -from ZSI import * +import unittest +import sys +import multifile +import mimetools +import base64 + +from ZSI import TC, ParseException, FaultFromException, ParsedSoap from ZSI import resolvers try: import cStringIO as StringIO @@ -34,16 +39,16 @@ self.failUnlessEqual(dict['stringtest'], strExtTest, "Failed to extract stringtest correctly") - print base64.encodestring(cid['pa...@zo...'].read()) + #print base64.encodestring(cid['pa...@zo...'].read()) v = dict['b64'] - print type(v), 'is type(v)' + #print type(v), 'is type(v)' self.failUnlessEqual(cid['pa...@zo...'].getvalue(), v, "mismatch") - print base64.encodestring(v) - from ZSI.wstools.c14n import Canonicalize - z = dict['xmltest'] - print type(z), z - print Canonicalize(z) + #print base64.encodestring(v) + #from ZSI.wstools.c14n import Canonicalize + #z = dict['xmltest'] + #print type(z), z + #print Canonicalize(z) def makeTestSuite(): suite = unittest.TestSuite() Modified: trunk/zsi/test/test_t7.py =================================================================== --- trunk/zsi/test/test_t7.py 2011-12-01 08:17:02 UTC (rev 1501) +++ trunk/zsi/test/test_t7.py 2012-03-29 10:46:23 UTC (rev 1502) @@ -1,8 +1,10 @@ #!/usr/bin/env python -import unittest, sys -from ZSI import * +import unittest +import sys +from ZSI import ParsedSoap, SoapWriter, TC + class t7TestCase(unittest.TestCase): "Test case wrapper for old ZSI t7 test case" @@ -14,22 +16,22 @@ d = tcdict.parse(ps.body_root, ps) self.assertEqual(d, { u'a':123, '\x00\x01':456 }) - print 'as dictionary\n', d + #print 'as dictionary\n', d l = tclist.parse(ps.body_root, ps) self.assertEqual(l, [('\x00\x01', 456), (u'a', 123)]) - print '\n', '=' * 30 - print 'as list\n', l + #print '\n', '=' * 30 + #print 'as list\n', l - print '\n', '=' * 30 + #print '\n', '=' * 30 sw = SoapWriter() sw.serialize(d, tcdict) - print >>sys.stdout, sw + #print >>sys.stdout, sw - print '\n', '=' * 30 + #print '\n', '=' * 30 sw = SoapWriter() sw.serialize(l, tclist) - print >>sys.stdout, sw + #print >>sys.stdout, sw def makeTestSuite(): suite = unittest.TestSuite() Modified: trunk/zsi/test/test_t9.py =================================================================== --- trunk/zsi/test/test_t9.py 2011-12-01 08:17:02 UTC (rev 1501) +++ trunk/zsi/test/test_t9.py 2012-03-29 10:46:23 UTC (rev 1502) @@ -1,5 +1,13 @@ #!/usr/bin/env python -import unittest, sys, sha, base64 + +import base64 +import unittest +try: + from hashlib import sha1 as local_sha +except ImportError: + import sha1 as local_sha +import sys + from ZSI import _get_element_nsuri_name from ZSI.parse import ParsedSoap from ZSI.wstools.c14n import Canonicalize @@ -25,8 +33,8 @@ s = StringIO() Canonicalize(self.el, s, unsuppressedPrefixes=None) cxml = s.getvalue() - d1 = base64.encodestring(sha.sha(C14N_INC1).digest()).strip() - d2 = base64.encodestring(sha.sha(cxml).digest()).strip() + d1 = base64.encodestring(local_sha(C14N_INC1).digest()).strip() + d2 = base64.encodestring(local_sha(cxml).digest()).strip() self.assertEqual(d1, d2) self.assertEqual(d1, C14N_INC1_DIGEST) @@ -36,8 +44,8 @@ s = StringIO() Canonicalize(self.el, s, unsuppressedPrefixes=[]) cxml = s.getvalue() - d1 = base64.encodestring(sha.sha(C14N_EXCL1).digest()).strip() - d2 = base64.encodestring(sha.sha(cxml).digest()).strip() + d1 = base64.encodestring(local_sha(C14N_EXCL1).digest()).strip() + d2 = base64.encodestring(local_sha(cxml).digest()).strip() self.assertEqual(d1, C14N_EXCL1_DIGEST) self.assertEqual(d1, d2) @@ -50,8 +58,8 @@ s = StringIO() Canonicalize(self.el, s, unsuppressedPrefixes=['xsi', 'xsd']) cxml = s.getvalue() - d1 = base64.encodestring(sha.sha(C14N_EXCL2).digest()).strip() - d2 = base64.encodestring(sha.sha(cxml).digest()).strip() + d1 = base64.encodestring(local_sha(C14N_EXCL2).digest()).strip() + d2 = base64.encodestring(local_sha(cxml).digest()).strip() self.assertEqual(d1, C14N_EXCL2_DIGEST) self.assertEqual(d1, d2) @@ -67,9 +75,9 @@ s = StringIO() Canonicalize(self.el, s, unsuppressedPrefixes=[]) cxml = s.getvalue() - print cxml - d1 = base64.encodestring(sha.sha(C14N_EXCL3).digest()).strip() - d2 = base64.encodestring(sha.sha(cxml).digest()).strip() + #print cxml + d1 = base64.encodestring(local_sha(C14N_EXCL3).digest()).strip() + d2 = base64.encodestring(local_sha(cxml).digest()).strip() self.assertEqual(d1, C14N_EXCL3_DIGEST) self.assertEqual(d1, d2) @@ -77,8 +85,8 @@ RCVDIGEST = "jhTbi7gWlY9oLqsRr+EZ0bokRFA=" CALDIGEST = "IkMyI4zCDlK41qE7sZxvkFHJioU=" - d1 = base64.encodestring(sha.sha(WRONG).digest()).strip() - d2 = base64.encodestring(sha.sha(CORRECT).digest()).strip() + d1 = base64.encodestring(local_sha(WRONG).digest()).strip() + d2 = base64.encodestring(local_sha(CORRECT).digest()).strip() ps = ParsedSoap(XML_INST4) el = filter(lambda el: _get_element_nsuri_name(el) == (WSA200403.ADDRESS, "MessageID"), @@ -87,10 +95,10 @@ s = StringIO() Canonicalize(el, s, unsuppressedPrefixes=[]) cxml = s.getvalue() - print "-- "*20 - print cxml - print "-- "*20 - d3 = base64.encodestring(sha.sha(cxml).digest()).strip() +# print "-- "*20 +# print cxml +# print "-- "*20 + d3 = base64.encodestring(local_sha(cxml).digest()).strip() self.assertEqual(d1, RCVDIGEST) self.assertEqual(d2, CALDIGEST) Modified: trunk/zsi/test/test_union.py =================================================================== --- trunk/zsi/test/test_union.py 2011-12-01 08:17:02 UTC (rev 1501) +++ trunk/zsi/test/test_union.py 2012-03-29 10:46:23 UTC (rev 1502) @@ -1,12 +1,15 @@ #!/usr/bin/env python -import unittest, sys, sha, base64 +import base64 +import unittest +import sys +from cStringIO import StringIO + import ZSI from ZSI import _get_element_nsuri_name from ZSI.schema import GED, TypeDefinition, ElementDeclaration from ZSI.parse import ParsedSoap from ZSI.wstools.c14n import Canonicalize from ZSI.wstools.Namespaces import WSA200403, SOAP -from cStringIO import StringIO # # Generated code Modified: trunk/zsi/test/test_zsi.py =================================================================== --- trunk/zsi/test/test_zsi.py 2011-12-01 08:17:02 UTC (rev 1501) +++ trunk/zsi/test/test_zsi.py 2012-03-29 10:46:23 UTC (rev 1502) @@ -26,4 +26,5 @@ unittest.main(defaultTest="makeTestSuite") suite = unittest.TestSuite() -if __name__ == "__main__" : main() +if __name__ == "__main__": + main() Modified: trunk/zsi/test/test_zsi_net.py =================================================================== --- trunk/zsi/test/test_zsi_net.py 2011-12-01 08:17:02 UTC (rev 1501) +++ trunk/zsi/test/test_zsi_net.py 2012-03-29 10:46:23 UTC (rev 1502) @@ -13,4 +13,5 @@ unittest.main(defaultTest="makeTestSuite") suite = unittest.TestSuite() -if __name__ == "__main__" : main() +if __name__ == "__main__" : + main() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |