More assertion cleanup
Change-Id: Id88af19c5bfd0bcbbeabcf4eeb23beef4c50b1cb Related-Change: I416831c8ad92f8445bc8d9560040a5ebf5c90702
This commit is contained in:
parent
3da144a3af
commit
c6b9195db8
@ -87,13 +87,11 @@ class TestGatekeeper(unittest.TestCase):
|
||||
|
||||
def _assertHeadersEqual(self, expected, actual):
|
||||
for key in expected:
|
||||
self.assertTrue(key.lower() in actual,
|
||||
'%s missing from %s' % (key, actual))
|
||||
self.assertIn(key.lower(), actual)
|
||||
|
||||
def _assertHeadersAbsent(self, unexpected, actual):
|
||||
for key in unexpected:
|
||||
self.assertNotIn(key.lower(), actual,
|
||||
'%s is in %s' % (key, actual))
|
||||
self.assertNotIn(key.lower(), actual)
|
||||
|
||||
def get_app(self, app, global_conf, **local_conf):
|
||||
factory = gatekeeper.filter_factory(global_conf, **local_conf)
|
||||
|
@ -453,8 +453,8 @@ class TestProxyLogging(unittest.TestCase):
|
||||
[x for x in resp]
|
||||
log_parts = self._log_parts(app)
|
||||
headers = unquote(log_parts[14]).split('\n')
|
||||
self.assertTrue('First: 1' in headers)
|
||||
self.assertTrue('Second: 2' in headers)
|
||||
self.assertIn('First: 1', headers)
|
||||
self.assertIn('Second: 2', headers)
|
||||
self.assertNotIn('Third: 3', headers)
|
||||
self.assertNotIn('Host: localhost:80', headers)
|
||||
|
||||
|
@ -470,8 +470,10 @@ class TestSloPutManifest(SloTestCase):
|
||||
body=test_json_data)
|
||||
self.assertNotIn('X-Static-Large-Object', req.headers)
|
||||
self.slo(req.environ, fake_start_response)
|
||||
self.assertTrue('X-Static-Large-Object' in req.headers)
|
||||
self.assertTrue(req.environ['PATH_INFO'], '/cont/object\xe2\x99\xa1')
|
||||
self.assertIn('X-Static-Large-Object', req.headers)
|
||||
self.assertEqual(req.environ['PATH_INFO'], '/v1/AUTH_test/c/man')
|
||||
self.assertIn(('HEAD', '/v1/AUTH_test/cont/object\xe2\x99\xa1'),
|
||||
self.app.calls)
|
||||
|
||||
def test_handle_multipart_put_no_xml(self):
|
||||
req = Request.blank(
|
||||
|
@ -554,8 +554,8 @@ class TestStaticWeb(unittest.TestCase):
|
||||
resp = Request.blank(
|
||||
'/v1/a/c3/subdir/').get_response(self.test_staticweb)
|
||||
self.assertEqual(resp.status_int, 200)
|
||||
self.assertTrue('Listing of /v1/a/c3/subdir/' in resp.body)
|
||||
self.assertTrue('</style>' in resp.body)
|
||||
self.assertIn('Listing of /v1/a/c3/subdir/', resp.body)
|
||||
self.assertIn('</style>', resp.body)
|
||||
self.assertNotIn('<link', resp.body)
|
||||
self.assertNotIn('listing.css', resp.body)
|
||||
|
||||
@ -588,8 +588,8 @@ class TestStaticWeb(unittest.TestCase):
|
||||
def test_container4indexhtml(self):
|
||||
resp = Request.blank('/v1/a/c4/').get_response(self.test_staticweb)
|
||||
self.assertEqual(resp.status_int, 200)
|
||||
self.assertTrue('Listing of /v1/a/c4/' in resp.body)
|
||||
self.assertTrue('href="listing.css"' in resp.body)
|
||||
self.assertIn('Listing of /v1/a/c4/', resp.body)
|
||||
self.assertIn('href="listing.css"', resp.body)
|
||||
|
||||
def test_container4indexhtmlauthed(self):
|
||||
resp = Request.blank('/v1/a/c4').get_response(self.test_staticweb)
|
||||
@ -609,16 +609,16 @@ class TestStaticWeb(unittest.TestCase):
|
||||
resp = Request.blank(
|
||||
'/v1/a/c4/unknown').get_response(self.test_staticweb)
|
||||
self.assertEqual(resp.status_int, 404)
|
||||
self.assertTrue("Chrome's 404 fancy-page sucks." in resp.body)
|
||||
self.assertIn("Chrome's 404 fancy-page sucks.", resp.body)
|
||||
|
||||
def test_container4subdir(self):
|
||||
resp = Request.blank(
|
||||
'/v1/a/c4/subdir/').get_response(self.test_staticweb)
|
||||
self.assertEqual(resp.status_int, 200)
|
||||
self.assertTrue('Listing of /v1/a/c4/subdir/' in resp.body)
|
||||
self.assertIn('Listing of /v1/a/c4/subdir/', resp.body)
|
||||
self.assertNotIn('</style>', resp.body)
|
||||
self.assertTrue('<link' in resp.body)
|
||||
self.assertTrue('href="../listing.css"' in resp.body)
|
||||
self.assertIn('<link', resp.body)
|
||||
self.assertIn('href="../listing.css"', resp.body)
|
||||
self.assertEqual(resp.headers['content-type'],
|
||||
'text/html; charset=UTF-8')
|
||||
|
||||
@ -768,7 +768,7 @@ class TestStaticWeb(unittest.TestCase):
|
||||
resp = Request.blank('/v1/a/c11a/subdir/').get_response(
|
||||
self.test_staticweb)
|
||||
self.assertEqual(resp.status_int, 404)
|
||||
self.assertTrue('Index File Not Found' in resp.body)
|
||||
self.assertIn('Index File Not Found', resp.body)
|
||||
|
||||
def test_container11subdirmarkeraltdirtype(self):
|
||||
resp = Request.blank('/v1/a/c11a/subdir2/').get_response(
|
||||
@ -784,20 +784,20 @@ class TestStaticWeb(unittest.TestCase):
|
||||
resp = Request.blank('/v1/a/c12/').get_response(
|
||||
self.test_staticweb)
|
||||
self.assertEqual(resp.status_int, 200)
|
||||
self.assertTrue('index file' in resp.body)
|
||||
self.assertIn('index file', resp.body)
|
||||
|
||||
def test_container_404_has_css(self):
|
||||
resp = Request.blank('/v1/a/c13/').get_response(
|
||||
self.test_staticweb)
|
||||
self.assertEqual(resp.status_int, 404)
|
||||
self.assertTrue('listing.css' in resp.body)
|
||||
self.assertIn('listing.css', resp.body)
|
||||
|
||||
def test_container_404_has_no_css(self):
|
||||
resp = Request.blank('/v1/a/c7/').get_response(
|
||||
self.test_staticweb)
|
||||
self.assertEqual(resp.status_int, 404)
|
||||
self.assertNotIn('listing.css', resp.body)
|
||||
self.assertTrue('<style' in resp.body)
|
||||
self.assertIn('<style', resp.body)
|
||||
|
||||
def test_subrequest_once_if_possible(self):
|
||||
resp = Request.blank(
|
||||
|
@ -407,8 +407,8 @@ class TestTempURL(unittest.TestCase):
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEqual(resp.status_int, 401)
|
||||
self.assertTrue('Temp URL invalid' in resp.body)
|
||||
self.assertTrue('Www-Authenticate' in resp.headers)
|
||||
self.assertIn('Temp URL invalid', resp.body)
|
||||
self.assertIn('Www-Authenticate', resp.headers)
|
||||
|
||||
def test_put_valid(self):
|
||||
method = 'PUT'
|
||||
@ -440,8 +440,8 @@ class TestTempURL(unittest.TestCase):
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEqual(resp.status_int, 401)
|
||||
self.assertTrue('Temp URL invalid' in resp.body)
|
||||
self.assertTrue('Www-Authenticate' in resp.headers)
|
||||
self.assertIn('Temp URL invalid', resp.body)
|
||||
self.assertIn('Www-Authenticate', resp.headers)
|
||||
|
||||
def test_missing_sig(self):
|
||||
method = 'GET'
|
||||
@ -455,8 +455,8 @@ class TestTempURL(unittest.TestCase):
|
||||
environ={'QUERY_STRING': 'temp_url_expires=%s' % expires})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEqual(resp.status_int, 401)
|
||||
self.assertTrue('Temp URL invalid' in resp.body)
|
||||
self.assertTrue('Www-Authenticate' in resp.headers)
|
||||
self.assertIn('Temp URL invalid', resp.body)
|
||||
self.assertIn('Www-Authenticate', resp.headers)
|
||||
|
||||
def test_missing_expires(self):
|
||||
method = 'GET'
|
||||
@ -470,8 +470,8 @@ class TestTempURL(unittest.TestCase):
|
||||
environ={'QUERY_STRING': 'temp_url_sig=%s' % sig})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEqual(resp.status_int, 401)
|
||||
self.assertTrue('Temp URL invalid' in resp.body)
|
||||
self.assertTrue('Www-Authenticate' in resp.headers)
|
||||
self.assertIn('Temp URL invalid', resp.body)
|
||||
self.assertIn('Www-Authenticate', resp.headers)
|
||||
|
||||
def test_bad_path(self):
|
||||
method = 'GET'
|
||||
@ -486,8 +486,8 @@ class TestTempURL(unittest.TestCase):
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEqual(resp.status_int, 401)
|
||||
self.assertTrue('Temp URL invalid' in resp.body)
|
||||
self.assertTrue('Www-Authenticate' in resp.headers)
|
||||
self.assertIn('Temp URL invalid', resp.body)
|
||||
self.assertIn('Www-Authenticate', resp.headers)
|
||||
|
||||
def test_no_key(self):
|
||||
method = 'GET'
|
||||
@ -502,8 +502,8 @@ class TestTempURL(unittest.TestCase):
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEqual(resp.status_int, 401)
|
||||
self.assertTrue('Temp URL invalid' in resp.body)
|
||||
self.assertTrue('Www-Authenticate' in resp.headers)
|
||||
self.assertIn('Temp URL invalid', resp.body)
|
||||
self.assertIn('Www-Authenticate', resp.headers)
|
||||
|
||||
def test_head_allowed_by_get(self):
|
||||
method = 'GET'
|
||||
@ -573,7 +573,7 @@ class TestTempURL(unittest.TestCase):
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEqual(resp.status_int, 401)
|
||||
self.assertTrue('Www-Authenticate' in resp.headers)
|
||||
self.assertIn('Www-Authenticate', resp.headers)
|
||||
|
||||
def test_post_when_forbidden_by_config(self):
|
||||
self.tempurl.conf['methods'].remove('POST')
|
||||
@ -590,8 +590,8 @@ class TestTempURL(unittest.TestCase):
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEqual(resp.status_int, 401)
|
||||
self.assertTrue('Temp URL invalid' in resp.body)
|
||||
self.assertTrue('Www-Authenticate' in resp.headers)
|
||||
self.assertIn('Temp URL invalid', resp.body)
|
||||
self.assertIn('Www-Authenticate', resp.headers)
|
||||
|
||||
def test_delete_when_forbidden_by_config(self):
|
||||
self.tempurl.conf['methods'].remove('DELETE')
|
||||
@ -608,8 +608,8 @@ class TestTempURL(unittest.TestCase):
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEqual(resp.status_int, 401)
|
||||
self.assertTrue('Temp URL invalid' in resp.body)
|
||||
self.assertTrue('Www-Authenticate' in resp.headers)
|
||||
self.assertIn('Temp URL invalid', resp.body)
|
||||
self.assertIn('Www-Authenticate', resp.headers)
|
||||
|
||||
def test_delete_allowed(self):
|
||||
method = 'DELETE'
|
||||
@ -640,8 +640,8 @@ class TestTempURL(unittest.TestCase):
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEqual(resp.status_int, 401)
|
||||
self.assertTrue('Temp URL invalid' in resp.body)
|
||||
self.assertTrue('Www-Authenticate' in resp.headers)
|
||||
self.assertIn('Temp URL invalid', resp.body)
|
||||
self.assertIn('Www-Authenticate', resp.headers)
|
||||
|
||||
def test_authorize_limits_scope(self):
|
||||
req_other_object = Request.blank("/v1/a/c/o2")
|
||||
@ -731,8 +731,8 @@ class TestTempURL(unittest.TestCase):
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEqual(resp.status_int, 401)
|
||||
self.assertTrue('Temp URL invalid' in resp.body)
|
||||
self.assertTrue('Www-Authenticate' in resp.headers)
|
||||
self.assertIn('Temp URL invalid', resp.body)
|
||||
self.assertIn('Www-Authenticate', resp.headers)
|
||||
|
||||
def test_changed_sig_invalid(self):
|
||||
method = 'GET'
|
||||
@ -751,8 +751,8 @@ class TestTempURL(unittest.TestCase):
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEqual(resp.status_int, 401)
|
||||
self.assertTrue('Temp URL invalid' in resp.body)
|
||||
self.assertTrue('Www-Authenticate' in resp.headers)
|
||||
self.assertIn('Temp URL invalid', resp.body)
|
||||
self.assertIn('Www-Authenticate', resp.headers)
|
||||
|
||||
def test_changed_expires_invalid(self):
|
||||
method = 'GET'
|
||||
@ -767,8 +767,8 @@ class TestTempURL(unittest.TestCase):
|
||||
sig, expires + 1)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEqual(resp.status_int, 401)
|
||||
self.assertTrue('Temp URL invalid' in resp.body)
|
||||
self.assertTrue('Www-Authenticate' in resp.headers)
|
||||
self.assertIn('Temp URL invalid', resp.body)
|
||||
self.assertIn('Www-Authenticate', resp.headers)
|
||||
|
||||
def test_different_key_invalid(self):
|
||||
method = 'GET'
|
||||
@ -783,8 +783,8 @@ class TestTempURL(unittest.TestCase):
|
||||
sig, expires)})
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEqual(resp.status_int, 401)
|
||||
self.assertTrue('Temp URL invalid' in resp.body)
|
||||
self.assertTrue('Www-Authenticate' in resp.headers)
|
||||
self.assertIn('Temp URL invalid', resp.body)
|
||||
self.assertIn('Www-Authenticate', resp.headers)
|
||||
|
||||
def test_disallowed_header_object_manifest(self):
|
||||
self.tempurl = tempurl.filter_factory({})(self.auth)
|
||||
@ -1075,7 +1075,7 @@ class TestTempURL(unittest.TestCase):
|
||||
self.tempurl)
|
||||
self.assertEqual(resp.status_int, 401)
|
||||
self.assertNotIn('Temp URL invalid', resp.body)
|
||||
self.assertTrue('Www-Authenticate' in resp.headers)
|
||||
self.assertIn('Www-Authenticate', resp.headers)
|
||||
self.assertNotIn('swift.auth_scheme', environ)
|
||||
|
||||
# Rejected by TempURL
|
||||
@ -1086,8 +1086,8 @@ class TestTempURL(unittest.TestCase):
|
||||
environ=environ)
|
||||
resp = req.get_response(self.tempurl)
|
||||
self.assertEqual(resp.status_int, 401)
|
||||
self.assertTrue('Temp URL invalid' in resp.body)
|
||||
self.assertTrue('Www-Authenticate' in resp.headers)
|
||||
self.assertIn('Temp URL invalid', resp.body)
|
||||
self.assertIn('Www-Authenticate', resp.headers)
|
||||
|
||||
def test_clean_incoming_headers(self):
|
||||
irh = []
|
||||
@ -1097,7 +1097,7 @@ class TestTempURL(unittest.TestCase):
|
||||
None, {'incoming_remove_headers': irh,
|
||||
'incoming_allow_headers': iah}
|
||||
)._clean_incoming_headers(env)
|
||||
self.assertTrue('HTTP_TEST_HEADER' in env)
|
||||
self.assertIn('HTTP_TEST_HEADER', env)
|
||||
|
||||
irh = ['test-header']
|
||||
iah = []
|
||||
@ -1128,7 +1128,7 @@ class TestTempURL(unittest.TestCase):
|
||||
'incoming_allow_headers': iah}
|
||||
)._clean_incoming_headers(env)
|
||||
self.assertNotIn('HTTP_TEST_HEADER_ONE', env)
|
||||
self.assertTrue('HTTP_TEST_HEADER_TWO' in env)
|
||||
self.assertIn('HTTP_TEST_HEADER_TWO', env)
|
||||
|
||||
irh = ['test-header-*', 'test-other-header']
|
||||
iah = ['test-header-two', 'test-header-yes-*']
|
||||
@ -1142,10 +1142,10 @@ class TestTempURL(unittest.TestCase):
|
||||
'incoming_allow_headers': iah}
|
||||
)._clean_incoming_headers(env)
|
||||
self.assertNotIn('HTTP_TEST_HEADER_ONE', env)
|
||||
self.assertTrue('HTTP_TEST_HEADER_TWO' in env)
|
||||
self.assertIn('HTTP_TEST_HEADER_TWO', env)
|
||||
self.assertNotIn('HTTP_TEST_OTHER_HEADER', env)
|
||||
self.assertNotIn('HTTP_TEST_HEADER_YES', env)
|
||||
self.assertTrue('HTTP_TEST_HEADER_YES_THIS' in env)
|
||||
self.assertIn('HTTP_TEST_HEADER_YES_THIS', env)
|
||||
|
||||
def test_clean_outgoing_headers(self):
|
||||
orh = []
|
||||
@ -1155,7 +1155,7 @@ class TestTempURL(unittest.TestCase):
|
||||
None,
|
||||
{'outgoing_remove_headers': orh, 'outgoing_allow_headers': oah}
|
||||
)._clean_outgoing_headers(hdrs.items()))
|
||||
self.assertTrue('test-header' in hdrs)
|
||||
self.assertIn('test-header', hdrs)
|
||||
|
||||
orh = ['test-header']
|
||||
oah = []
|
||||
@ -1186,7 +1186,7 @@ class TestTempURL(unittest.TestCase):
|
||||
{'outgoing_remove_headers': orh, 'outgoing_allow_headers': oah}
|
||||
)._clean_outgoing_headers(hdrs.items()))
|
||||
self.assertNotIn('test-header-one', hdrs)
|
||||
self.assertTrue('test-header-two' in hdrs)
|
||||
self.assertIn('test-header-two', hdrs)
|
||||
|
||||
orh = ['test-header-*', 'test-other-header']
|
||||
oah = ['test-header-two', 'test-header-yes-*']
|
||||
@ -1200,16 +1200,16 @@ class TestTempURL(unittest.TestCase):
|
||||
{'outgoing_remove_headers': orh, 'outgoing_allow_headers': oah}
|
||||
)._clean_outgoing_headers(hdrs.items()))
|
||||
self.assertNotIn('test-header-one', hdrs)
|
||||
self.assertTrue('test-header-two' in hdrs)
|
||||
self.assertIn('test-header-two', hdrs)
|
||||
self.assertNotIn('test-other-header', hdrs)
|
||||
self.assertNotIn('test-header-yes', hdrs)
|
||||
self.assertTrue('test-header-yes-this' in hdrs)
|
||||
self.assertIn('test-header-yes-this', hdrs)
|
||||
|
||||
def test_unicode_metadata_value(self):
|
||||
meta = {"temp-url-key": "test", "temp-url-key-2": u"test2"}
|
||||
results = tempurl.get_tempurl_keys_from_metadata(meta)
|
||||
for str_value in results:
|
||||
self.assertTrue(isinstance(str_value, str))
|
||||
self.assertIsInstance(str_value, str)
|
||||
|
||||
|
||||
class TestSwiftInfo(unittest.TestCase):
|
||||
@ -1220,7 +1220,7 @@ class TestSwiftInfo(unittest.TestCase):
|
||||
def test_registered_defaults(self):
|
||||
tempurl.filter_factory({})
|
||||
swift_info = utils.get_swift_info()
|
||||
self.assertTrue('tempurl' in swift_info)
|
||||
self.assertIn('tempurl', swift_info)
|
||||
info = swift_info['tempurl']
|
||||
self.assertEqual(set(info['methods']),
|
||||
set(('GET', 'HEAD', 'PUT', 'POST', 'DELETE')))
|
||||
@ -1241,7 +1241,7 @@ class TestSwiftInfo(unittest.TestCase):
|
||||
'outgoing_allow_headers': 'x-object-meta-* content-type',
|
||||
})
|
||||
swift_info = utils.get_swift_info()
|
||||
self.assertTrue('tempurl' in swift_info)
|
||||
self.assertIn('tempurl', swift_info)
|
||||
info = swift_info['tempurl']
|
||||
self.assertEqual(set(info['methods']),
|
||||
set(('GET', 'HEAD', 'PUT', 'DELETE', 'BREW')))
|
||||
|
@ -51,14 +51,14 @@ class TestDatabaseConnectionError(unittest.TestCase):
|
||||
def test_str(self):
|
||||
err = \
|
||||
DatabaseConnectionError(':memory:', 'No valid database connection')
|
||||
self.assertTrue(':memory:' in str(err))
|
||||
self.assertTrue('No valid database connection' in str(err))
|
||||
self.assertIn(':memory:', str(err))
|
||||
self.assertIn('No valid database connection', str(err))
|
||||
err = DatabaseConnectionError(':memory:',
|
||||
'No valid database connection',
|
||||
timeout=1357)
|
||||
self.assertTrue(':memory:' in str(err))
|
||||
self.assertTrue('No valid database connection' in str(err))
|
||||
self.assertTrue('1357' in str(err))
|
||||
self.assertIn(':memory:', str(err))
|
||||
self.assertIn('No valid database connection', str(err))
|
||||
self.assertIn('1357', str(err))
|
||||
|
||||
|
||||
class TestDictFactory(unittest.TestCase):
|
||||
@ -607,7 +607,7 @@ class TestDatabaseBroker(unittest.TestCase):
|
||||
db_file = os.path.join(self.testdir, '1.db')
|
||||
broker = DatabaseBroker(db_file)
|
||||
self.assertEqual(broker.db_file, db_file)
|
||||
self.assertTrue(broker.conn is None)
|
||||
self.assertIsNone(broker.conn)
|
||||
|
||||
def test_disk_preallocate(self):
|
||||
test_size = [-1]
|
||||
@ -676,7 +676,7 @@ class TestDatabaseBroker(unittest.TestCase):
|
||||
broker._initialize = init_stub
|
||||
# Initializes a good broker for us
|
||||
broker.initialize(normalize_timestamp('1'))
|
||||
self.assertTrue(broker.conn is not None)
|
||||
self.assertIsNotNone(broker.conn)
|
||||
broker._delete_db = delete_stub
|
||||
stub_called[0] = False
|
||||
broker.delete_db('2')
|
||||
@ -1077,58 +1077,58 @@ class TestDatabaseBroker(unittest.TestCase):
|
||||
first_timestamp = normalize_timestamp(1)
|
||||
first_value = '1'
|
||||
broker.update_metadata({'First': [first_value, first_timestamp]})
|
||||
self.assertTrue('First' in broker.metadata)
|
||||
self.assertIn('First', broker.metadata)
|
||||
self.assertEqual(broker.metadata['First'],
|
||||
[first_value, first_timestamp])
|
||||
# Add our second item
|
||||
second_timestamp = normalize_timestamp(2)
|
||||
second_value = '2'
|
||||
broker.update_metadata({'Second': [second_value, second_timestamp]})
|
||||
self.assertTrue('First' in broker.metadata)
|
||||
self.assertIn('First', broker.metadata)
|
||||
self.assertEqual(broker.metadata['First'],
|
||||
[first_value, first_timestamp])
|
||||
self.assertTrue('Second' in broker.metadata)
|
||||
self.assertIn('Second', broker.metadata)
|
||||
self.assertEqual(broker.metadata['Second'],
|
||||
[second_value, second_timestamp])
|
||||
# Update our first item
|
||||
first_timestamp = normalize_timestamp(3)
|
||||
first_value = '1b'
|
||||
broker.update_metadata({'First': [first_value, first_timestamp]})
|
||||
self.assertTrue('First' in broker.metadata)
|
||||
self.assertIn('First', broker.metadata)
|
||||
self.assertEqual(broker.metadata['First'],
|
||||
[first_value, first_timestamp])
|
||||
self.assertTrue('Second' in broker.metadata)
|
||||
self.assertIn('Second', broker.metadata)
|
||||
self.assertEqual(broker.metadata['Second'],
|
||||
[second_value, second_timestamp])
|
||||
# Delete our second item (by setting to empty string)
|
||||
second_timestamp = normalize_timestamp(4)
|
||||
second_value = ''
|
||||
broker.update_metadata({'Second': [second_value, second_timestamp]})
|
||||
self.assertTrue('First' in broker.metadata)
|
||||
self.assertIn('First', broker.metadata)
|
||||
self.assertEqual(broker.metadata['First'],
|
||||
[first_value, first_timestamp])
|
||||
self.assertTrue('Second' in broker.metadata)
|
||||
self.assertIn('Second', broker.metadata)
|
||||
self.assertEqual(broker.metadata['Second'],
|
||||
[second_value, second_timestamp])
|
||||
# Reclaim at point before second item was deleted
|
||||
reclaim(broker, normalize_timestamp(3))
|
||||
self.assertTrue('First' in broker.metadata)
|
||||
self.assertIn('First', broker.metadata)
|
||||
self.assertEqual(broker.metadata['First'],
|
||||
[first_value, first_timestamp])
|
||||
self.assertTrue('Second' in broker.metadata)
|
||||
self.assertIn('Second', broker.metadata)
|
||||
self.assertEqual(broker.metadata['Second'],
|
||||
[second_value, second_timestamp])
|
||||
# Reclaim at point second item was deleted
|
||||
reclaim(broker, normalize_timestamp(4))
|
||||
self.assertTrue('First' in broker.metadata)
|
||||
self.assertIn('First', broker.metadata)
|
||||
self.assertEqual(broker.metadata['First'],
|
||||
[first_value, first_timestamp])
|
||||
self.assertTrue('Second' in broker.metadata)
|
||||
self.assertIn('Second', broker.metadata)
|
||||
self.assertEqual(broker.metadata['Second'],
|
||||
[second_value, second_timestamp])
|
||||
# Reclaim after point second item was deleted
|
||||
reclaim(broker, normalize_timestamp(5))
|
||||
self.assertTrue('First' in broker.metadata)
|
||||
self.assertIn('First', broker.metadata)
|
||||
self.assertEqual(broker.metadata['First'],
|
||||
[first_value, first_timestamp])
|
||||
self.assertNotIn('Second', broker.metadata)
|
||||
|
@ -528,8 +528,7 @@ class TestDirectClient(unittest.TestCase):
|
||||
|
||||
self.assertEqual(conn.req_headers['user-agent'], self.user_agent)
|
||||
self.assertEqual('bar', conn.req_headers.get('x-foo'))
|
||||
self.assertNotIn('x-timestamp', conn.req_headers,
|
||||
'x-timestamp was in HEAD request headers')
|
||||
self.assertNotIn('x-timestamp', conn.req_headers)
|
||||
self.assertEqual(headers, resp)
|
||||
|
||||
def test_direct_head_object_error(self):
|
||||
|
@ -483,7 +483,7 @@ class TestServer(unittest.TestCase):
|
||||
# check verbose lists configs
|
||||
conf_files = server.conf_files(number=2, verbose=True)
|
||||
c1 = self.join_swift_dir('container-server/1.conf')
|
||||
self.assertTrue(c1 in pop_stream(f))
|
||||
self.assertIn(c1, pop_stream(f))
|
||||
finally:
|
||||
sys.stdout = old_stdout
|
||||
|
||||
@ -719,11 +719,11 @@ class TestServer(unittest.TestCase):
|
||||
server = manager.Server('proxy', run_dir=manager.RUN_DIR)
|
||||
pids = server.signal_pids(DUMMY_SIG)
|
||||
self.assertEqual(len(pids), 1)
|
||||
self.assertTrue(1 in pids)
|
||||
self.assertIn(1, pids)
|
||||
self.assertEqual(manager.os.pid_sigs[1], [DUMMY_SIG])
|
||||
# make sure other process not signaled
|
||||
self.assertFalse(2 in pids)
|
||||
self.assertFalse(2 in manager.os.pid_sigs)
|
||||
self.assertNotIn(2, pids)
|
||||
self.assertNotIn(2, manager.os.pid_sigs)
|
||||
# capture stdio
|
||||
old_stdout = sys.stdout
|
||||
try:
|
||||
@ -732,8 +732,8 @@ class TestServer(unittest.TestCase):
|
||||
# test print details
|
||||
pids = server.signal_pids(DUMMY_SIG)
|
||||
output = pop_stream(f)
|
||||
self.assertTrue('pid: %s' % 1 in output)
|
||||
self.assertTrue('signal: %s' % DUMMY_SIG in output)
|
||||
self.assertIn('pid: %s' % 1, output)
|
||||
self.assertIn('signal: %s' % DUMMY_SIG, output)
|
||||
# test no details on signal.SIG_DFL
|
||||
pids = server.signal_pids(signal.SIG_DFL)
|
||||
self.assertEqual(pop_stream(f), '')
|
||||
@ -817,7 +817,7 @@ class TestServer(unittest.TestCase):
|
||||
manager.os = MockOs([1, 3])
|
||||
running_pids = server.get_running_pids()
|
||||
self.assertEqual(len(running_pids), 1)
|
||||
self.assertTrue(1 in running_pids)
|
||||
self.assertIn(1, running_pids)
|
||||
self.assertNotIn(2, running_pids)
|
||||
self.assertNotIn(3, running_pids)
|
||||
# test persistent running pid files
|
||||
@ -854,7 +854,7 @@ class TestServer(unittest.TestCase):
|
||||
running_pids = server.get_running_pids()
|
||||
# only thing-doer.pid, 1
|
||||
self.assertEqual(len(running_pids), 1)
|
||||
self.assertTrue(1 in running_pids)
|
||||
self.assertIn(1, running_pids)
|
||||
# no other pids returned
|
||||
for n in (2, 3, 4):
|
||||
self.assertNotIn(n, running_pids)
|
||||
@ -898,7 +898,7 @@ class TestServer(unittest.TestCase):
|
||||
# test kill one pid
|
||||
pids = server.kill_running_pids()
|
||||
self.assertEqual(len(pids), 1)
|
||||
self.assertTrue(1 in pids)
|
||||
self.assertIn(1, pids)
|
||||
self.assertEqual(manager.os.pid_sigs[1], [signal.SIGTERM])
|
||||
# reset os mock
|
||||
manager.os = MockOs([1])
|
||||
@ -907,7 +907,7 @@ class TestServer(unittest.TestCase):
|
||||
manager.GRACEFUL_SHUTDOWN_SERVERS)
|
||||
pids = server.kill_running_pids(graceful=True)
|
||||
self.assertEqual(len(pids), 1)
|
||||
self.assertTrue(1 in pids)
|
||||
self.assertIn(1, pids)
|
||||
self.assertEqual(manager.os.pid_sigs[1], [signal.SIGHUP])
|
||||
# start up other servers
|
||||
manager.os = MockOs([11, 12])
|
||||
@ -1242,8 +1242,8 @@ class TestServer(unittest.TestCase):
|
||||
server.procs = [proc]
|
||||
status = server.wait(output=True)
|
||||
output = pop_stream(f)
|
||||
self.assertTrue('mock process started' in output)
|
||||
self.assertTrue('setup complete' in output)
|
||||
self.assertIn('mock process started', output)
|
||||
self.assertIn('setup complete', output)
|
||||
# make sure we don't get prints after stdout was closed
|
||||
self.assertNotIn('mock process finished', output)
|
||||
# test process which fails to start
|
||||
@ -1251,7 +1251,7 @@ class TestServer(unittest.TestCase):
|
||||
server.procs = [proc]
|
||||
status = server.wait()
|
||||
self.assertEqual(status, 1)
|
||||
self.assertTrue('failed' in pop_stream(f))
|
||||
self.assertIn('failed', pop_stream(f))
|
||||
# test multiple procs
|
||||
procs = [MockProcess(delay=.5) for i in range(3)]
|
||||
for proc in procs:
|
||||
@ -1385,7 +1385,7 @@ class TestServer(unittest.TestCase):
|
||||
}
|
||||
self.assertEqual(mock_spawn.kwargs, [expected])
|
||||
output = pop_stream(f)
|
||||
self.assertTrue('Starting' in output)
|
||||
self.assertIn('Starting', output)
|
||||
self.assertNotIn('once', output)
|
||||
# test multi-server kwarg once
|
||||
server = manager.Server('object-replicator')
|
||||
|
@ -268,21 +268,21 @@ class TestMatch(unittest.TestCase):
|
||||
def test_match(self):
|
||||
match = swift.common.swob.Match('"a", "b"')
|
||||
self.assertEqual(match.tags, set(('a', 'b')))
|
||||
self.assertTrue('a' in match)
|
||||
self.assertTrue('b' in match)
|
||||
self.assertIn('a', match)
|
||||
self.assertIn('b', match)
|
||||
self.assertNotIn('c', match)
|
||||
|
||||
def test_match_star(self):
|
||||
match = swift.common.swob.Match('"a", "*"')
|
||||
self.assertTrue('a' in match)
|
||||
self.assertTrue('b' in match)
|
||||
self.assertTrue('c' in match)
|
||||
self.assertIn('a', match)
|
||||
self.assertIn('b', match)
|
||||
self.assertIn('c', match)
|
||||
|
||||
def test_match_noquote(self):
|
||||
match = swift.common.swob.Match('a, b')
|
||||
self.assertEqual(match.tags, set(('a', 'b')))
|
||||
self.assertTrue('a' in match)
|
||||
self.assertTrue('b' in match)
|
||||
self.assertIn('a', match)
|
||||
self.assertIn('b', match)
|
||||
self.assertNotIn('c', match)
|
||||
|
||||
|
||||
@ -742,7 +742,7 @@ class TestRequest(unittest.TestCase):
|
||||
req.range = 'bytes=1-7'
|
||||
self.assertEqual(req.range.ranges[0], (1, 7))
|
||||
|
||||
self.assertTrue('Range' in req.headers)
|
||||
self.assertIn('Range', req.headers)
|
||||
req.range = None
|
||||
self.assertNotIn('Range', req.headers)
|
||||
|
||||
@ -759,7 +759,7 @@ class TestRequest(unittest.TestCase):
|
||||
self.assertEqual(req.headers['If-Unmodified-Since'], 'something')
|
||||
self.assertEqual(req.if_unmodified_since, None)
|
||||
|
||||
self.assertTrue('If-Unmodified-Since' in req.headers)
|
||||
self.assertIn('If-Unmodified-Since', req.headers)
|
||||
req.if_unmodified_since = None
|
||||
self.assertNotIn('If-Unmodified-Since', req.headers)
|
||||
|
||||
@ -1030,12 +1030,12 @@ class TestResponse(unittest.TestCase):
|
||||
|
||||
resp.location = 'something'
|
||||
self.assertEqual(resp.location, 'something')
|
||||
self.assertTrue('Location' in resp.headers)
|
||||
self.assertIn('Location', resp.headers)
|
||||
resp.location = None
|
||||
self.assertNotIn('Location', resp.headers)
|
||||
|
||||
resp.content_type = 'text/plain'
|
||||
self.assertTrue('Content-Type' in resp.headers)
|
||||
self.assertIn('Content-Type', resp.headers)
|
||||
resp.content_type = None
|
||||
self.assertNotIn('Content-Type', resp.headers)
|
||||
|
||||
@ -1357,7 +1357,7 @@ class TestResponse(unittest.TestCase):
|
||||
self.assertEqual(resp.headers['Etag'], '"hi"')
|
||||
self.assertEqual(resp.etag, 'hi')
|
||||
|
||||
self.assertTrue('etag' in resp.headers)
|
||||
self.assertIn('etag', resp.headers)
|
||||
resp.etag = None
|
||||
self.assertNotIn('etag', resp.headers)
|
||||
|
||||
|
@ -1550,7 +1550,7 @@ class TestUtils(unittest.TestCase):
|
||||
log_exception(OSError(en, 'my %s error message' % en))
|
||||
log_msg = strip_value(sio)
|
||||
self.assertNotIn('Traceback', log_msg)
|
||||
self.assertTrue('my %s error message' % en in log_msg)
|
||||
self.assertIn('my %s error message' % en, log_msg)
|
||||
# unfiltered
|
||||
log_exception(OSError())
|
||||
self.assertTrue('Traceback' in strip_value(sio))
|
||||
@ -1561,23 +1561,23 @@ class TestUtils(unittest.TestCase):
|
||||
log_msg = strip_value(sio)
|
||||
self.assertNotIn('Traceback', log_msg)
|
||||
self.assertNotIn('errno.ECONNREFUSED message test', log_msg)
|
||||
self.assertTrue('Connection refused' in log_msg)
|
||||
self.assertIn('Connection refused', log_msg)
|
||||
log_exception(socket.error(errno.EHOSTUNREACH,
|
||||
'my error message'))
|
||||
log_msg = strip_value(sio)
|
||||
self.assertNotIn('Traceback', log_msg)
|
||||
self.assertNotIn('my error message', log_msg)
|
||||
self.assertTrue('Host unreachable' in log_msg)
|
||||
self.assertIn('Host unreachable', log_msg)
|
||||
log_exception(socket.error(errno.ETIMEDOUT, 'my error message'))
|
||||
log_msg = strip_value(sio)
|
||||
self.assertNotIn('Traceback', log_msg)
|
||||
self.assertNotIn('my error message', log_msg)
|
||||
self.assertTrue('Connection timeout' in log_msg)
|
||||
self.assertIn('Connection timeout', log_msg)
|
||||
# unfiltered
|
||||
log_exception(socket.error(0, 'my error message'))
|
||||
log_msg = strip_value(sio)
|
||||
self.assertTrue('Traceback' in log_msg)
|
||||
self.assertTrue('my error message' in log_msg)
|
||||
self.assertIn('Traceback', log_msg)
|
||||
self.assertIn('my error message', log_msg)
|
||||
|
||||
# test eventlet.Timeout
|
||||
connection_timeout = ConnectionTimeout(42, 'my error message')
|
||||
@ -1682,19 +1682,19 @@ class TestUtils(unittest.TestCase):
|
||||
self.assertFalse(logger.txn_id)
|
||||
logger.error('my error message')
|
||||
log_msg = strip_value(sio)
|
||||
self.assertTrue('my error message' in log_msg)
|
||||
self.assertIn('my error message', log_msg)
|
||||
self.assertNotIn('txn', log_msg)
|
||||
logger.txn_id = '12345'
|
||||
logger.error('test')
|
||||
log_msg = strip_value(sio)
|
||||
self.assertTrue('txn' in log_msg)
|
||||
self.assertTrue('12345' in log_msg)
|
||||
self.assertIn('txn', log_msg)
|
||||
self.assertIn('12345', log_msg)
|
||||
# test txn in info message
|
||||
self.assertEqual(logger.txn_id, '12345')
|
||||
logger.info('test')
|
||||
log_msg = strip_value(sio)
|
||||
self.assertTrue('txn' in log_msg)
|
||||
self.assertTrue('12345' in log_msg)
|
||||
self.assertIn('txn', log_msg)
|
||||
self.assertIn('12345', log_msg)
|
||||
# test txn already in message
|
||||
self.assertEqual(logger.txn_id, '12345')
|
||||
logger.warning('test 12345 test')
|
||||
@ -1702,19 +1702,19 @@ class TestUtils(unittest.TestCase):
|
||||
# Test multi line collapsing
|
||||
logger.error('my\nerror\nmessage')
|
||||
log_msg = strip_value(sio)
|
||||
self.assertTrue('my#012error#012message' in log_msg)
|
||||
self.assertIn('my#012error#012message', log_msg)
|
||||
|
||||
# test client_ip
|
||||
self.assertFalse(logger.client_ip)
|
||||
logger.error('my error message')
|
||||
log_msg = strip_value(sio)
|
||||
self.assertTrue('my error message' in log_msg)
|
||||
self.assertIn('my error message', log_msg)
|
||||
self.assertNotIn('client_ip', log_msg)
|
||||
logger.client_ip = '1.2.3.4'
|
||||
logger.error('test')
|
||||
log_msg = strip_value(sio)
|
||||
self.assertTrue('client_ip' in log_msg)
|
||||
self.assertTrue('1.2.3.4' in log_msg)
|
||||
self.assertIn('client_ip', log_msg)
|
||||
self.assertIn('1.2.3.4', log_msg)
|
||||
# test no client_ip on info message
|
||||
self.assertEqual(logger.client_ip, '1.2.3.4')
|
||||
logger.info('test')
|
||||
@ -4024,12 +4024,12 @@ class TestSwiftInfo(unittest.TestCase):
|
||||
|
||||
self.assertNotIn('admin', info)
|
||||
|
||||
self.assertTrue('swift' in info)
|
||||
self.assertTrue('foo' in info['swift'])
|
||||
self.assertIn('swift', info)
|
||||
self.assertIn('foo', info['swift'])
|
||||
self.assertEqual(utils._swift_info['swift']['foo'], 'bar')
|
||||
|
||||
self.assertTrue('cap1' in info)
|
||||
self.assertTrue('cap1_foo' in info['cap1'])
|
||||
self.assertIn('cap1', info)
|
||||
self.assertIn('cap1_foo', info['cap1'])
|
||||
self.assertEqual(utils._swift_info['cap1']['cap1_foo'], 'cap1_bar')
|
||||
|
||||
def test_get_swift_info_with_disallowed_sections(self):
|
||||
@ -4043,14 +4043,14 @@ class TestSwiftInfo(unittest.TestCase):
|
||||
|
||||
self.assertNotIn('admin', info)
|
||||
|
||||
self.assertTrue('swift' in info)
|
||||
self.assertTrue('foo' in info['swift'])
|
||||
self.assertIn('swift', info)
|
||||
self.assertIn('foo', info['swift'])
|
||||
self.assertEqual(info['swift']['foo'], 'bar')
|
||||
|
||||
self.assertNotIn('cap1', info)
|
||||
|
||||
self.assertTrue('cap2' in info)
|
||||
self.assertTrue('cap2_foo' in info['cap2'])
|
||||
self.assertIn('cap2', info)
|
||||
self.assertIn('cap2_foo', info['cap2'])
|
||||
self.assertEqual(info['cap2']['cap2_foo'], 'cap2_bar')
|
||||
|
||||
self.assertNotIn('cap3', info)
|
||||
@ -4061,19 +4061,19 @@ class TestSwiftInfo(unittest.TestCase):
|
||||
utils.register_swift_info('cap1', admin=True, ac1_foo='ac1_bar')
|
||||
utils.register_swift_info('cap1', admin=True, ac1_lorem='ac1_ipsum')
|
||||
|
||||
self.assertTrue('swift' in utils._swift_admin_info)
|
||||
self.assertTrue('admin_foo' in utils._swift_admin_info['swift'])
|
||||
self.assertIn('swift', utils._swift_admin_info)
|
||||
self.assertIn('admin_foo', utils._swift_admin_info['swift'])
|
||||
self.assertEqual(
|
||||
utils._swift_admin_info['swift']['admin_foo'], 'admin_bar')
|
||||
self.assertTrue('admin_lorem' in utils._swift_admin_info['swift'])
|
||||
self.assertIn('admin_lorem', utils._swift_admin_info['swift'])
|
||||
self.assertEqual(
|
||||
utils._swift_admin_info['swift']['admin_lorem'], 'admin_ipsum')
|
||||
|
||||
self.assertTrue('cap1' in utils._swift_admin_info)
|
||||
self.assertTrue('ac1_foo' in utils._swift_admin_info['cap1'])
|
||||
self.assertIn('cap1', utils._swift_admin_info)
|
||||
self.assertIn('ac1_foo', utils._swift_admin_info['cap1'])
|
||||
self.assertEqual(
|
||||
utils._swift_admin_info['cap1']['ac1_foo'], 'ac1_bar')
|
||||
self.assertTrue('ac1_lorem' in utils._swift_admin_info['cap1'])
|
||||
self.assertIn('ac1_lorem', utils._swift_admin_info['cap1'])
|
||||
self.assertEqual(
|
||||
utils._swift_admin_info['cap1']['ac1_lorem'], 'ac1_ipsum')
|
||||
|
||||
@ -4087,17 +4087,17 @@ class TestSwiftInfo(unittest.TestCase):
|
||||
|
||||
info = utils.get_swift_info(admin=True)
|
||||
|
||||
self.assertTrue('admin' in info)
|
||||
self.assertTrue('admin_cap1' in info['admin'])
|
||||
self.assertTrue('ac1_foo' in info['admin']['admin_cap1'])
|
||||
self.assertIn('admin', info)
|
||||
self.assertIn('admin_cap1', info['admin'])
|
||||
self.assertIn('ac1_foo', info['admin']['admin_cap1'])
|
||||
self.assertEqual(info['admin']['admin_cap1']['ac1_foo'], 'ac1_bar')
|
||||
|
||||
self.assertTrue('swift' in info)
|
||||
self.assertTrue('foo' in info['swift'])
|
||||
self.assertIn('swift', info)
|
||||
self.assertIn('foo', info['swift'])
|
||||
self.assertEqual(utils._swift_info['swift']['foo'], 'bar')
|
||||
|
||||
self.assertTrue('cap1' in info)
|
||||
self.assertTrue('cap1_foo' in info['cap1'])
|
||||
self.assertIn('cap1', info)
|
||||
self.assertIn('cap1_foo', info['cap1'])
|
||||
self.assertEqual(utils._swift_info['cap1']['cap1_foo'], 'cap1_bar')
|
||||
|
||||
def test_get_swift_admin_info_with_disallowed_sections(self):
|
||||
@ -4110,23 +4110,23 @@ class TestSwiftInfo(unittest.TestCase):
|
||||
info = utils.get_swift_info(
|
||||
admin=True, disallowed_sections=['cap1', 'cap3'])
|
||||
|
||||
self.assertTrue('admin' in info)
|
||||
self.assertTrue('admin_cap1' in info['admin'])
|
||||
self.assertTrue('ac1_foo' in info['admin']['admin_cap1'])
|
||||
self.assertIn('admin', info)
|
||||
self.assertIn('admin_cap1', info['admin'])
|
||||
self.assertIn('ac1_foo', info['admin']['admin_cap1'])
|
||||
self.assertEqual(info['admin']['admin_cap1']['ac1_foo'], 'ac1_bar')
|
||||
self.assertTrue('disallowed_sections' in info['admin'])
|
||||
self.assertTrue('cap1' in info['admin']['disallowed_sections'])
|
||||
self.assertIn('disallowed_sections', info['admin'])
|
||||
self.assertIn('cap1', info['admin']['disallowed_sections'])
|
||||
self.assertNotIn('cap2', info['admin']['disallowed_sections'])
|
||||
self.assertTrue('cap3' in info['admin']['disallowed_sections'])
|
||||
self.assertIn('cap3', info['admin']['disallowed_sections'])
|
||||
|
||||
self.assertTrue('swift' in info)
|
||||
self.assertTrue('foo' in info['swift'])
|
||||
self.assertIn('swift', info)
|
||||
self.assertIn('foo', info['swift'])
|
||||
self.assertEqual(info['swift']['foo'], 'bar')
|
||||
|
||||
self.assertNotIn('cap1', info)
|
||||
|
||||
self.assertTrue('cap2' in info)
|
||||
self.assertTrue('cap2_foo' in info['cap2'])
|
||||
self.assertIn('cap2', info)
|
||||
self.assertIn('cap2_foo', info['cap2'])
|
||||
self.assertEqual(info['cap2']['cap2_foo'], 'cap2_bar')
|
||||
|
||||
self.assertNotIn('cap3', info)
|
||||
|
Loading…
Reference in New Issue
Block a user