-
-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added expected_data parameter to register_uri #97
base: main
Are you sure you want to change the base?
Conversation
This checks that POST payload received matches the one expected. This is very helpful for improving robustness of some mocked tests.
tests/functional/test_requests.py
Outdated
"https://api.imaginary.com/v1/sweet/", | ||
{"wrong": "data"} | ||
) | ||
raise Exception("Payload checked didn't work") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could have used:
requests.post.when.called_with("https://api.imaginary.com/v1/sweet/", {"wrong": "data"}).should.throw(ValueError)
I've moved indented code to a method named I've also adjusted the test as you mentioned. Thanks for the feedback. BTW I had to do a push force because Github five hundred yesterday while i was pushing and the repository end up inconsistent. Cheers, |
@maraujop I love it, thank you for your time. I'm pretty busy rightnow but as soon as I get some free time I will apply this. Again, thank you so much! |
…cted_data Conflicts: httpretty/core.py tests/functional/test_requests.py
Hi Gabriel, I've rebased the patch against latest |
I've done something similar in #168 which might subsume this feature, though its purpose is a little different. |
if self.expected_data is not None: | ||
body_dict = dict(parse_qsl(request.body)) | ||
if body_dict != self.expected_data: | ||
raise ValueError("Body Post didn't match, expected %s, got %s" % ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should raise an AssertionError
instead, that way the test will fail as failure rather than error
This checks that POST payload received matches the one expected. This is very helpful for improving robustness of some mocked tests, when creating or updating objects, it is very helpful to check data sent to the endpoint was correct, otherwise a bug could be in between and there is no easy way to catch it.
Currently you can access last request's body as you know, but doing it this way is more elegant and easy to follow, as everything is gathered together in the same mock registration.
Thanks, cheers,
Miguel