From: Daira Hopwood Date: Fri, 26 Apr 2013 22:17:47 +0000 (+0100) Subject: Use 'fail*' rather than 'assert*' methods for consistency with other tests. X-Git-Url: https://git.rkrishnan.org/%5B/frontends/flags/index.php?a=commitdiff_plain;h=a230de6f1c3c87afece98e4d4bf45d11f8ade71a;p=tahoe-lafs%2Ftahoe-lafs.git Use 'fail*' rather than 'assert*' methods for consistency with other tests. Signed-off-by: Daira Hopwood --- diff --git a/src/allmydata/test/test_storage.py b/src/allmydata/test/test_storage.py index f7c71b51..72210c45 100644 --- a/src/allmydata/test/test_storage.py +++ b/src/allmydata/test/test_storage.py @@ -661,8 +661,8 @@ class GoogleStorageAuthenticationClient(unittest.TestCase): """ # Somewhat fragile tests, but better than nothing. auth = googlestorage_container.AuthenticationClient("u@example.com", "xxx123") - self.assertEqual(auth._credentials.service_account_name, "u@example.com") - self.assertEqual(auth._credentials.private_key, "xxx123".encode("base64").strip()) + self.failUnlessEqual(auth._credentials.service_account_name, "u@example.com") + self.failUnlessEqual(auth._credentials.private_key, "xxx123".encode("base64").strip()) def test_initial(self): """ @@ -673,7 +673,7 @@ class GoogleStorageAuthenticationClient(unittest.TestCase): "u@example.com", "xxx123", _credentialsClass=mock.create_autospec(SignedJwtAssertionCredentials), _deferToThread=defer.maybeDeferred) - self.assertEqual(auth._credentials.refresh.call_count, 1) + self.failUnlessEqual(auth._credentials.refresh.call_count, 1) def test_expired(self): """ @@ -688,7 +688,7 @@ class GoogleStorageAuthenticationClient(unittest.TestCase): auth._credentials.apply = lambda d: d.__setitem__('Authorization', 'xxx') auth._credentials.access_token_expired = True auth.get_authorization_header() - self.assertEqual(auth._credentials.refresh.call_count, 2) + self.failUnlessEqual(auth._credentials.refresh.call_count, 2) def test_no_refresh(self): """ @@ -703,7 +703,7 @@ class GoogleStorageAuthenticationClient(unittest.TestCase): auth._credentials.apply = lambda d: d.__setitem__('Authorization', 'xxx') auth._credentials.access_token_expired = False auth.get_authorization_header() - self.assertEqual(auth._credentials.refresh.call_count, 1) + self.failUnlessEqual(auth._credentials.refresh.call_count, 1) def test_header(self): """ @@ -721,8 +721,8 @@ class GoogleStorageAuthenticationClient(unittest.TestCase): _deferToThread=defer.maybeDeferred) result = [] auth.get_authorization_header().addCallback(result.append) - self.assertEqual(result, ["Bearer xxx"]) - self.assertIsInstance(result[0], bytes) + self.failUnlessEqual(result, ["Bearer xxx"]) + self.failUnlessIsInstance(result[0], bytes) def test_one_refresh(self): """ @@ -742,13 +742,13 @@ class GoogleStorageAuthenticationClient(unittest.TestCase): _credentialsClass=mock.create_autospec(SignedJwtAssertionCredentials), _deferToThread=fakeDeferToThread) # Initial authorization call happens... - self.assertEqual(len(results), 1) + self.failUnlessEqual(len(results), 1) # ... and still isn't finished, so next one doesn't run yet: auth._refresh_if_necessary(force=True) - self.assertEqual(len(results), 1) + self.failUnlessEqual(len(results), 1) # When first one finishes, second one can run: first.callback(None) - self.assertEqual(len(results), 0) + self.failUnlessEqual(len(results), 0) def test_refresh_call(self): """ @@ -761,14 +761,14 @@ class GoogleStorageAuthenticationClient(unittest.TestCase): class NoNetworkCreds(SignedJwtAssertionCredentials): def refresh(cred_self, http): cred_self.access_token = "xxx" - self.assertIsInstance(http, Http) - self.thread = thread.get_ident() + self.failUnlessIsInstance(http, Http) + self.thread_id = thread.get_ident() auth = googlestorage_container.AuthenticationClient( "u@example.com", "xxx123", _credentialsClass=NoNetworkCreds) def gotResult(ignore): - self.assertNotEqual(thread.get_ident(), self.thread) + self.failIfEqual(thread.get_ident(), self.thread_id) return auth.get_authorization_header().addCallback(gotResult) @@ -821,18 +821,18 @@ class ContainerRetryTests(unittest.TestCase, CloudStorageBackendMixin): "test", "GET", "http://example", {}, body=None, need_response_body=True).addCallback(result.append) # No response from first request yet: - self.assertFalse(result) - self.assertEqual(self.container._http_request.call_count, 1) + self.failIf(result) + self.failUnlessEqual(self.container._http_request.call_count, 1) self.container._http_request.assert_called_with( "test", "GET", "http://example", {}, body=None, need_response_body=True) # First response fails: first.errback(CloudServiceError(None, 500)) - self.assertFalse(result, result) - self.assertEqual(self.container._http_request.call_count, 1) + self.failIf(result, result) + self.failUnlessEqual(self.container._http_request.call_count, 1) self.reactor.advance(0.1) - self.assertEqual(self.container._http_request.call_count, 2) + self.failUnlessEqual(self.container._http_request.call_count, 2) self.container._http_request.assert_called_with( "test", "GET", "http://example", {}, body=None, need_response_body=True) @@ -840,7 +840,7 @@ class ContainerRetryTests(unittest.TestCase, CloudStorageBackendMixin): # Second response succeeds: done = object() second.callback(done) - self.assertEqual(result, [done]) + self.failUnlessEqual(result, [done]) def test_retry_random_exception(self): """ @@ -857,18 +857,18 @@ class ContainerRetryTests(unittest.TestCase, CloudStorageBackendMixin): need_response_body=True).addCallback(result.append) # No response from first request yet: - self.assertFalse(result) - self.assertEqual(self.container._http_request.call_count, 1) + self.failIf(result) + self.failUnlessEqual(self.container._http_request.call_count, 1) self.container._http_request.assert_called_with( "test", "GET", "http://example", {}, body=None, need_response_body=True) # First response fails: first.errback(NewException()) - self.assertFalse(result, result) - self.assertEqual(self.container._http_request.call_count, 1) + self.failIf(result, result) + self.failUnlessEqual(self.container._http_request.call_count, 1) self.reactor.advance(0.1) - self.assertEqual(self.container._http_request.call_count, 2) + self.failUnlessEqual(self.container._http_request.call_count, 2) self.container._http_request.assert_called_with( "test", "GET", "http://example", {}, body=None, need_response_body=True) @@ -962,7 +962,7 @@ class GoogleStorageBackend(unittest.TestCase, CloudStorageBackendMixin): http_response = self.mock_http_request() done = [] self.container.list_objects(prefix='xxx xxx').addCallback(done.append) - self.assertFalse(done) + self.failIf(done) self.container._http_request.assert_called_once_with( "Google Storage list objects", "GET", "https://storage.googleapis.com/thebucket?prefix=xxx%20xxx", @@ -974,23 +974,23 @@ class GoogleStorageBackend(unittest.TestCase, CloudStorageBackendMixin): need_response_body=True) http_response.callback((self.Response(200), LIST_RESPONSE)) listing = done[0] - self.assertEqual(listing.name, "thebucket") - self.assertEqual(listing.prefix, "xxx xxx") - self.assertEqual(listing.marker, "themark") - self.assertEqual(listing.max_keys, None) - self.assertEqual(listing.is_truncated, "false") - self.assertEqual(listing.common_prefixes, ["xxx", "xxx xxx"]) + self.failUnlessEqual(listing.name, "thebucket") + self.failUnlessEqual(listing.prefix, "xxx xxx") + self.failUnlessEqual(listing.marker, "themark") + self.failUnlessEqual(listing.max_keys, None) + self.failUnlessEqual(listing.is_truncated, "false") + self.failUnlessEqual(listing.common_prefixes, ["xxx", "xxx xxx"]) item1, item2 = listing.contents - self.assertEqual(item1.key, "xxx xxx1") - self.assertEqual(item1.modification_date, "2013-01-27T01:23:45.678Z") - self.assertEqual(item1.etag, '"abc"') - self.assertEqual(item1.size, 123) - self.assertEqual(item1.owner, None) # meh, who cares - self.assertEqual(item2.key, "xxx xxx2") - self.assertEqual(item2.modification_date, "2013-01-28T01:23:45.678Z") - self.assertEqual(item2.etag, '"def"') - self.assertEqual(item2.size, 456) - self.assertEqual(item2.owner, None) # meh, who cares + self.failUnlessEqual(item1.key, "xxx xxx1") + self.failUnlessEqual(item1.modification_date, "2013-01-27T01:23:45.678Z") + self.failUnlessEqual(item1.etag, '"abc"') + self.failUnlessEqual(item1.size, 123) + self.failUnlessEqual(item1.owner, None) # meh, who cares + self.failUnlessEqual(item2.key, "xxx xxx2") + self.failUnlessEqual(item2.modification_date, "2013-01-28T01:23:45.678Z") + self.failUnlessEqual(item2.etag, '"def"') + self.failUnlessEqual(item2.size, 456) + self.failUnlessEqual(item2.owner, None) # meh, who cares def test_put_object(self): """ @@ -1001,7 +1001,7 @@ class GoogleStorageBackend(unittest.TestCase, CloudStorageBackendMixin): http_response = self.mock_http_request() done = [] self.container.put_object("theobj", "the body").addCallback(done.append) - self.assertFalse(done) + self.failIf(done) self.container._http_request.assert_called_once_with( "Google Storage PUT object", "PUT", "https://storage.googleapis.com/thebucket/theobj", @@ -1012,7 +1012,7 @@ class GoogleStorageBackend(unittest.TestCase, CloudStorageBackendMixin): body="the body", need_response_body=False) http_response.callback((self.Response(200), None)) - self.assertTrue(done) + self.failUnless(done) def test_put_object_additional(self): """ @@ -1026,7 +1026,7 @@ class GoogleStorageBackend(unittest.TestCase, CloudStorageBackendMixin): self.container.put_object("theobj", "the body", "text/plain", {"key": "value"}).addCallback(done.append) - self.assertFalse(done) + self.failIf(done) self.container._http_request.assert_called_once_with( "Google Storage PUT object", "PUT", "https://storage.googleapis.com/thebucket/theobj", @@ -1038,7 +1038,7 @@ class GoogleStorageBackend(unittest.TestCase, CloudStorageBackendMixin): body="the body", need_response_body=False) http_response.callback((self.Response(200), None)) - self.assertTrue(done) + self.failUnless(done) def test_get_object(self): """ @@ -1049,7 +1049,7 @@ class GoogleStorageBackend(unittest.TestCase, CloudStorageBackendMixin): http_response = self.mock_http_request() done = [] self.container.get_object("theobj").addCallback(done.append) - self.assertFalse(done) + self.failIf(done) self.container._http_request.assert_called_once_with( "Google Storage GET object", "GET", "https://storage.googleapis.com/thebucket/theobj", @@ -1059,7 +1059,7 @@ class GoogleStorageBackend(unittest.TestCase, CloudStorageBackendMixin): body=None, need_response_body=True) http_response.callback((self.Response(200), "the body")) - self.assertEqual(done, ["the body"]) + self.failUnlessEqual(done, ["the body"]) def test_delete_object(self): """ @@ -1070,7 +1070,7 @@ class GoogleStorageBackend(unittest.TestCase, CloudStorageBackendMixin): http_response = self.mock_http_request() done = [] self.container.delete_object("theobj").addCallback(done.append) - self.assertFalse(done) + self.failIf(done) self.container._http_request.assert_called_once_with( "Google Storage DELETE object", "DELETE", "https://storage.googleapis.com/thebucket/theobj", @@ -1080,7 +1080,7 @@ class GoogleStorageBackend(unittest.TestCase, CloudStorageBackendMixin): body=None, need_response_body=False) http_response.callback((self.Response(200), None)) - self.assertTrue(done) + self.failUnless(done) def test_retry(self): """ @@ -1095,28 +1095,28 @@ class GoogleStorageBackend(unittest.TestCase, CloudStorageBackendMixin): "test", "GET", "http://example", {}, body=None, need_response_body=True).addCallback(result.append) # No response from first request yet: - self.assertFalse(result) - self.assertEqual(self.container._http_request.call_count, 1) + self.failIf(result) + self.failUnlessEqual(self.container._http_request.call_count, 1) self.container._http_request.assert_called_with( "test", "GET", "http://example", {}, body=None, need_response_body=True) # First response fails: first.errback(CloudServiceError(None, 500)) - self.assertFalse(result, result) - self.assertEqual(self.container._http_request.call_count, 1) + self.failIf(result, result) + self.failUnlessEqual(self.container._http_request.call_count, 1) self.reactor.advance(0.1) - self.assertEqual(self.container._http_request.call_count, 2) + self.failUnlessEqual(self.container._http_request.call_count, 2) self.container._http_request.assert_called_with( "test", "GET", "http://example", {}, body=None, need_response_body=True) # Second response fails: second.errback(CloudServiceError(None, 401)) # Unauthorized - self.assertFalse(result) - self.assertEqual(self.container._http_request.call_count, 2) + self.failIf(result) + self.failUnlessEqual(self.container._http_request.call_count, 2) self.reactor.advance(2) - self.assertEqual(self.container._http_request.call_count, 3) + self.failUnlessEqual(self.container._http_request.call_count, 3) self.container._http_request.assert_called_with( "test", "GET", "http://example", {}, body=None, need_response_body=True) @@ -1124,17 +1124,17 @@ class GoogleStorageBackend(unittest.TestCase, CloudStorageBackendMixin): # Third response succeeds: done = object() third.callback(done) - self.assertEqual(result, [done]) + self.failUnlessEqual(result, [done]) def test_react_to_error(self): """ GoogleStorageContainer._react_to_error() will return True (i.e. retry) for any response code between 400 and 599. """ - self.assertFalse(self.container._react_to_error(399)) - self.assertFalse(self.container._react_to_error(600)) + self.failIf(self.container._react_to_error(399)) + self.failIf(self.container._react_to_error(600)) for i in range(400, 600): - self.assertTrue(self.container._react_to_error(i)) + self.failUnless(self.container._react_to_error(i)) def test_head_object(self): """ @@ -1170,7 +1170,7 @@ class MSAzureAuthentication(unittest.TestCase): self.container = msazure_container.MSAzureStorageContainer( "account", "key".encode("base64"), "thebucket") - def assertSignatureEqual(self, method, url, headers, result, azure_buggy=False): + def failUnlessSignatureEqual(self, method, url, headers, result, azure_buggy=False): """ Assert the given HTTP request parameters produce a value to be signed equal to the given result. @@ -1178,7 +1178,7 @@ class MSAzureAuthentication(unittest.TestCase): If possible, assert the signature calculation matches the Microsoft reference implementation. """ - self.assertEqual( + self.failUnlessEqual( self.container._calculate_presignature(method, url, headers), result) if azure_buggy: @@ -1193,7 +1193,7 @@ class MSAzureAuthentication(unittest.TestCase): raise unittest.SkipTest("No azure installed") request = self.FakeRequest(method, url, headers) - self.assertEqual( + self.failUnlessEqual( _sign_storage_blob_request(request, self.container._account_name, self.container._account_key.encode("base64")), @@ -1203,7 +1203,7 @@ class MSAzureAuthentication(unittest.TestCase): """ The correct HTTP method is included in the signature. """ - self.assertSignatureEqual( + self.failUnlessSignatureEqual( "HEAD", "http://x/", {"x-ms-date": ["Sun, 11 Oct 2009 21:49:13 GMT"]}, "HEAD\n\n\n\n\n\n\n\n\n\n\n\n" "x-ms-date:Sun, 11 Oct 2009 21:49:13 GMT\n" @@ -1227,21 +1227,21 @@ class MSAzureAuthentication(unittest.TestCase): "Range": ["r"], "Other": ["o"], "x-ms-date": ["xmd"]} - self.assertSignatureEqual("GET", "http://x/", headers, - "GET\n" - "ce\n" - "cl\n" - "cl2\n" - "cm\n" - "ct\n" - "\n" # Date value is ignored! - "ims\n" - "im\n" - "inm\n" - "ius\n" - "r\n" - "x-ms-date:xmd\n" - "/account/", True) + self.failUnlessSignatureEqual("GET", "http://x/", headers, + "GET\n" + "ce\n" + "cl\n" + "cl2\n" + "cm\n" + "ct\n" + "\n" # Date value is ignored! + "ims\n" + "im\n" + "inm\n" + "ius\n" + "r\n" + "x-ms-date:xmd\n" + "/account/", True) def test_xms_headers(self): """ @@ -1250,37 +1250,37 @@ class MSAzureAuthentication(unittest.TestCase): headers = {"x-ms-foo": ["a"], "x-ms-z": ["b"], "x-ms-date": ["c"]} - self.assertSignatureEqual("GET", "http://x/", headers, - "GET\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "x-ms-date:c\n" - "x-ms-foo:a\n" - "x-ms-z:b\n" - "/account/") + self.failUnlessSignatureEqual("GET", "http://x/", headers, + "GET\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "x-ms-date:c\n" + "x-ms-foo:a\n" + "x-ms-z:b\n" + "/account/") def test_xmsdate_required(self): """ The x-ms-date header is mandatory. """ - self.assertRaises(ValueError, - self.assertSignatureEqual, "GET", "http://x/", {}, "") + self.failUnlessRaises(ValueError, + self.failUnlessSignatureEqual, "GET", "http://x/", {}, "") def test_path_and_account(self): """ The URL path and account name is included. """ self.container._account_name = "theaccount" - self.assertSignatureEqual( + self.failUnlessSignatureEqual( "HEAD", "http://x/foo/bar", {"x-ms-date": ["d"]}, "HEAD\n\n\n\n\n\n\n\n\n\n\n\n" "x-ms-date:d\n" @@ -1291,7 +1291,7 @@ class MSAzureAuthentication(unittest.TestCase): The query arguments are included. """ value = "hello%20there" - self.assertSignatureEqual( + self.failUnlessSignatureEqual( "HEAD", "http://x/?z=%s&y=abc" % (value,), {"x-ms-date": ["d"]}, "HEAD\n\n\n\n\n\n\n\n\n\n\n\n" "x-ms-date:d\n" @@ -1387,7 +1387,7 @@ class MSAzureStorageBackendTests(unittest.TestCase, CloudStorageBackendMixin): http_response = self.mock_http_request() done = [] self.container.list_objects(prefix='xxx xxx/').addCallback(done.append) - self.assertFalse(done) + self.failIf(done) self.container._http_request.assert_called_once_with( "MS Azure list objects", "GET", "https://theaccount.blob.core.windows.net/thebucket?comp=list&restype=container&prefix=xxx%20xxx%2F", @@ -1399,22 +1399,22 @@ class MSAzureStorageBackendTests(unittest.TestCase, CloudStorageBackendMixin): need_response_body=True) http_response.callback((self.Response(200), LIST_RESPONSE)) listing = done[0] - self.assertEqual(listing.name, "thebucket") - self.assertEqual(listing.prefix, "xxx xxx/") - self.assertEqual(listing.marker, "xxx xxx/foo") - self.assertEqual(listing.max_keys, None) - self.assertEqual(listing.is_truncated, "false") + self.failUnlessEqual(listing.name, "thebucket") + self.failUnlessEqual(listing.prefix, "xxx xxx/") + self.failUnlessEqual(listing.marker, "xxx xxx/foo") + self.failUnlessEqual(listing.max_keys, None) + self.failUnlessEqual(listing.is_truncated, "false") item1, item2 = listing.contents - self.assertEqual(item1.key, "xxx xxx/firstblob") - self.assertEqual(item1.modification_date, "Mon, 30 Jan 2013 01:23:45 GMT") - self.assertEqual(item1.etag, 'abc') - self.assertEqual(item1.size, 123) - self.assertEqual(item1.owner, None) # meh, who cares - self.assertEqual(item2.key, "xxx xxx/secondblob") - self.assertEqual(item2.modification_date, "Mon, 30 Jan 2013 01:23:46 GMT") - self.assertEqual(item2.etag, 'def') - self.assertEqual(item2.size, 100) - self.assertEqual(item2.owner, None) # meh, who cares + self.failUnlessEqual(item1.key, "xxx xxx/firstblob") + self.failUnlessEqual(item1.modification_date, "Mon, 30 Jan 2013 01:23:45 GMT") + self.failUnlessEqual(item1.etag, 'abc') + self.failUnlessEqual(item1.size, 123) + self.failUnlessEqual(item1.owner, None) # meh, who cares + self.failUnlessEqual(item2.key, "xxx xxx/secondblob") + self.failUnlessEqual(item2.modification_date, "Mon, 30 Jan 2013 01:23:46 GMT") + self.failUnlessEqual(item2.etag, 'def') + self.failUnlessEqual(item2.size, 100) + self.failUnlessEqual(item2.owner, None) # meh, who cares def test_put_object(self): """ @@ -1425,7 +1425,7 @@ class MSAzureStorageBackendTests(unittest.TestCase, CloudStorageBackendMixin): http_response = self.mock_http_request() done = [] self.container.put_object("theobj", "the body").addCallback(done.append) - self.assertFalse(done) + self.failIf(done) self.container._http_request.assert_called_once_with( "MS Azure PUT object", "PUT", "https://theaccount.blob.core.windows.net/thebucket/theobj", @@ -1439,7 +1439,7 @@ class MSAzureStorageBackendTests(unittest.TestCase, CloudStorageBackendMixin): body="the body", need_response_body=False) http_response.callback((self.Response(200), None)) - self.assertTrue(done) + self.failUnless(done) def test_put_object_additional(self): """ @@ -1453,8 +1453,7 @@ class MSAzureStorageBackendTests(unittest.TestCase, CloudStorageBackendMixin): self.container.put_object("theobj", "the body", "text/plain", {"key": "value"}).addCallback(done.append) - self.assertFalse(done) - self.assertFalse(done) + self.failIf(done) self.container._http_request.assert_called_once_with( "MS Azure PUT object", "PUT", "https://theaccount.blob.core.windows.net/thebucket/theobj", @@ -1469,7 +1468,7 @@ class MSAzureStorageBackendTests(unittest.TestCase, CloudStorageBackendMixin): body="the body", need_response_body=False) http_response.callback((self.Response(200), None)) - self.assertTrue(done) + self.failUnless(done) def test_get_object(self): """ @@ -1480,7 +1479,7 @@ class MSAzureStorageBackendTests(unittest.TestCase, CloudStorageBackendMixin): http_response = self.mock_http_request() done = [] self.container.get_object("theobj").addCallback(done.append) - self.assertFalse(done) + self.failIf(done) self.container._http_request.assert_called_once_with( "MS Azure GET object", "GET", "https://theaccount.blob.core.windows.net/thebucket/theobj", @@ -1491,7 +1490,7 @@ class MSAzureStorageBackendTests(unittest.TestCase, CloudStorageBackendMixin): body=None, need_response_body=True) http_response.callback((self.Response(200), "the body")) - self.assertEqual(done, ["the body"]) + self.failUnlessEqual(done, ["the body"]) def test_delete_object(self): """ @@ -1502,7 +1501,7 @@ class MSAzureStorageBackendTests(unittest.TestCase, CloudStorageBackendMixin): http_response = self.mock_http_request() done = [] self.container.delete_object("theobj").addCallback(done.append) - self.assertFalse(done) + self.failIf(done) self.container._http_request.assert_called_once_with( "MS Azure DELETE object", "DELETE", "https://theaccount.blob.core.windows.net/thebucket/theobj", @@ -1513,7 +1512,7 @@ class MSAzureStorageBackendTests(unittest.TestCase, CloudStorageBackendMixin): body=None, need_response_body=False) http_response.callback((self.Response(200), None)) - self.assertTrue(done) + self.failUnless(done) class ServerMixin: