2017-12-07 20:41:01 +00:00
|
|
|
import random
|
|
|
|
import requests
|
|
|
|
import string
|
|
|
|
import time
|
|
|
|
|
|
|
|
from nose.tools import eq_ as eq
|
|
|
|
|
|
|
|
def assert_raises(excClass, callableObj, *args, **kwargs):
|
|
|
|
"""
|
|
|
|
Like unittest.TestCase.assertRaises, but returns the exception.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
callableObj(*args, **kwargs)
|
|
|
|
except excClass as e:
|
|
|
|
return e
|
|
|
|
else:
|
|
|
|
if hasattr(excClass, '__name__'):
|
|
|
|
excName = excClass.__name__
|
|
|
|
else:
|
|
|
|
excName = str(excClass)
|
|
|
|
raise AssertionError("%s not raised" % excName)
|
|
|
|
|
|
|
|
def generate_random(size, part_size=5*1024*1024):
|
|
|
|
"""
|
|
|
|
Generate the specified number random data.
|
|
|
|
(actually each MB is a repetition of the first KB)
|
|
|
|
"""
|
|
|
|
chunk = 1024
|
|
|
|
allowed = string.ascii_letters
|
|
|
|
for x in range(0, size, part_size):
|
2019-03-22 17:58:30 +00:00
|
|
|
strpart = ''.join([allowed[random.randint(0, len(allowed) - 1)] for _ in range(chunk)])
|
2017-12-07 20:41:01 +00:00
|
|
|
s = ''
|
|
|
|
left = size - x
|
|
|
|
this_part_size = min(left, part_size)
|
2019-03-22 17:58:30 +00:00
|
|
|
for y in range(this_part_size // chunk):
|
2017-12-07 20:41:01 +00:00
|
|
|
s = s + strpart
|
|
|
|
s = s + strpart[:(this_part_size % chunk)]
|
|
|
|
yield s
|
|
|
|
if (x == size):
|
|
|
|
return
|
|
|
|
|
|
|
|
def _get_status(response):
|
|
|
|
status = response['ResponseMetadata']['HTTPStatusCode']
|
|
|
|
return status
|
|
|
|
|
|
|
|
def _get_status_and_error_code(response):
|
|
|
|
status = response['ResponseMetadata']['HTTPStatusCode']
|
|
|
|
error_code = response['Error']['Code']
|
|
|
|
return status, error_code
|