From 089af7dd21167d0b1b3739d22b5b879f8372b858 Mon Sep 17 00:00:00 2001 From: Edward J M Easton Date: Thu, 29 Oct 2015 11:36:50 +0000 Subject: [PATCH] EASY-511 return deleted state in list_versions, so you can tell whether or not the leading version is just a delete sentinel --- arctic/store/version_store.py | 10 ++++++---- tests/integration/store/test_version_store.py | 20 +++++++++++++++++++ tests/unit/store/test_version_store.py | 5 +++-- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/arctic/store/version_store.py b/arctic/store/version_store.py index eeb58c6096b0c..790bc7d4a9c70 100644 --- a/arctic/store/version_store.py +++ b/arctic/store/version_store.py @@ -244,14 +244,16 @@ def list_versions(self, symbol=None, snapshot=None, latest_only=False): for symbol in symbols: query['symbol'] = symbol seen_symbols = set() - for version in self._versions.find(query, projection=['symbol', 'version', 'parent'], sort=[('version', -1)]): + for version in self._versions.find(query, projection=['symbol', 'version', 'parent', 'metadata.deleted'], sort=[('version', -1)]): if latest_only and version['symbol'] in seen_symbols: continue seen_symbols.add(version['symbol']) + meta = version.get('metadata') versions.append({'symbol': version['symbol'], 'version': version['version'], - # We return offset-aware datetimes in Local Time. - 'date': ms_to_datetime(datetime_to_ms(version['_id'].generation_time)), - 'snapshots': self._find_snapshots(version.get('parent', []))}) + 'deleted': meta.get('deleted', False) if meta else False, + # We return offset-aware datetimes in Local Time. + 'date': ms_to_datetime(datetime_to_ms(version['_id'].generation_time)), + 'snapshots': self._find_snapshots(version.get('parent', []))}) return versions def _find_snapshots(self, parent_ids): diff --git a/tests/integration/store/test_version_store.py b/tests/integration/store/test_version_store.py index b7b82ff4989a9..9099cd03d5931 100644 --- a/tests/integration/store/test_version_store.py +++ b/tests/integration/store/test_version_store.py @@ -303,6 +303,26 @@ def test_list_version(library): assert versions[i]['version'] == x +def test_list_version_deleted(library): + assert len(library.list_versions(symbol)) == 0 + library.write(symbol, ts1, prune_previous_version=False) + assert len(library.list_versions(symbol)) == 1 + # Snapshot the library so we keep the sentinel version + library.snapshot('xxx', versions={symbol: 1}) + library.delete(symbol) + versions = library.list_versions(symbol) + assert len(versions) == 2 + assert versions[0]['symbol'] == symbol + assert versions[0]['version'] == 2 + assert versions[0]['snapshots'] == [] + assert versions[0]['deleted'] == True + + assert versions[1]['symbol'] == symbol + assert versions[1]['version'] == 1 + assert versions[1]['deleted'] == False + assert versions[1]['snapshots'] == ['xxx'] + + def test_list_version_latest_only(library): assert len(list(library.list_versions(symbol))) == 0 dates = [None, None, None] diff --git a/tests/unit/store/test_version_store.py b/tests/unit/store/test_version_store.py index 715f8aefc31b4..bc5a6fa361503 100644 --- a/tests/unit/store/test_version_store.py +++ b/tests/unit/store/test_version_store.py @@ -34,14 +34,15 @@ def test_list_versions_localTime(): vs._find_snapshots.return_value = 'snap' date = dt(2013, 4, 1, 9, 0) vs._versions.find.return_value = [{'_id': bson.ObjectId.from_datetime(date), - 'symbol': 's', 'version': 10}] + 'symbol': 's', 'version': 10, 'metadata': None}] version = list(VersionStore.list_versions(vs, "symbol"))[0] local_date = date.replace(tzinfo=mktz("UTC")) assert version == {'symbol': version['symbol'], 'version': version['version'], # We return naive datetimes in 'default' time, which is London for us 'date': local_date, - 'snapshots': 'snap'} + 'snapshots': 'snap', + 'deleted': False} def test__read_preference__allow_secondary_true():