Colin-b / pytest_httpx

pytest fixture to mock HTTPX
https://colin-b.github.io/pytest_httpx/
MIT License
344 stars 32 forks source link

Added the match_json_content matcher #103

Closed dolfandringa closed 1 year ago

dolfandringa commented 1 year ago

closes #83 Added the match_json_content matcher which checks if the passed object matches the json decoded request body

I preferred adding a new matcher match_json_content over modifying the existing match_content.

I could have added conditions that if the match_content argument isn't of type bytes then assume we want to json decode the body, but that doesn't match nicely with Explicit is better than implicit., and with the extra argument I think the code also stays cleaner.

dolfandringa commented 1 year ago

Few small oversights, last one was a formatting issue in the README.md docs. All tests are present and passing, both sync and async.

dolfandringa commented 1 year ago

Now really fixed, after I ran coverage and discovered I missed something

Colin-b commented 1 year ago

Seems like a nice feature, thanks for tackling this up! I think I will tweak it a bit after merge but this would only be cosmetics. I don't have time to invest in it right now however. Is it ok if I try to tackle this next week ?

dolfandringa commented 1 year ago

Could you rename match_json_content into matchjson ? It would follow a bit more the structure where we provide match{name_of_the_httpx_parameter}

Cool, will do. To stay in the same theme, I also renamed self.match_json to self.json (like self.content)

dolfandringa commented 1 year ago

Thanks for the comments. They made sense. I think I addressed them all.

sonarcloud[bot] commented 1 year ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication