mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2025-03-03 19:55:47 +03:00
update for smoke tests
This commit is contained in:
parent
8aa12db425
commit
4edf6ebe00
|
@ -18,13 +18,13 @@
|
|||
|
||||
"""An HTTP handler for urllib2 that supports HTTP 1.1 and keepalive.
|
||||
|
||||
>>> import urllib2
|
||||
>>> from keepalive import HTTPHandler
|
||||
>>> keepalive_handler = HTTPHandler()
|
||||
>>> opener = urllib2.build_opener(keepalive_handler)
|
||||
>>> urllib2.install_opener(opener)
|
||||
>>>
|
||||
>>> fo = urllib2.urlopen('http://www.python.org')
|
||||
import urllib2
|
||||
from keepalive import HTTPHandler
|
||||
keepalive_handler = HTTPHandler()
|
||||
opener = urllib2.build_opener(keepalive_handler)
|
||||
urllib2.install_opener(opener)
|
||||
|
||||
fo = urllib2.urlopen('http://www.python.org')
|
||||
|
||||
To remove the handler, simply re-run build_opener with no arguments, and
|
||||
install that opener.
|
||||
|
@ -37,7 +37,9 @@ use the handler methods:
|
|||
close_all()
|
||||
open_connections()
|
||||
|
||||
>>> keepalive_handler.close_all()
|
||||
Example:
|
||||
|
||||
keepalive_handler.close_all()
|
||||
|
||||
EXTRA ATTRIBUTES AND METHODS
|
||||
|
||||
|
@ -53,8 +55,8 @@ EXTRA ATTRIBUTES AND METHODS
|
|||
If you want the best of both worlds, use this inside an
|
||||
AttributeError-catching try:
|
||||
|
||||
>>> try: status = fo.status
|
||||
>>> except AttributeError: status = None
|
||||
try: status = fo.status
|
||||
except AttributeError: status = None
|
||||
|
||||
Unfortunately, these are ONLY there if status == 200, so it's not
|
||||
easy to distinguish between non-200 responses. The reason is that
|
||||
|
|
|
@ -1356,6 +1356,16 @@ def getPartRun():
|
|||
return commonPartsDict[retVal][1] if retVal in commonPartsDict else retVal
|
||||
|
||||
def getUnicode(value):
|
||||
"""
|
||||
Return the unicode representation of the supplied value:
|
||||
|
||||
>>> getUnicode(u'test')
|
||||
u'test'
|
||||
>>> getUnicode('test')
|
||||
u'test'
|
||||
>>> getUnicode(1)
|
||||
u'1'
|
||||
"""
|
||||
if isinstance(value, basestring):
|
||||
return value if isinstance(value, unicode) else unicode(value, conf.dataEncoding if 'dataEncoding' in conf else "utf-8", errors='replace')
|
||||
else:
|
||||
|
@ -1416,6 +1426,7 @@ def commonFinderOnly(initial, sequence):
|
|||
return longestCommonPrefix(*filter(lambda x: x.startswith(initial), sequence))
|
||||
|
||||
def smokeTest():
|
||||
import doctest
|
||||
retVal = True
|
||||
for root, _, files in os.walk(paths.SQLMAP_ROOT_PATH):
|
||||
for file in files:
|
||||
|
@ -1424,15 +1435,24 @@ def smokeTest():
|
|||
path = path.replace(paths.SQLMAP_ROOT_PATH, '.')
|
||||
path = path.replace(os.sep, '.').lstrip('.')
|
||||
try:
|
||||
module = __import__(path)
|
||||
__import__(path)
|
||||
module = sys.modules[path]
|
||||
except Exception, msg:
|
||||
retVal = False
|
||||
errMsg = "smoke test failed at importing module '%s' (%s):\n%s\n" % (path, os.path.join(paths.SQLMAP_ROOT_PATH, file), msg)
|
||||
logger.error(errMsg)
|
||||
else:
|
||||
# Run doc tests
|
||||
# Reference: http://docs.python.org/library/doctest.html
|
||||
results = doctest.testmod(module)
|
||||
if results.failed > 0:
|
||||
retVal = False
|
||||
|
||||
infoMsg = "smoke test "
|
||||
if retVal:
|
||||
infoMsg = "smoke test PASSED"
|
||||
infoMsg += "PASSED"
|
||||
logger.info(infoMsg)
|
||||
else:
|
||||
errMsg = "smoke test FAILED"
|
||||
logger.error(errMsg)
|
||||
return retVal
|
||||
infoMsg += "FAILED"
|
||||
logger.error(infoMsg)
|
||||
return retVal
|
||||
|
|
Loading…
Reference in New Issue
Block a user