-
-
Notifications
You must be signed in to change notification settings - Fork 946
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
feat(testing): simulate multipart file upload #2141
base: master
Are you sure you want to change the base?
feat(testing): simulate multipart file upload #2141
Conversation
Tests: added a test case to test_unset_cookies and to on_get in CookieUnset
…te; added towncrier news fragment.
…load (text, urlencoded, image, nested) and some errors.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2141 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 63 63
Lines 7485 7522 +37
Branches 1278 1286 +8
=========================================
+ Hits 7485 7522 +37 ☔ View full report in Codecov by Sentry. |
I used urllib3 and I added it to requirements, but it isn't found in the tests - where does it need to be added to be seen? |
Hi again @TigreModerata, and thanks for this improvement 👍 |
I'll try to write it out, it's probably good exercise :) |
Yeah, it should be easy at least when it comes to basic functionality, check out |
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.
Looks great so far 💯
As discussed, we just need to get rid of urllib3
, or if the functionality in question is non-trivial to implement, we need to make it optional, like msgpack, jsonschema, etc.
(But of course I'd prefer if this was implemented directly in the framework.)
tests/files/loremipsum.txt
Outdated
@@ -0,0 +1,11 @@ | |||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor |
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.
Do we really need to add separate files? Maybe we could just use inline strings, or use existing source or image files?
Otherwise we need to surface these new files in MANIFEST.in
to get them included in the sdist.
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 didn't really know... I wanted to make sure all goes well mainly with bigger stuff (the image), but now that I'm sure I'll remove them.
docs/changes/4.0.0.rst
Outdated
@@ -15,7 +15,6 @@ Changes to Supported Platforms | |||
- CPython 3.11 is now fully supported. (`#2072 <https://github.com/falconry/falcon/issues/2072>`__) | |||
- End-of-life Python 3.5 & 3.6 are no longer supported. (`#2074 <https://github.com/falconry/falcon/pull/2074>`__) | |||
|
|||
|
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.
Is there any particular reason behind this newline removal?
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 know what happened... was that me?
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 think it must have been you, yes. It is coming from you changeset, but it might be some artefact of merging things back and forth on your side, not necessarily something you actively did.
I added the data arg to simulate_post, in such a way that if both json and (files or data) are present, a badrequest exception is thrown. If json is absent, then files and data will be processed: if files is also absent, data will be url-encoded. [I am really a beginner, so some of what you said may have gone over my head... I apologize. Since you guys are so responsive, this is a great help to me to learn/practice, I really appreciate your patience!] |
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.
thanks for the change. let's wait for @vytas7 review
falcon/testing/client.py
Outdated
urlresult = [] | ||
body_part = b'' | ||
if isinstance(data, (str, bytes)) or hasattr(data, 'read'): | ||
fields = list(json_module.loads(data).items()) |
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.
so we are assuming that if provided as string it's a json.
this would mean that we cannot replace deprecate body with data.
let's see @vytas7 opinion
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.
ok, I hadn't really understood what you guys meant by replacing the body... but ok, that should be an easy fix. I'll try to implement it, then you can use whatever works best.
(I'm in the process of terraforming this somewhat... ) |
Hi @vytas7 , did something happen, can I do anything to help? I just got a notification saying "mentioned" but I'm not sure why. I've not looked at this in ages, but I have time and I'm happy to try to contribute. |
Hi @TigreModerata! I was thinking to update your PR, and to change Does that sound like a good plan? |
I'm not totally sure what needs to be done, I need to refresh my memory a bit. But yeah, I'm happy if I can contribute! |
Hi again @TigreModerata!
That's why I thought it would be a good opportunity to restart this from scratch, it doesn't need to be too complex in the first iteration. I was thinking we could simply add a I have written a simple proof-of-concept implementation, but it needs more validation, tests, documentation, and a newsfragment.
You are very welcome to! |
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.
overall seems ok. I've not checked if the api is consistent with what was suggested before or what request etc do
Summary of Changes
Draft of tests section for post-ing files as multipart/form-data. Parameter 'files' added to simulate_requests in the testing client, as well as a file test_multipart_formdata_request of tests.
Related Issues
#1010
Pull Request Checklist
This is just a reminder about the most common mistakes. Please make sure that you tick all appropriate boxes. But please read our contribution guide at least once; it will save you a few review cycles!
If an item doesn't apply to your pull request, check it anyway to make it apparent that there's nothing to do.
docs/
.docs/
.versionadded
,versionchanged
, ordeprecated
directives.docs/_newsfragments/
, with the file name format{issue_number}.{fragment_type}.rst
. (Runtowncrier --draft
to ensure it renders correctly.)If you have any questions to any of the points above, just submit and ask! This checklist is here to help you, not to deter you from contributing!
PR template inspired by the attrs project.