Page MenuHomeSoftware Heritage

common/service: Add lookup_object function
ClosedPublic

Authored by anlambert on Nov 19 2019, 3:26 PM.

Details

Summary

Add an utility function for looking up an object in the archive by its type
and id. Supported object types are: content, directory, release, revision
and snapshot.

Its purpose is to factorize some code that will be needed in the upcoming
swh badge endpoints implementation. Notably, it enables to check that
an object exists in the archive in order to return adequate HTTP status code.

Related to T2090

Test Plan

Nex tests have been added.

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

anlambert created this revision.Nov 19 2019, 3:26 PM

I don't feel comfortable to accept revisions, globally... but your diff looks solid.

swh/web/api/views/identifiers.py
58

nicely done !

swh/web/tests/common/test_service.py
810

I see that tests are not documented.
Here valid objects means objects that exists in the archive?
Maybe known objects as the contrast of unknown objects is more appropriate...

ardumont added inline comments.
swh/web/api/views/identifiers.py
58

Where is stored the result of the lookup_object function call?

anlambert added inline comments.Nov 20 2019, 10:53 AM
swh/web/api/views/identifiers.py
58

Here the idea is to check the object existence in the archive.

An exception will be raised if it is not found and an HTTP error response will be generated.

swh/web/tests/common/test_service.py
810

Sounds better indeed, I will rename the test.

anlambert updated this revision to Diff 7952.Nov 20 2019, 11:09 AM

Update: Rename test function

ardumont accepted this revision.Nov 20 2019, 2:01 PM
This revision is now accepted and ready to land.Nov 20 2019, 2:01 PM
This revision was automatically updated to reflect the committed changes.