Modify HTTPretty to allow for assertion testing#19
Conversation
ajhodges
left a comment
There was a problem hiding this comment.
I like the idea of this feature, but I'm not sure it belongs in a mixin. Seems to me like a decorator would be more appropriate. I think it'd be cleaner and a little more flexible. Something like:
@httpretty_assertions([{'path': '/bing-path', 'query': {'param_1': 1}}])
Where the position drives the asserted order, not an index parameter. Or alternatively you could write a HTTPretty class that inherits from the base one and provides a httpretty.assert_calls() method.
@mlclay also had the idea to add something similar to the functionality in https://github.com/kavod/WWWoman where we can define the mocked urls and assertions together in an annotation.
This is obviously a big change and will need to be factored into future sprint planning.
cdcda70 to
11b9a4d
Compare
|
Were you happy with this? I remember you said there were some changes you wanted to make to mine. |
|
Thinking about it, I'm curious as to whether you believe that the path should always be required in the assertion? does it make sense to check that when there is no path? |
|
What do you mean by "does it make sense to check that when there is no path"? I don't know how you could make HTTPretty assertions without a URL. Also, it looks like the commits on this branch got screwed up somehow. I am seeing changes in the diff that are already in master. Please rebase. |
|
Basically, the path is checking everything after the |
|
If a request is made to |
|
And in those instances does it still make sense to require that as a parameter in the assertion? It couldn't hurt but I was just thinking that it might seem like an unnecessary check |
|
Yes, assertions should be explicit |
d598e98 to
fcd2ee1
Compare
ajhodges
left a comment
There was a problem hiding this comment.
@mlclay made a good point - I think this would be nice to have as part of our pytest plugin (in the same way that json_asserter was). This would make usage a little easier. Maybe name it httpretty_asserter. I would not make it an autouse fixture though.
ajhodges
left a comment
There was a problem hiding this comment.
Can you please squash some of these commits from the refactor that was rolled back? It's ready for merge after that.
e7386af to
75f30ee
Compare
Add HttprettyAsserterMixin Modify httpretty asserter from mixin to modification of httpretty DRY query_dict's
75f30ee to
3702247
Compare
When running pytests, there is not a very clear and easy way to test that all your mocked calls have been made, and if they have been made with the expected data. This provides a way to ensure that all the calls were made as expected, via passing in a list of assertions to HTTPretty.
This is run by using the
HTTPrettyAsserterin a yield fixture, and passing in a list of assertions to theassert_callsfunction on the mocked calls.