py3: port some more middleware tests

* name_check
  * quotas
  * ratelimit
  * read_only
  * recon

Note that the middlewares themselves seem to be fine.

Fix proxy-logging for PEP-0479.

Change-Id: If47d09e8e8c09b9f50451f93d5b0803aa58743a7
This commit is contained in:
Tim Burke 2019-02-20 14:59:49 -08:00
parent 3c224af80c
commit b4e4700765
7 changed files with 85 additions and 71 deletions

View File

@ -316,6 +316,8 @@ class ProxyLoggingMiddleware(object):
bytes_sent += len(chunk)
yield chunk
chunk = next(iterator)
except StopIteration: # iterator was depleted
return
except GeneratorExit: # generator was closed before we finished
client_disconnect = True
raise

View File

@ -50,7 +50,7 @@ class TestNameCheckMiddleware(unittest.TestCase):
path = '/V1.0/' + 'c' * (MAX_LENGTH - 6)
resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'}
).get_response(self.test_check)
self.assertEqual(resp.body, 'OK')
self.assertEqual(resp.body, b'OK')
def test_invalid_character(self):
for c in self.conf['forbidden_chars']:
@ -61,7 +61,7 @@ class TestNameCheckMiddleware(unittest.TestCase):
self.assertEqual(
resp.body,
("Object/Container/Account name contains forbidden chars "
"from %s" % self.conf['forbidden_chars']))
"from %s" % self.conf['forbidden_chars']).encode('utf8'))
self.assertEqual(resp.status_int, 400)
def test_maximum_length_from_config(self):
@ -73,7 +73,7 @@ class TestNameCheckMiddleware(unittest.TestCase):
self.assertEqual(
resp.body,
("Object/Container/Account name longer than the allowed "
"maximum 500"))
"maximum 500").encode('utf-8'))
self.assertEqual(resp.status_int, 400)
# test valid length
@ -81,7 +81,7 @@ class TestNameCheckMiddleware(unittest.TestCase):
resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'}
).get_response(app)
self.assertEqual(resp.status_int, 200)
self.assertEqual(resp.body, 'OK')
self.assertEqual(resp.body, b'OK')
def test_invalid_length(self):
path = '/V1.0/' + 'c' * (MAX_LENGTH - 5)
@ -90,7 +90,7 @@ class TestNameCheckMiddleware(unittest.TestCase):
self.assertEqual(
resp.body,
("Object/Container/Account name longer than the allowed maximum %s"
% self.conf['maximum_length']))
% self.conf['maximum_length']).encode('utf-8'))
self.assertEqual(resp.status_int, 400)
def test_invalid_regexp(self):
@ -103,7 +103,7 @@ class TestNameCheckMiddleware(unittest.TestCase):
resp.body,
("Object/Container/Account name contains a forbidden "
"substring from regular expression %s"
% self.conf['forbidden_regexp']))
% self.conf['forbidden_regexp']).encode('utf-8'))
self.assertEqual(resp.status_int, 400)
def test_valid_regexp(self):
@ -112,7 +112,7 @@ class TestNameCheckMiddleware(unittest.TestCase):
resp = Request.blank(
path, environ={'REQUEST_METHOD': 'PUT'}).get_response(
self.test_check)
self.assertEqual(resp.body, 'OK')
self.assertEqual(resp.body, b'OK')
class TestSwiftInfo(unittest.TestCase):

View File

