From 797f34aec32eefbe495d9936d955e7ab4bdc3f1a Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Mon, 6 Jun 2022 09:59:12 -0400 Subject: [PATCH] More tests. --- src/allmydata/storage/http_client.py | 3 --- src/allmydata/test/test_storage_http.py | 35 +++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/allmydata/storage/http_client.py b/src/allmydata/storage/http_client.py index bf6104dea..9711e748d 100644 --- a/src/allmydata/storage/http_client.py +++ b/src/allmydata/storage/http_client.py @@ -696,7 +696,6 @@ class StorageClientMutables: Given a mapping between share numbers and test/write vectors, the tests are done and if they are valid the writes are done. """ - # TODO unit test all the things url = self._client.relative_url( "/v1/mutable/{}/read-test-write".format(_encode_si(storage_index)) ) @@ -731,7 +730,6 @@ class StorageClientMutables: """ Download a chunk of data from a share. """ - # TODO unit test all the things return read_share_chunk( self._client, "mutable", storage_index, share_number, offset, length ) @@ -741,7 +739,6 @@ class StorageClientMutables: """ List the share numbers for a given storage index. """ - # TODO unit test all the things url = self._client.relative_url( "/v1/mutable/{}/shares".format(_encode_si(storage_index)) ) diff --git a/src/allmydata/test/test_storage_http.py b/src/allmydata/test/test_storage_http.py index 6cf2f883b..65aa12e40 100644 --- a/src/allmydata/test/test_storage_http.py +++ b/src/allmydata/test/test_storage_http.py @@ -1271,10 +1271,41 @@ class MutableHTTPAPIsTests(SyncTestCase): ) def test_list_shares(self): - pass + """``list_shares()`` returns the shares for a given storage index.""" + storage_index, _, _ = self.create_upload() + self.assertEqual(result_of(self.mut_client.list_shares(storage_index)), {0, 1}) + + def test_non_existent_list_shares(self): + """A non-existent storage index errors when shares are listed.""" + with self.assertRaises(ClientException) as exc: + result_of(self.mut_client.list_shares(urandom(32))) + self.assertEqual(exc.exception.code, http.NOT_FOUND) def test_wrong_write_enabler(self): - pass + """Writes with the wrong write enabler fail, and are not processed.""" + storage_index, write_secret, lease_secret = self.create_upload() + with self.assertRaises(ClientException) as exc: + result_of( + self.mut_client.read_test_write_chunks( + storage_index, + urandom(32), + lease_secret, + lease_secret, + { + 0: TestWriteVectors( + write_vectors=[WriteVector(offset=1, data=b"XYZ")] + ), + }, + [ReadVector(0, 8)], + ) + ) + self.assertEqual(exc.exception.code, http.UNAUTHORIZED) + + # The write did not happen: + self.assertEqual( + result_of(self.mut_client.read_share_chunk(storage_index, 0, 0, 8)), + b"abcdef-0", + ) # TODO refactor reads tests so they're shared