ITISFoundation / osparc-simcore

🐼 osparc-simcore simulation framework
https://osparc.io
MIT License
44 stars 26 forks source link

♻️🔨 Removes httpx client capture from `api-server` and moves to a plugin in `pytest_simcore` (⚠️) #5798

Closed pcrespov closed 2 months ago

pcrespov commented 2 months ago

What do these changes do?

This PR removes "httpx client capture" mechanism from api-server and moves it as fixtures to pytest_simcore.httpx_calls_capture plugin.

"httpx client capture " is a technique that wraps httpx clients and captures calls (i.e. both requests and responses) from the client to/from the back-end. These "captures" are then dumped into a file and used to produce respx.MockRouters that mock the behavior of the back-end during tests. In #5705 we argue that it might be handy to incorporate this mechanism as part of the testing infrastructure instead of being part of the code (as it was now). This way we can use the tests to both

In addition, any service tests that includes pytest_simcore.httpx_calls_capture plugin can now enable, via CLI, a spy on the httpx.AsyncClient to produce capture files and then use them to create respx.MockRouter that mock the back-end.

Related issue/s

How to test

Let's assume we are create a new test suit called test_it.

async def test_my_stuff(client: httpx.AsyncClient, mocked_backend: MockedBackendApiDict):
   await call_some_external_service()
   # rest API in my app but might forward calls to other external backend services
   r = await client.get("/v0/foo")

Dev-ops checklist

codecov[bot] commented 2 months ago

Codecov Report

Attention: Patch coverage is 60.00000% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 86.9%. Comparing base (cafbf96) to head (c3d0da5). Report is 217 commits behind head on master.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5798/graphs/tree.svg?width=650&height=150&src=pr&token=h1rOE8q7ic&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation)](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5798?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation) ```diff @@ Coverage Diff @@ ## master #5798 +/- ## ========================================= + Coverage 84.5% 86.9% +2.4% ========================================= Files 10 1354 +1344 Lines 214 56476 +56262 Branches 25 1284 +1259 ========================================= + Hits 181 49134 +48953 - Misses 23 7068 +7045 - Partials 10 274 +264 ``` | [Flag](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5798/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation) | Coverage Δ | | |---|---|---| | [integrationtests](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5798/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation) | `60.9% <ø> (?)` | | | [unittests](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5798/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation) | `85.6% <60.0%> (+1.0%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5798?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation) | Coverage Δ | | |---|---|---| | [...er/src/simcore\_service\_api\_server/core/settings.py](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5798?src=pr&el=tree&filepath=services%2Fapi-server%2Fsrc%2Fsimcore_service_api_server%2Fcore%2Fsettings.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation#diff-c2VydmljZXMvYXBpLXNlcnZlci9zcmMvc2ltY29yZV9zZXJ2aWNlX2FwaV9zZXJ2ZXIvY29yZS9zZXR0aW5ncy5weQ==) | `100.0% <ø> (ø)` | | | [...\_api\_server/services/service\_exception\_handling.py](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5798?src=pr&el=tree&filepath=services%2Fapi-server%2Fsrc%2Fsimcore_service_api_server%2Fservices%2Fservice_exception_handling.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation#diff-c2VydmljZXMvYXBpLXNlcnZlci9zcmMvc2ltY29yZV9zZXJ2aWNlX2FwaV9zZXJ2ZXIvc2VydmljZXMvc2VydmljZV9leGNlcHRpb25faGFuZGxpbmcucHk=) | `82.6% <50.0%> (ø)` | | | [...rc/simcore\_service\_api\_server/utils/client\_base.py](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5798?src=pr&el=tree&filepath=services%2Fapi-server%2Fsrc%2Fsimcore_service_api_server%2Futils%2Fclient_base.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation#diff-c2VydmljZXMvYXBpLXNlcnZlci9zcmMvc2ltY29yZV9zZXJ2aWNlX2FwaV9zZXJ2ZXIvdXRpbHMvY2xpZW50X2Jhc2UucHk=) | `93.7% <66.6%> (ø)` | | ... and [1328 files with indirect coverage changes](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5798/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation)
sonarcloud[bot] commented 2 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.2% Duplication on New Code

See analysis details on SonarCloud