ssl-hep / ServiceX_frontend

Client access library for ServiceX
https://servicex-frontend.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
5 stars 11 forks source link

Added Test cases for Servicex_Adapter #428

Closed ketan96-m closed 3 months ago

ketan96-m commented 3 months ago

In light of using the new Aiohttp module for making async get and post requests, the typical httpx.Response was not working. Since we were dealing with double context managers e.g

        async with RetryClient() as client:
            async with client.post(url, headers=headers, json=None) as r:

Found a way to patch the get request Decorate the test functions with @patch("servicex.servicex_adapter.RetryClient.get")

Mock response and status

get.return_value.__aenter__.return_value.json.return_value = transform_status_response
get.return_value.__aenter__.return_value.status = 200

Resources: https://stackoverflow.com/questions/28850070/python-mocking-a-context-manager https://blog.sneawo.com/blog/2019/05/22/mock-aiohttp-request-in-unittests/

Optimizations:

get.return_value.__aenter__.return_value.json.return_value = transform_status_response
get.return_value.__aenter__.return_value.status = 200

Any help in compressing the 2 lines into one so that we can pass the response(with json and status code) directly to the get.return_value Typical httpx.Response() doesn't work

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Please upload report for BASE (fix_timeouts@66a1dca). Learn more about missing BASE report.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## fix_timeouts #428 +/- ## =============================================== Coverage ? 80.90% =============================================== Files ? 26 Lines ? 1351 Branches ? 0 =============================================== Hits ? 1093 Misses ? 258 Partials ? 0 ``` | [Flag](https://app.codecov.io/gh/ssl-hep/ServiceX_frontend/pull/428/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ssl-hep) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/ssl-hep/ServiceX_frontend/pull/428/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ssl-hep) | `80.90% <100.00%> (?)` | | 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=ssl-hep#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.