Page MenuHomeSoftware Heritage

Refactor BaseApiDepositClient to get rid of the _client argument
ClosedPublic

Authored by douardda on Nov 6 2020, 11:15 AM.

Details

Summary

This argument was only there to make it easier to mock the HTTP calls
(via a mocked requests). Thanks to the mockup capabilities, this is in
fact not necessary. So get rid of it and replace its usage in tests by
proper use of the mocker pytest fixture.

Also:

  • refactor this BaseApiDepositClient constructor to acces directly "url" and "auth" kwargs instead of an unspecified generic config dict (still supported but deprecated),
  • get rid of a few actually not really needed fixtures (deposit_config)
  • rewrite PrivateApiDepositClientStatusUpdateTest as a couple of pytest functions,
  • get rid of onliners functions in swh.deposit.cli.client (_client(), deposit_create, deposit_update).

Diff Detail

Repository
rDDEP Push deposit
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Build is green

Patch application report for D4431 (id=15687)

Rebasing onto 0f4ec31168...

Current branch diff-target is up to date.
Changes applied before test
commit 77900028c2c694fc67b1c3fa1046de60aa5e80f5
Author: David Douard <david.douard@sdfa3.org>
Date:   Mon Nov 2 14:39:42 2020 +0100

    Refactor BaseApiDepositClient to get rid of the _client argument
    
    This argument was only there to make it easier to mock the HTTP calls
    (via a mocked requests). Thanks to the mockup capabilities, this is in
    fact not necessary. So get rid of it and replace its usage in tests by
    proper use of the mocker pytest fixture.
    
    Also:
    - refactor this BaseApiDepositClient constructor to acces directly
      "url" and "auth" kwargs instead of an unspecified generic config dict
      (still supported but deprecated),
    - get rid of a few actually not really needed fixtures (deposit_config)
    - rewrite PrivateApiDepositClientStatusUpdateTest as a couple of pytest
      functions,
    - get rid of onliners functions in  swh.deposit.cli.client (_client(),
      deposit_create, deposit_update).

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

vlorentz added a subscriber: vlorentz.
vlorentz added inline comments.
swh/deposit/client.py
134

it doesn't just notify, but also computes a value.

162–166

these four lines look a lot like the code in notify_deprecated.

(also, the or None is redundant)

172

move the comment on the line before the assert, so black doesn't need to add newlines like this

swh/deposit/tests/loader/test_client.py
37–38

not covered?

also, "passzord"

This revision now requires changes to proceed.Nov 6 2020, 12:24 PM

Build is green

Patch application report for D4431 (id=15726)

Rebasing onto 7148a257b2...

Current branch diff-target is up to date.
Changes applied before test
commit 5e05355a83ae33a03d2daa60052dda3c600ac9c2
Author: David Douard <david.douard@sdfa3.org>
Date:   Mon Nov 2 14:39:42 2020 +0100

    Refactor BaseApiDepositClient to get rid of the _client argument
    
    This argument was only there to make it easier to mock the HTTP calls
    (via a mocked requests). Thanks to the mockup capabilities, this is in
    fact not necessary. So get rid of it and replace its usage in tests by
    proper use of the mocker pytest fixture.
    
    Also:
    - refactor this BaseApiDepositClient constructor to acces directly
      "url" and "auth" kwargs instead of an unspecified generic config dict
      (still supported but deprecated),
    - get rid of a few actually not really needed fixtures (deposit_config)
    - rewrite PrivateApiDepositClientStatusUpdateTest as a couple of pytest
      functions,
    - get rid of onliners functions in  swh.deposit.cli.client (_client(),
      deposit_create, deposit_update).

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

Fixes according to vlorentz' comments

ardumont added inline comments.
swh/deposit/cli/client.py
249

It's already there line 254 below.

Build is green

Patch application report for D4431 (id=15730)

Rebasing onto 7148a257b2...

