Skip to content

Commit 074cbb7

Browse files
authored
Remove deprecated list_* methods on DB client (#885)
These have been deprecated for years; we should stop carrying this baggage around.
1 parent 15bbc66 commit 074cbb7

File tree

3 files changed

+3
-282
lines changed

3 files changed

+3
-282
lines changed

web_monitoring/cli/ia_healthcheck.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ def sample_monitored_urls(sample_size):
2424
list of string
2525
"""
2626
client = db.Client.from_env()
27-
page = client.list_pages(chunk=1, chunk_size=1, active=True, include_total=True)
28-
url_count = page['meta']['total_results']
27+
page = next(client.get_pages(chunk=1, chunk_size=1, active=True, include_total=True))
28+
url_count = page['_list_meta']['total_results']
2929
return (get_page_url(client, index)
3030
for index in random.sample(range(url_count), sample_size))
3131

3232

3333
def get_page_url(client, index):
34-
return client.list_pages(chunk=index, chunk_size=1, active=True)['data'][0]['url']
34+
return next(client.get_pages(chunk=index, chunk_size=1, active=True))['url']
3535

3636

3737
def wayback_has_captures(url, from_date=None):

web_monitoring/db.py

Lines changed: 0 additions & 198 deletions
Original file line numberDiff line numberDiff line change
@@ -352,70 +352,6 @@ def _iterate_chunk_items(self, method, url, data=None, timeout=None, **kwargs):
352352

353353
### PAGES ###
354354

355-
def list_pages(self, *, chunk=None, chunk_size=None, sort=None,
356-
tags=None, maintainers=None, url=None, title=None,
357-
include_versions=None, include_earliest=None,
358-
include_latest=None, source_type=None, hash=None,
359-
start_date=None, end_date=None, active=None,
360-
include_total=False):
361-
"""
362-
List all Pages, optionally filtered by search criteria.
363-
364-
Parameters
365-
----------
366-
chunk : integer, optional
367-
pagination parameter
368-
chunk_size : integer, optional
369-
number of items per chunk
370-
sort : list of string, optional
371-
fields to sort by in `{field}:{order}` format, e.g. `title:asc`
372-
tags : list of string, optional
373-
maintainers : list of string, optional
374-
url : string, optional
375-
title : string, optional
376-
include_versions : boolean, optional
377-
include_earliest : boolean, optional
378-
include_latest : boolean, optional
379-
source_type : string, optional
380-
such as 'versionista' or 'internet_archive'
381-
hash : string, optional
382-
SHA256 hash of Version content
383-
start_date : datetime, optional
384-
end_date : datetime, optional
385-
active : boolean, optional
386-
include_total : boolean, optional
387-
Whether to include a `meta.total_results` field in the response.
388-
If not set, `links.last` will usually be empty unless you are on
389-
the last chunk. Setting this option runs a pretty expensive query,
390-
so use it sparingly. (Default: False)
391-
392-
Returns
393-
-------
394-
response : dict
395-
"""
396-
warnings.warn('db.client.list_pages() has been deprecated. Please use '
397-
'db.client.get_pages().',
398-
DeprecationWarning)
399-
400-
params = {'chunk': chunk,
401-
'chunk_size': chunk_size,
402-
'sort': sort and ','.join(sort) or None,
403-
'tags[]': tags,
404-
'maintainers[]': maintainers,
405-
'url': url,
406-
'title': title,
407-
'include_versions': include_versions,
408-
'include_earliest': include_earliest,
409-
'include_latest': include_latest,
410-
'source_type': source_type,
411-
'hash': hash,
412-
'capture_time': _time_range_string(start_date, end_date),
413-
'active': active,
414-
'include_total': include_total or None}
415-
url = '/pages'
416-
result = self.request_json(GET, url, params=params)
417-
return result
418-
419355
def get_pages(self, *, chunk=None, chunk_size=None, sort=None,
420356
tags=None, maintainers=None, url=None, title=None,
421357
include_versions=None, include_earliest=None,
@@ -507,82 +443,6 @@ def get_page(self, page_id):
507443

508444
### VERSIONS ###
509445

510-
def list_versions(self, *, page_id=None, chunk=None, chunk_size=None,
511-
sort=None, start_date=None, end_date=None,
512-
source_type=None, hash=None,
513-
source_metadata=None, different=None,
514-
include_change_from_previous=None,
515-
include_change_from_earliest=None, include_total=False):
516-
"""
517-
List Versions, optionally filtered by serach criteria, including Page.
518-
519-
Parameters
520-
----------
521-
page_id : string, optional
522-
restricts serach to Versions of a specific Page
523-
chunk : integer, optional
524-
pagination parameter
525-
chunk_size : integer, optional
526-
number of items per chunk
527-
sort : list of string, optional
528-
fields to sort by in `{field}:{order}` format,
529-
e.g. `capture_time:asc`
530-
start_date : datetime, optional
531-
end_date : datetime, optional
532-
source_type : string, optional
533-
such as 'versionista' or 'internetarchive'
534-
hash : string, optional
535-
SHA256 hash of Version content
536-
source_metadata : dict, optional
537-
Examples:
538-
539-
* ``{'version_id': 12345678}``
540-
* ``{'account': 'versionista1', 'has_content': True}``
541-
different : boolean, optional
542-
If False, include versions that aren't actually different from the
543-
previous version of the same page in the response.
544-
include_change_from_previous : boolean, optional
545-
If True, include a `change_from_previous` field in each version
546-
that represents a change object between it and the previous version
547-
of the same page.
548-
include_change_from_earliest : boolean, optional
549-
If True, include a `change_from_earliest` field in each version
550-
that represents a change object between it and the earliest version
551-
of the same page.
552-
include_total : boolean, optional
553-
Whether to include a `meta.total_results` field in the response.
554-
If not set, `links.last` will usually be empty unless you are on
555-
the last chunk. Setting this option runs a pretty expensive query,
556-
so use it sparingly. (Default: False)
557-
558-
Returns
559-
-------
560-
response : dict
561-
"""
562-
warnings.warn('db.client.list_versions() has been deprecated. Please '
563-
'use db.client.get_versions().',
564-
DeprecationWarning)
565-
566-
params = {'chunk': chunk,
567-
'chunk_size': chunk_size,
568-
'sort': sort and ','.join(sort) or None,
569-
'capture_time': _time_range_string(start_date, end_date),
570-
'source_type': source_type,
571-
'hash': hash,
572-
'different': different,
573-
'include_change_from_previous': include_change_from_previous,
574-
'include_change_from_earliest': include_change_from_earliest,
575-
'include_total': include_total or None}
576-
if source_metadata is not None:
577-
for k, v in source_metadata.items():
578-
params[f'source_metadata[{k}]'] = v
579-
if page_id is None:
580-
url = '/versions'
581-
else:
582-
url = f'/pages/{page_id}/versions'
583-
result = self.request_json(GET, url, params=params)
584-
return result
585-
586446
def get_versions(self, *, page_id=None, chunk=None, chunk_size=None,
587447
sort=None, start_date=None, end_date=None,
588448
source_type=None, hash=None,
@@ -860,32 +720,6 @@ def get_import_status(self, import_id):
860720

861721
### CHANGES AND ANNOTATIONS ###
862722

863-
def list_changes(self, page_id, include_total=False):
864-
"""
865-
List Changes between two Versions on a Page.
866-
867-
Parameters
868-
----------
869-
page_id : string
870-
include_total : bool, optional
871-
Whether to include a `meta.total_results` field in the response.
872-
If not set, `links.last` will usually be empty unless you are on
873-
the last chunk. Setting this option runs a pretty expensive query,
874-
so use it sparingly. (Default: False)
875-
876-
Returns
877-
-------
878-
response : dict
879-
"""
880-
warnings.warn('db.client.list_changes() has been deprecated. Please '
881-
'use db.client.get_changes().',
882-
DeprecationWarning)
883-
884-
url = f'/pages/{page_id}/changes/'
885-
result = self.request_json(
886-
GET, url, params={'include_total': include_total or None})
887-
return result
888-
889723
def get_changes(self, page_id, include_total=False):
890724
"""
891725
Iterate through a set of changes between any two versions of a page.
@@ -928,38 +762,6 @@ def get_change(self, *, page_id, to_version_id, from_version_id=''):
928762
result = self.request_json(GET, url)
929763
return result
930764

931-
def list_annotations(self, *, page_id, to_version_id, from_version_id='',
932-
include_total=False):
933-
"""
934-
List Annotations for a Change between two Versions.
935-
936-
Parameters
937-
----------
938-
page_id : string
939-
to_version_id : string
940-
from_version_id : string, optional
941-
If from_version_id is not given, it will be treated as version
942-
immediately prior to ``to_version``.
943-
include_total : boolean, optional
944-
Whether to include a `meta.total_results` field in the response.
945-
If not set, `links.last` will usually be empty unless you are on
946-
the last chunk. Setting this option runs a pretty expensive query,
947-
so use it sparingly. (Default: False)
948-
949-
Returns
950-
-------
951-
response : dict
952-
"""
953-
warnings.warn('db.client.list_annotations() has been deprecated. '
954-
'Please use db.client.get_annotations().',
955-
DeprecationWarning)
956-
957-
url = (f'/pages/{page_id}/changes/'
958-
f'{from_version_id}..{to_version_id}/annotations')
959-
result = self.request_json(
960-
GET, url, params={'include_total': include_total or None})
961-
return result
962-
963765
def get_annotations(self, *, page_id, to_version_id, from_version_id='',
964766
include_total=False):
965767
"""

web_monitoring/tests/test_db.py

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -108,48 +108,6 @@ def test_ignores_empty_DB_URL(self, monkeypatch):
108108
assert client.get_page('x') == {'data': {'uuid': 'x'}}
109109

110110

111-
# DEPRECATED
112-
@db_vcr.use_cassette()
113-
def test_list_pages():
114-
cli = Client(**AUTH)
115-
res = cli.list_pages()
116-
assert res['data']
117-
118-
# Test datetimes are parsed correctly.
119-
assert isinstance(res['data'][0]['created_at'], datetime)
120-
assert isinstance(res['data'][0]['updated_at'], datetime)
121-
122-
# Test chunk query parameters.
123-
res = cli.list_pages(chunk_size=2)
124-
assert len(res['data']) == 2
125-
res = cli.list_pages(chunk_size=5)
126-
assert len(res['data']) == 5
127-
128-
# Test filtering query parameters.
129-
res = cli.list_pages(url='__nonexistent__')
130-
assert len(res['data']) == 0
131-
res = cli.list_pages(url=URL)
132-
assert len(res['data']) > 0
133-
res = cli.list_pages(tags=['__nonexistent__'])
134-
assert len(res['data']) == 0
135-
res = cli.list_pages(tags=[SITE])
136-
assert len(res['data']) > 0
137-
res = cli.list_pages(maintainers=['__nonexistent__'])
138-
assert len(res['data']) == 0
139-
res = cli.list_pages(maintainers=[AGENCY])
140-
assert len(res['data']) > 0
141-
142-
# Test relations
143-
res = cli.list_pages(include_earliest=True)
144-
assert all(['earliest' in page for page in res['data']]) is True
145-
assert isinstance(res['data'][0]['earliest']['created_at'], datetime)
146-
assert isinstance(res['data'][0]['earliest']['updated_at'], datetime)
147-
res = cli.list_pages(include_latest=True)
148-
assert all(['latest' in page for page in res['data']]) is True
149-
assert isinstance(res['data'][0]['latest']['created_at'], datetime)
150-
assert isinstance(res['data'][0]['latest']['updated_at'], datetime)
151-
152-
153111
@db_vcr.use_cassette()
154112
def test_get_pages():
155113
cli = Client(**AUTH)
@@ -220,35 +178,13 @@ def test_get_page():
220178
assert res['data']['uuid'] == PAGE_ID
221179

222180

223-
# DEPRECATED
224-
@db_vcr.use_cassette()
225-
def test_list_page_versions():
226-
cli = Client(**AUTH)
227-
res = cli.list_versions(page_id=PAGE_ID)
228-
assert all([v['page_uuid'] == PAGE_ID for v in res['data']])
229-
230-
231181
@db_vcr.use_cassette()
232182
def test_get_versions_for_page():
233183
cli = Client(**AUTH)
234184
versions = cli.get_versions(page_id=PAGE_ID)
235185
assert all(v['page_uuid'] == PAGE_ID for v in versions)
236186

237187

238-
# DEPRECATED
239-
@db_vcr.use_cassette()
240-
def test_list_versions():
241-
cli = Client(**AUTH)
242-
res = cli.list_versions()
243-
assert res['data']
244-
245-
# Test relations
246-
res = cli.list_versions(include_change_from_previous=True)
247-
assert all(['change_from_previous' in item for item in res['data']]) is True
248-
res = cli.list_versions(include_change_from_earliest=True)
249-
assert all(['change_from_earliest' in item for item in res['data']]) is True
250-
251-
252188
@db_vcr.use_cassette()
253189
def test_get_versions():
254190
cli = Client(**AUTH)
@@ -423,14 +359,6 @@ def test_monitor_import_statuses_returns_errors():
423359
"not match expected hash (hash_placeholder)"]}
424360

425361

426-
# DEPRECATED
427-
@db_vcr.use_cassette()
428-
def test_list_changes():
429-
cli = Client(**AUTH)
430-
# smoke test
431-
cli.list_changes(PAGE_ID)
432-
433-
434362
@db_vcr.use_cassette()
435363
def test_get_changes():
436364
cli = Client(**AUTH)
@@ -449,15 +377,6 @@ def test_get_change():
449377
to_version_id=TO_VERSION_ID)
450378

451379

452-
# DEPRECATED
453-
@db_vcr.use_cassette()
454-
def test_list_annotations():
455-
cli = Client(**AUTH)
456-
# smoke test
457-
cli.list_annotations(page_id=PAGE_ID,
458-
to_version_id=TO_VERSION_ID)
459-
460-
461380
@db_vcr.use_cassette()
462381
def test_get_annotations():
463382
cli = Client(**AUTH)

0 commit comments

Comments
 (0)