Page MenuHomeSoftware Heritage

Web API: Add endpoint to list all archived software origins
ClosedPublic

Authored by anlambert on Jan 16 2019, 12:04 PM.

Details

Summary

Add a new endpoint to the Web API (/origins) in order to list all archived
software origins in a paginated way.

Related T1399
Depends on D958

Diff Detail

Repository
rDWAPPS Web applications
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

vlorentz added inline comments.
swh/web/api/views/origin.py
77–80

You should set origin_count = results[0]['id'] - origin_from` (or something similar)

swh/web/tests/api/views/test_origin.py
338–341

Is this how example() is supposed to be used with hypothesis? It looks like it exepects that "one call of the test function = one example".

Shouldn't we ask hypothesis to build a list of origins instead?

anlambert added inline comments.
swh/web/api/views/origin.py
77–80

There is no need to do so as origin_count corresponds to the maximum number of origins to return.

swh/web/tests/api/views/test_origin.py
338–341

The issue here is that I restrain the maximum number of examples to 1 to speedup overall tests execution.
In order to generate nb_origins origins with different values, I need to temporarily override the
max_examples hypothesis setting.

However, I agree that this code could be put in a dedicated strategy function as
I should reuse it in other tests implementation.

swh/web/api/views/origin.py
77–80

I know, but as this is the link-prev, having too many origins will make the two lists of origins overlap.

Update: Address vlorentz comment

anlambert added inline comments.
swh/web/api/views/origin.py
77–80

Yes it can happen but I don't want to modify the origin_count parameter value.

In practice, origins should be listed from the first one to the last one so that's not really
a big issue.

swh/web/api/views/origin.py
77–80

Shouldn't we drop link-prev then?

anlambert marked an inline comment as done.
anlambert added inline comments.
swh/web/api/views/origin.py
77–80

Sold, will update accordingly after rebase (got some incoming changes in master branch that I want to push before landing that one).

Update: Rebase to master and remove the link-prev entry in api reponse Link header

Update: rebase to master and use better implementation for new_origins strategy

Two more nitpicks, and it should be good!

swh/web/tests/strategies.py
171–172

You might want to check for Noneness, nb_origins might be zero on purpose (eg. when combined with other strategies that vary that parameter).

175

unique_by=lambda o: tuple(sorted(o.items()))

This revision is now accepted and ready to land.Jan 21 2019, 12:24 PM

Thanks for the review @vlorentz . I will address your last comments and land that diff.

Update: Address latest vlorentz comments

This revision was automatically updated to reflect the committed changes.