Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
RequestURL and ResponseURL #42
RequestURL and ResponseURL #42
Changes from all commits
b2c665e
10a3883
f56da89
890a238
5b0e889
2884d2f
ea11f3d
ba4e615
aad8ae6
9287744
237fab6
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
@Gallaecio has raised a good point if
HttpResponse("url")
andHttpRequest("url")
are equal. We should add a test for such.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.
I've added a test which shows that they're not equal.
But I'm not sure this behavior is useful. What kind of errors would it prevent?
I wonder if it'd better to leave it "undefined", instead of solidifying this behavior in tests (if that's even a reasonable approach :)
pathlib does some magic when comparing paths, it's not a simple string match. E.g. on Windows path components are lower-cased before comparison.
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.
The test simply solidifies the expectation to users in case they're unsure. As a user, I might expect when initially using it for the first time that the expression
response.url == request.url
holds True. However, I need to cast it to its string value to bear True.I also expect such test to conveniently break when we override
__eq__
to another behavior. It helps future PRs denote that an equality expectation will change.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.
I don't think we should be casting this to
str
as the tests that rely on this mock are expectingResponseUrl
. We'd need to update the downstream tests instead to validate their expectations.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.
I must admit I failed to make tests working, and applied this hack instead :) Mocks are not my friends.
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.
I was thinking it's harmless, because tests should be getting ResponseUrl, as HttpResponse should be converting str to ResponseUrl; without having mocks in mind the change doesn't really change the behavior. But I'm likely missing some interactions with mocks which are in effect here.
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.
hey @BurnzZ @Gallaecio! I tried to follow @Gallaecio's suggestion, and created a minimal version of the Url base class. To keep it minimal, I haven't added anything useful to the
_Url
class; that's the difference with #45On one hand, it allows us to improve _Url class in future almost without any restrictions.
On the other hand, it kind-of gets in a way now. With this implementation, users need to cast to str almost always: for example, HttpClient backends would always need to do
str(request.url)
.So, for the users the current implementation is more cumbersome than just using
str
, or having URL a str subclass, without any benefits. It may be ok.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 is for backwards compatibility, and also for consistency with .base_url and .urljoin properties, where urls are strings.
Overall, I don't like ResponseShortcutsMixin, it seems using HttpResponse methods is better :)