@ -94,7 +94,7 @@ class TestContainerQuotas(unittest.TestCase):
'CONTENT_LENGTH': '100'})
res = req.get_response(app)
self.assertEqual(res.status_int, 413)
self.assertEqual(res.body, 'Upload exceeds quota.')
self.assertEqual(res.body, b'Upload exceeds quota.')
def test_not_exceed_bytes_quota(self):
app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {})
@ -115,7 +115,7 @@ class TestContainerQuotas(unittest.TestCase):
'CONTENT_LENGTH': '100'})
res = req.get_response(app)
self.assertEqual(res.status_int, 413)
self.assertEqual(res.body, 'Upload exceeds quota.')
self.assertEqual(res.body, b'Upload exceeds quota.')
def test_not_exceed_counts_quota(self):
app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {})
@ -211,7 +211,7 @@ class ContainerQuotaCopyingTestCases(unittest.TestCase):
headers={'Destination': '/c/o'})
res = req.get_response(self.copy_filter)
self.assertEqual(res.status_int, 413)
self.assertEqual(res.body, 'Upload exceeds quota.')
self.assertEqual(res.body, b'Upload exceeds quota.')
def test_not_exceed_bytes_quota_copy_verb(self):
self.app.register('GET', '/v1/a/c2/o2', HTTPOk,
@ -235,7 +235,7 @@ class ContainerQuotaCopyingTestCases(unittest.TestCase):
headers={'Destination': '/c/o'})
res = req.get_response(self.copy_filter)
self.assertEqual(res.status_int, 413)
self.assertEqual(res.body, 'Upload exceeds quota.')
self.assertEqual(res.body, b'Upload exceeds quota.')
def test_exceed_counts_quota_copy_cross_account_verb(self):
self.app.register('GET', '/v1/a/c2/o2', HTTPOk, {}, 'passed')
@ -252,7 +252,7 @@ class ContainerQuotaCopyingTestCases(unittest.TestCase):
'Destination-Account': 'a2'})
res = req.get_response(self.copy_filter)
self.assertEqual(res.status_int, 413)
self.assertEqual(res.body, 'Upload exceeds quota.')
self.assertEqual(res.body, b'Upload exceeds quota.')
def test_exceed_counts_quota_copy_cross_account_PUT_verb(self):
self.app.register('GET', '/v1/a/c2/o2', HTTPOk, {}, 'passed')
@ -269,7 +269,7 @@ class ContainerQuotaCopyingTestCases(unittest.TestCase):
'X-Copy-From-Account': 'a'})
res = req.get_response(self.copy_filter)
self.assertEqual(res.status_int, 413)
self.assertEqual(res.body, 'Upload exceeds quota.')
self.assertEqual(res.body, b'Upload exceeds quota.')
def test_exceed_bytes_quota_copy_from(self):
self.app.register('GET', '/v1/a/c2/o2', HTTPOk,
@ -282,7 +282,7 @@ class ContainerQuotaCopyingTestCases(unittest.TestCase):
headers={'x-copy-from': '/c2/o2'})
res = req.get_response(self.copy_filter)
self.assertEqual(res.status_int, 413)
self.assertEqual(res.body, 'Upload exceeds quota.')
self.assertEqual(res.body, b'Upload exceeds quota.')
def test_not_exceed_bytes_quota_copy_from(self):
self.app.register('GET', '/v1/a/c2/o2', HTTPOk,
@ -328,7 +328,7 @@ class ContainerQuotaCopyingTestCases(unittest.TestCase):
headers={'x-copy-from': '/c2/o2'})
res = req.get_response(self.copy_filter)
self.assertEqual(res.status_int, 413)
self.assertEqual(res.body, 'Upload exceeds quota.')
self.assertEqual(res.body, b'Upload exceeds quota.')
def test_not_exceed_counts_quota_copy_from(self):
self.app.register('GET', '/v1/a/c2/o2', HTTPOk,

View File

@ -74,7 +74,8 @@ class FakeMemcache(object):
class FakeApp(object):
def __call__(self, env, start_response):
return ['204 No Content']
start_response('200 OK', [])
return [b'Some Content']
def start_response(*args):
@ -306,7 +307,7 @@ class TestRateLimit(unittest.TestCase):
thread.join()
the_498s = [
t for t in threads
if ''.join(t.result).startswith('Slow down')]
if b''.join(t.result).startswith(b'Slow down')]
self.assertEqual(len(the_498s), 0)
self.assertEqual(time_ticker, 0)
@ -348,7 +349,7 @@ class TestRateLimit(unittest.TestCase):
thread.join()
the_497s = [
t for t in threads
if ''.join(t.result).startswith('Your account')]
if b''.join(t.result).startswith(b'Your account')]
self.assertEqual(len(the_497s), 5)
self.assertEqual(time_ticker, 0)
@ -374,13 +375,14 @@ class TestRateLimit(unittest.TestCase):
r = self.test_ratelimit(req.environ, start_response)
mock_sleep(.1)
r = self.test_ratelimit(req.environ, start_response)
self.assertEqual(r[0], 'Slow down')
self.assertEqual(r[0], b'Slow down')
mock_sleep(.1)
r = self.test_ratelimit(req.environ, start_response)
self.assertEqual(r[0], 'Slow down')
self.assertEqual(r[0], b'Slow down')
mock_sleep(.1)
r = self.test_ratelimit(req.environ, start_response)
self.assertEqual(r[0], '204 No Content')
print(repr(r))
self.assertEqual(r[0], b'Some Content')
def test_ratelimit_max_rate_double_container(self):
global time_ticker
@ -407,13 +409,13 @@ class TestRateLimit(unittest.TestCase):
r = self.test_ratelimit(req.environ, start_response)
mock_sleep(.1)
r = self.test_ratelimit(req.environ, start_response)
self.assertEqual(r[0], 'Slow down')
self.assertEqual(r[0], b'Slow down')
mock_sleep(.1)
r = self.test_ratelimit(req.environ, start_response)
self.assertEqual(r[0], 'Slow down')
self.assertEqual(r[0], b'Slow down')
mock_sleep(.1)
r = self.test_ratelimit(req.environ, start_response)
self.assertEqual(r[0], '204 No Content')
self.assertEqual(r[0], b'Some Content')
def test_ratelimit_max_rate_double_container_listing(self):
global time_ticker
@ -440,13 +442,13 @@ class TestRateLimit(unittest.TestCase):
r = self.test_ratelimit(req.environ, start_response)
mock_sleep(.1)
r = self.test_ratelimit(req.environ, start_response)
self.assertEqual(r[0], 'Slow down')
self.assertEqual(r[0], b'Slow down')
mock_sleep(.1)
r = self.test_ratelimit(req.environ, start_response)
self.assertEqual(r[0], 'Slow down')
self.assertEqual(r[0], b'Slow down')
mock_sleep(.1)
r = self.test_ratelimit(req.environ, start_response)
self.assertEqual(r[0], '204 No Content')
self.assertEqual(r[0], b'Some Content')
mc = self.test_ratelimit.memcache_client
try:
self.test_ratelimit.memcache_client = None
@ -579,7 +581,7 @@ class TestSwiftInfo(unittest.TestCase):
try:
swift_info[key]
except KeyError as err:
if key not in err:
if key not in str(err):
raise
test_limits = {'account_ratelimit': 1,

View File

@ -23,7 +23,8 @@ from test.unit import FakeLogger
class FakeApp(object):
def __call__(self, env, start_response):
return ['204 No Content']
start_response('200 OK', [])
return [b'Some Content']
def start_response(*args):
@ -32,7 +33,7 @@ def start_response(*args):
read_methods = 'GET HEAD'.split()
write_methods = 'COPY DELETE POST PUT'.split()
ro_resp = ['Writes are disabled for this account.']
ro_resp = [b'Writes are disabled for this account.']
class TestReadOnly(unittest.TestCase):
@ -50,7 +51,7 @@ class TestReadOnly(unittest.TestCase):
req = Request.blank('/v/a')
req.method = method
resp = ro(req.environ, start_response)
self.assertTrue(resp[0].startswith('204'))
self.assertEqual(resp, [b'Some Content'])
def test_global_read_only_on(self):
conf = {
@ -66,7 +67,7 @@ class TestReadOnly(unittest.TestCase):
req = Request.blank('/v/a')
req.method = method
resp = ro(req.environ, start_response)
self.assertTrue(resp[0].startswith('204'))
self.assertEqual(resp, [b'Some Content'])
for method in write_methods:
req = Request.blank('/v/a')
@ -86,7 +87,7 @@ class TestReadOnly(unittest.TestCase):
req = Request.blank('/v/a')
req.method = method
resp = ro(req.environ, start_response)
self.assertTrue(resp[0].startswith('204'))
self.assertEqual(resp, [b'Some Content'])
for method in write_methods:
req = Request.blank('/v/a')
@ -106,7 +107,7 @@ class TestReadOnly(unittest.TestCase):
req = Request.blank('/v/a')
req.method = method
resp = ro(req.environ, start_response)
self.assertTrue(resp[0].startswith('204'))
self.assertEqual(resp, [b'Some Content'])
def test_global_read_only_on_account_off(self):
conf = {
@ -122,7 +123,7 @@ class TestReadOnly(unittest.TestCase):
req = Request.blank('/v/a')
req.method = method
resp = ro(req.environ, start_response)
self.assertTrue(resp[0].startswith('204'))
self.assertEqual(resp, [b'Some Content'])
def test_global_read_only_on_allow_deletes(self):
conf = {
@ -138,7 +139,7 @@ class TestReadOnly(unittest.TestCase):
req = Request.blank('/v/a')
req.method = "DELETE"
resp = ro(req.environ, start_response)
self.assertTrue(resp[0].startswith('204'))
self.assertEqual(resp, [b'Some Content'])
def test_account_read_only_on_allow_deletes(self):
conf = {
@ -153,7 +154,7 @@ class TestReadOnly(unittest.TestCase):
req = Request.blank('/v/a')
req.method = "DELETE"
resp = ro(req.environ, start_response)
self.assertTrue(resp[0].startswith('204'))
self.assertEqual(resp, [b'Some Content'])
def test_global_read_only_on_destination_account_off_on_copy(self):
conf = {
@ -174,7 +175,7 @@ class TestReadOnly(unittest.TestCase):
req = Request.blank('/v/a', headers=headers)
req.method = "COPY"
resp = ro(req.environ, start_response)
self.assertTrue(resp[0].startswith('204'))
self.assertEqual(resp, [b'Some Content'])
def test_global_read_only_off_destination_account_on_on_copy(self):
conf = {}
@ -214,7 +215,7 @@ class TestReadOnly(unittest.TestCase):
req = Request.blank('/v/a', headers=headers)
req.method = "COPY"
resp = ro(req.environ, start_response)
self.assertTrue(resp[0].startswith('204'))
self.assertEqual(resp, [b'Some Content'])
def test_global_read_only_off_src_acct_on_dest_acct_on_on_copy(self):
conf = {}

View File

@ -15,6 +15,7 @@
import array
from contextlib import contextmanager
import json
import mock
import os
from posix import stat_result, statvfs_result
@ -45,7 +46,7 @@ def fail_io_open(file_path, open_mode):
class FakeApp(object):
def __call__(self, env, start_response):
return "FAKE APP"
return b"FAKE APP"
def start_response(*args):
@ -76,7 +77,7 @@ class OpenAndReadTester(object):
def __iter__(self):
return self
def next(self):
def __next__(self):
if self.index == self.out_len:
raise StopIteration
else:
@ -84,6 +85,8 @@ class OpenAndReadTester(object):
self.index += 1
return line
next = __next__
def read(self, *args, **kwargs):
self.read_calls.append((args, kwargs))
try:
@ -1138,7 +1141,7 @@ class TestReconMiddleware(unittest.TestCase):
self.app.get_time = self.frecon.fake_time
def test_recon_get_mem(self):
get_mem_resp = ['{"memtest": "1"}']
get_mem_resp = [b'{"memtest": "1"}']
req = Request.blank('/recon/mem', environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)
self.assertEqual(resp, get_mem_resp)
@ -1147,29 +1150,30 @@ class TestReconMiddleware(unittest.TestCase):
req = Request.blank('/recon/version',
environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)
self.assertEqual(resp, [utils.json.dumps({'version': swiftver})])
self.assertEqual(resp, [json.dumps({
'version': swiftver}).encode('ascii')])
def test_recon_get_load(self):
get_load_resp = ['{"loadtest": "1"}']
get_load_resp = [b'{"loadtest": "1"}']
req = Request.blank('/recon/load', environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)
self.assertEqual(resp, get_load_resp)
def test_recon_get_async(self):
get_async_resp = ['{"asynctest": "1"}']
get_async_resp = [b'{"asynctest": "1"}']
req = Request.blank('/recon/async', environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)
self.assertEqual(resp, get_async_resp)
def test_get_device_info(self):
get_device_resp = ['{"/srv/1/node": ["sdb1"]}']
get_device_resp = [b'{"/srv/1/node": ["sdb1"]}']
req = Request.blank('/recon/devices',
environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)
self.assertEqual(resp, get_device_resp)
def test_recon_get_replication_notype(self):
get_replication_resp = ['{"replicationtest": "1"}']
get_replication_resp = [b'{"replicationtest": "1"}']
req = Request.blank('/recon/replication',
environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)
@ -1178,7 +1182,7 @@ class TestReconMiddleware(unittest.TestCase):
self.frecon.fake_replication_rtype = None
def test_recon_get_replication_all(self):
get_replication_resp = ['{"replicationtest": "1"}']
get_replication_resp = [b'{"replicationtest": "1"}']
# test account
req = Request.blank('/recon/replication/account',
environ={'REQUEST_METHOD': 'GET'})
@ -1202,21 +1206,21 @@ class TestReconMiddleware(unittest.TestCase):
self.frecon.fake_replication_rtype = None
def test_recon_get_auditor_invalid(self):
get_auditor_resp = ['Invalid path: /recon/auditor/invalid']
get_auditor_resp = [b'Invalid path: /recon/auditor/invalid']
req = Request.blank('/recon/auditor/invalid',
environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)
self.assertEqual(resp, get_auditor_resp)
def test_recon_get_auditor_notype(self):
get_auditor_resp = ['Invalid path: /recon/auditor']
get_auditor_resp = [b'Invalid path: /recon/auditor']
req = Request.blank('/recon/auditor',
environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)
self.assertEqual(resp, get_auditor_resp)
def test_recon_get_auditor_all(self):
get_auditor_resp = ['{"auditortest": "1"}']
get_auditor_resp = [b'{"auditortest": "1"}']
req = Request.blank('/recon/auditor/account',
environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)
@ -1237,21 +1241,21 @@ class TestReconMiddleware(unittest.TestCase):
self.frecon.fake_auditor_rtype = None
def test_recon_get_updater_invalid(self):
get_updater_resp = ['Invalid path: /recon/updater/invalid']
get_updater_resp = [b'Invalid path: /recon/updater/invalid']
req = Request.blank('/recon/updater/invalid',
environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)
self.assertEqual(resp, get_updater_resp)
def test_recon_get_updater_notype(self):
get_updater_resp = ['Invalid path: /recon/updater']
get_updater_resp = [b'Invalid path: /recon/updater']
req = Request.blank('/recon/updater',
environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)
self.assertEqual(resp, get_updater_resp)
def test_recon_get_updater(self):
get_updater_resp = ['{"updatertest": "1"}']
get_updater_resp = [b'{"updatertest": "1"}']
req = Request.blank('/recon/updater/container',
environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)
@ -1266,21 +1270,21 @@ class TestReconMiddleware(unittest.TestCase):
self.frecon.fake_updater_rtype = None
def test_recon_get_expirer_invalid(self):
get_updater_resp = ['Invalid path: /recon/expirer/invalid']
get_updater_resp = [b'Invalid path: /recon/expirer/invalid']
req = Request.blank('/recon/expirer/invalid',
environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)
self.assertEqual(resp, get_updater_resp)
def test_recon_get_expirer_notype(self):
get_updater_resp = ['Invalid path: /recon/expirer']
get_updater_resp = [b'Invalid path: /recon/expirer']
req = Request.blank('/recon/expirer',
environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)
self.assertEqual(resp, get_updater_resp)
def test_recon_get_expirer_object(self):
get_expirer_resp = ['{"expirertest": "1"}']
get_expirer_resp = [b'{"expirertest": "1"}']
req = Request.blank('/recon/expirer/object',
environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)
@ -1289,14 +1293,14 @@ class TestReconMiddleware(unittest.TestCase):
self.frecon.fake_updater_rtype = None
def test_recon_get_mounted(self):
get_mounted_resp = ['{"mountedtest": "1"}']
get_mounted_resp = [b'{"mountedtest": "1"}']
req = Request.blank('/recon/mounted',
environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)
self.assertEqual(resp, get_mounted_resp)
def test_recon_get_unmounted(self):
get_unmounted_resp = ['{"unmountedtest": "1"}']
get_unmounted_resp = [b'{"unmountedtest": "1"}']
self.app.get_unmounted = self.frecon.fake_unmounted
req = Request.blank('/recon/unmounted',
environ={'REQUEST_METHOD': 'GET'})
@ -1304,43 +1308,43 @@ class TestReconMiddleware(unittest.TestCase):
self.assertEqual(resp, get_unmounted_resp)
def test_recon_get_unmounted_empty(self):
get_unmounted_resp = '[]'
get_unmounted_resp = b'[]'
self.app.get_unmounted = self.frecon.fake_unmounted_empty
req = Request.blank('/recon/unmounted',
environ={'REQUEST_METHOD': 'GET'})
resp = ''.join(self.app(req.environ, start_response))
resp = b''.join(self.app(req.environ, start_response))
self.assertEqual(resp, get_unmounted_resp)
def test_recon_get_diskusage(self):
get_diskusage_resp = ['{"diskusagetest": "1"}']
get_diskusage_resp = [b'{"diskusagetest": "1"}']
req = Request.blank('/recon/diskusage',
environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)
self.assertEqual(resp, get_diskusage_resp)
def test_recon_get_ringmd5(self):
get_ringmd5_resp = ['{"ringmd5test": "1"}']
get_ringmd5_resp = [b'{"ringmd5test": "1"}']
req = Request.blank('/recon/ringmd5',
environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)
self.assertEqual(resp, get_ringmd5_resp)
def test_recon_get_swiftconfmd5(self):
get_swiftconfmd5_resp = ['{"/etc/swift/swift.conf": "abcdef"}']
get_swiftconfmd5_resp = [b'{"/etc/swift/swift.conf": "abcdef"}']
req = Request.blank('/recon/swiftconfmd5',
environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)
self.assertEqual(resp, get_swiftconfmd5_resp)
def test_recon_get_quarantined(self):
get_quarantined_resp = ['{"quarantinedtest": "1"}']
get_quarantined_resp = [b'{"quarantinedtest": "1"}']
req = Request.blank('/recon/quarantined',
environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)
self.assertEqual(resp, get_quarantined_resp)
def test_recon_get_sockstat(self):
get_sockstat_resp = ['{"sockstattest": "1"}']
get_sockstat_resp = [b'{"sockstattest": "1"}']
req = Request.blank('/recon/sockstat',
environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)
@ -1350,28 +1354,28 @@ class TestReconMiddleware(unittest.TestCase):
req = Request.blank('/recon/invalid',
environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)
self.assertEqual(resp, ['Invalid path: /recon/invalid'])
self.assertEqual(resp, [b'Invalid path: /recon/invalid'])
def test_no_content(self):
self.app.get_load = self.frecon.nocontent
req = Request.blank('/recon/load', environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)
self.assertEqual(resp, ['Internal server error.'])
self.assertEqual(resp, [b'Internal server error.'])
def test_recon_pass(self):
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)
self.assertEqual(resp, 'FAKE APP')
self.assertEqual(resp, b'FAKE APP')
def test_recon_get_driveaudit(self):
get_driveaudit_resp = ['{"driveaudittest": "1"}']
get_driveaudit_resp = [b'{"driveaudittest": "1"}']
req = Request.blank('/recon/driveaudit',
environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)
self.assertEqual(resp, get_driveaudit_resp)
def test_recon_get_time(self):
get_time_resp = ['{"timetest": "1"}']
get_time_resp = [b'{"timetest": "1"}']
req = Request.blank('/recon/time',
environ={'REQUEST_METHOD': 'GET'})
resp = self.app(req.environ, start_response)

View File

@ -58,7 +58,12 @@ commands =
test/unit/common/middleware/test_list_endpoints.py \
test/unit/common/middleware/test_listing_formats.py \
test/unit/common/middleware/test_memcache.py \
test/unit/common/middleware/test_name_check.py \
test/unit/common/middleware/test_proxy_logging.py \
test/unit/common/middleware/test_quotas.py \
test/unit/common/middleware/test_ratelimit.py \
test/unit/common/middleware/test_read_only.py \
test/unit/common/middleware/test_recon.py \
test/unit/common/middleware/test_subrequest_logging.py \
test/unit/common/middleware/test_tempauth.py \
test/unit/common/middleware/test_xprofile.py \