diff options
-rw-r--r-- | src/leap/soledad/client/_db/blobs.py | 6 | ||||
-rw-r--r-- | tests/blobs/test_blob_manager.py | 19 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/leap/soledad/client/_db/blobs.py b/src/leap/soledad/client/_db/blobs.py index ab9de8dd..4b90f8f2 100644 --- a/src/leap/soledad/client/_db/blobs.py +++ b/src/leap/soledad/client/_db/blobs.py @@ -72,6 +72,7 @@ class SyncStatus: PENDING_DOWNLOAD = 3 FAILED_UPLOAD = 4 FAILED_DOWNLOAD = 5 + UNAVAILABLE_STATUSES = (3, 5) class ConnectionPool(adbapi.ConnectionPool): @@ -573,6 +574,11 @@ class SQLiteBlobBackend(object): if sync_status: query += ' and sync_status = ?' values += (sync_status,) + else: + avoid_values = SyncStatus.UNAVAILABLE_STATUSES + query += ' AND sync_status NOT IN (%s)' + query %= ','.join(['?' for _ in avoid_values]) + values += avoid_values result = yield self.dbpool.runQuery(query, values) if result: defer.returnValue([b_id[0] for b_id in result]) diff --git a/tests/blobs/test_blob_manager.py b/tests/blobs/test_blob_manager.py index 995a1989..0fcfff72 100644 --- a/tests/blobs/test_blob_manager.py +++ b/tests/blobs/test_blob_manager.py @@ -174,3 +174,22 @@ class BlobManagerTestCase(unittest.TestCase): failed_upload = SyncStatus.FAILED_UPLOAD local_list = yield self.manager.local_list(sync_status=failed_upload) self.assertIn(blob_id, local_list) + + @defer.inlineCallbacks + @pytest.mark.usefixtures("method_tmpdir") + def test_local_list_doesnt_include_unavailable_blobs(self): + local = self.manager.local + unavailable_ids, deferreds = [], [] + for unavailable_status in SyncStatus.UNAVAILABLE_STATUSES: + current_blob_id = uuid4().hex + deferreds.append(local.put(current_blob_id, BytesIO(''), 0, + status=unavailable_status)) + unavailable_ids.append(current_blob_id) + available_blob_id = uuid4().hex + content, length = self.cleartext, len(self.cleartext.getvalue()) + deferreds.append(local.put(available_blob_id, content, length)) + yield defer.gatherResults(deferreds) + local_list = yield local.list() + message = 'Unavailable blob showing up on listing!' + for blob_id in unavailable_ids: + self.assertNotIn(blob_id, local_list, message) |