Current branch diff-target is up to date.
Changes applied before test
commit bda0d3b5d7e33fd9e981f075a8f3ac425698d442
Author: David Douard <david.douard@sdfa3.org>
Date:   Mon Nov 2 14:39:42 2020 +0100

    Refactor BaseApiDepositClient to get rid of the _client argument
    
    This argument was only there to make it easier to mock the HTTP calls
    (via a mocked requests). Thanks to the mockup capabilities, this is in
    fact not necessary. So get rid of it and replace its usage in tests by
    proper use of the mocker pytest fixture.
    
    Also:
    - refactor this BaseApiDepositClient constructor to acces directly
      "url" and "auth" kwargs instead of an unspecified generic config dict
      (still supported but deprecated),
    - get rid of a few actually not really needed fixtures (deposit_config)
    - rewrite PrivateApiDepositClientStatusUpdateTest as a couple of pytest
      functions,
    - get rid of onliners functions in  swh.deposit.cli.client (_client(),
      deposit_create, deposit_update).

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

swh/deposit/tests/loader/test_client.py
37–38

not sure I get the "not covered?" part here

swh/deposit/tests/loader/test_client.py
37–38

the jenkins coverage report on the right (once jenkins build is done) for the else block is orange (so it's not covered).

swh/deposit/cli/client.py
249

oops, thx

fix a few more oopsies reported by vlorentz and ardumont

Build is green

Patch application report for D4431 (id=15735)

Rebasing onto 7148a257b2...

Current branch diff-target is up to date.
Changes applied before test
commit 7e69a87f813630102696a2a0a4238cf5cf7545ff
Author: David Douard <david.douard@sdfa3.org>
Date:   Mon Nov 2 14:39:42 2020 +0100

    Refactor BaseApiDepositClient to get rid of the _client argument
    
    This argument was only there to make it easier to mock the HTTP calls
    (via a mocked requests). Thanks to the mockup capabilities, this is in
    fact not necessary. So get rid of it and replace its usage in tests by
    proper use of the mocker pytest fixture.
    
    Also:
    - refactor this BaseApiDepositClient constructor to acces directly
      "url" and "auth" kwargs instead of an unspecified generic config dict
      (still supported but deprecated),
    - get rid of a few actually not really needed fixtures (deposit_config)
    - rewrite PrivateApiDepositClientStatusUpdateTest as a couple of pytest
      functions,
    - get rid of onliners functions in  swh.deposit.cli.client (_client(),
      deposit_create, deposit_update).

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

This revision is now accepted and ready to land.Nov 9 2020, 4:17 PM

Build is green

Patch application report for D4431 (id=15780)

Rebasing onto 018500c195...

Current branch diff-target is up to date.
Changes applied before test
commit c7e397e527a13fc09ffb314c3a2cc9df69712160
Author: David Douard <david.douard@sdfa3.org>
Date:   Mon Nov 2 14:39:42 2020 +0100

    Refactor BaseApiDepositClient to get rid of the _client argument
    
    This argument was only there to make it easier to mock the HTTP calls
    (via a mocked requests). Thanks to the mockup capabilities, this is in
    fact not necessary. So get rid of it and replace its usage in tests by
    proper use of the mocker pytest fixture.
    
    Also:
    - refactor this BaseApiDepositClient constructor to acces directly
      "url" and "auth" kwargs instead of an unspecified generic config dict
      (still supported but deprecated),
    - get rid of a few actually not really needed fixtures (deposit_config)
    - rewrite PrivateApiDepositClientStatusUpdateTest as a couple of pytest
      functions,
    - get rid of onliners functions in  swh.deposit.cli.client (_client(),
      deposit_create, deposit_update).

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

Build is green

Patch application report for D4431 (id=15801)

Rebasing onto c815bbf19a...

Current branch diff-target is up to date.
Changes applied before test
commit 1129a092e6718c1c7bfc8bd467d4f389066f6b65
Author: David Douard <david.douard@sdfa3.org>
Date:   Mon Nov 2 14:39:42 2020 +0100

    Refactor BaseApiDepositClient to get rid of the _client argument
    
    This argument was only there to make it easier to mock the HTTP calls
    (via a mocked requests). Thanks to the mockup capabilities, this is in
    fact not necessary. So get rid of it and replace its usage in tests by
    proper use of the mocker pytest fixture.
    
    Also:
    - refactor this BaseApiDepositClient constructor to acces directly
      "url" and "auth" kwargs instead of an unspecified generic config dict
      (still supported but deprecated),
    - get rid of a few actually not really needed fixtures (deposit_config)
    - rewrite PrivateApiDepositClientStatusUpdateTest as a couple of pytest
      functions,
    - get rid of onliners functions in  swh.deposit.cli.client (_client(),
      deposit_create, deposit_update).

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