Page MenuHomeSoftware Heritage

browse/snapshot_context: Refactor, add type annotations and tests
ClosedPublic

Authored by anlambert on Apr 21 2020, 4:35 PM.

Details

Summary

On the road to T2342, second part of T2360.

Slightly refactor and improve the swh.web.browse.snapshot_context module:

  • merge _process_snapshot_request function into get_snapshot_context one
  • rename some dict keys and add snapshot / origin related type annotations
  • cleanup and simplify get_snapshot_context implementation
  • update some docstrings
  • add new exhaustive tests for get_snapshot_context function

That diff is quite large as I performed some keys renaming in dictionaries spanning
numerous files. I have also added mising tests.

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 edited the summary of this revision. (Show Details)

Build is green

Patch application report for D3041 (id=10807)

Rebasing onto 88847f09e8...

Current branch diff-target is up to date.
Changes applied before test
commit a71f64e0d19fd6fbe1c0a8e6105c9fc25eefae02
Author: Antoine Lambert <antoine.lambert@inria.fr>
Date:   Wed Apr 15 13:47:21 2020 +0200

    browse/snapshot_context: Refactor, add type annotations and tests
    
    Slightly refactor and improve the swh.web.browse.snapshot_context module:
    
      - merge _process_snapshot_request function into get_snapshot_context one
    
      - rename some dict keys and add snapshot / origin related type annotations
    
      - cleanup and simplify get_snapshot_context implementation
    
      - update some docstrings
    
      - add new exhaustive tests for get_snapshot_context function
    
    Closes T2360

See https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/71/ for more details.

ardumont added inline comments.
swh/web/browse/snapshot_context.py
651

It's retrieving the GET query parameters, right?
(i forgot ;)

I think it's fine :D

It's "slightly" big ;)

This revision is now accepted and ready to land.Apr 21 2020, 5:15 PM

I think it's fine :D

It's "slightly" big ;)

Yes sorry, I started playing with mypy and had to modify quite a lot of files ...
This is mostly code readability improvements, some slight reorganization and code duplication removal.

I could have split it in multiple parts (notably the origin visit stuffs) but snapshots, origins and visits are so tightly linked
so I processed all of them regarding type annotations in one batch. Plus I would like to advance on T2342 as it is quite urgent for Roberto.

swh/web/browse/snapshot_context.py
651

Yes it is ;-)

anlambert edited the summary of this revision. (Show Details)

Update: Do not filtered out branches with a non resolvable revision (restore previous behavior)

Build is green

Patch application report for D3041 (id=10808)

Rebasing onto 88847f09e8...

Current branch diff-target is up to date.
Changes applied before test
commit 40ac1374bc4aed7b3d3c7f48f2f8dc1170446f28
Author: Antoine Lambert <antoine.lambert@inria.fr>
Date:   Wed Apr 15 13:47:21 2020 +0200

    browse/snapshot_context: Refactor, add type annotations and tests
    
    Slightly refactor and improve the swh.web.browse.snapshot_context module:
    
      - merge _process_snapshot_request function into get_snapshot_context one
    
      - rename some dict keys and add snapshot / origin related type annotations
    
      - cleanup and simplify get_snapshot_context implementation
    
      - update some docstrings
    
      - add new exhaustive tests for get_snapshot_context function
    
    Closes T2360

See https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/72/ for more details.