Skip to content
This repository has been archived by the owner on Oct 5, 2022. It is now read-only.

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AudreyAltman committed Jul 30, 2020
1 parent b8278ef commit 802a862
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 54 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ The application will be available with the following endpoints:
* `http://localhost:8000/v2/items`
* `http://localhost:8000/v2/items/<item ID or IDs>`
* `http://localhost:8000/v2/items/<item ID or IDs>/mlt`
* `http://localhost:8000/v2/items/<item ID or IDs>/necropolis`
* `http://localhost:8000/v2/necropolis/<item ID>/`

See [the API Codex](https://pro.dp.la/developers/api-codex) for usage.

Expand Down
49 changes: 2 additions & 47 deletions dplaapi/handlers/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,11 @@ def items(query):
return result



def necropolis_items(query):
"""Return "item" records from a necropolis search query
The search query could either be a typical SearchQuery or a MLTQuery
("More Like This" query)
"""Return records from a necropolis search query
Arguments:
- query: instance of SearchQuery or MLTQuery, which has a `query'
property.
- query: instance of NecropolisQuery, which has a `query' property.
"""
try:
resp = requests.post("%s/_search" % dplaapi.NECRO_BASE,
Expand Down Expand Up @@ -489,46 +484,6 @@ async def specific_item(request):
return response_object(rv, goodparams, task)


async def specific_item(request):

for k in request.query_params.items(): # list of tuples
if k[0] != 'callback' and k[0] != 'api_key':
raise HTTPException(400, 'Unrecognized parameter %s' % k[0])

id_or_ids = request.path_params['id_or_ids']
account = account_from_params(request.query_params)
goodparams = ItemsQueryType({k: v for [k, v]
in request.query_params.items()})
ids = id_or_ids.split(',')
for the_id in ids:
if not re.match(r'[a-f0-9]{32}$', the_id):
raise HTTPException(400, "Bad ID: %s" % the_id)
goodparams.update({'ids': ids})
goodparams['page_size'] = len(ids)

result = search_items(goodparams)
log.debug('cache size: %d' % search_cache.currsize)

if hit_count(result) == 0:
raise HTTPException(404)

rv = {
'count': hit_count(result),
'docs': [hit['_source'] for hit in result['hits']['hits']]
}

if account and not account.staff:
task = BackgroundTask(track,
request=request,
results=rv,
api_key=account.key,
title='Fetch items')
else:
task = None

return response_object(rv, goodparams, task)


async def mlt(request):
"""'More Like This' items"""

Expand Down
7 changes: 1 addition & 6 deletions tests/handlers/test_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,6 @@ def mock_not_found_Account_get(*args, **kwargs):
raise DoesNotExist()


def mock_search_necro_w_no_results(*args, **kwargs):
return {'hits': {'total': {'value': 0}}}


def get_request(path, querystring=None, path_params=None):
rv = {'type': 'http', 'method': 'GET', 'path': path, 'query_string': b''}
if querystring:
Expand Down Expand Up @@ -771,8 +767,7 @@ def mock_zero_items(*args):


@pytest.mark.asyncio
async def test_specific_nero_item_calls_BackgroundTask(monkeypatch,
mocker):
async def test_specific_nero_item_calls_BackgroundTask(monkeypatch, mocker):
"""It instantiates BackgroundTask correctly"""

def mock_items(*argv):
Expand Down

0 comments on commit 802a862

Please sign in to comment.