-
-
Notifications
You must be signed in to change notification settings - Fork 227
Fix multipart File fields #372
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
Fix multipart File fields #372
Conversation
8efb6ad
to
f7d68a9
Compare
Codecov Report
@@ Coverage Diff @@
## main #372 +/- ##
========================================
Coverage ? 100.00%
========================================
Files ? 47
Lines ? 1558
Branches ? 0
========================================
Hits ? 1558
Misses ? 0
Partials ? 0
Continue to review full report at Codecov.
|
@dbanty This is the other PR I mentioned :) |
f7d68a9
to
b2443c8
Compare
Btw I only had to move those golden record files so that I could import one of them for the e2e test (the directory was I didn't realise this but there might be another option if you prefer to keep the existing directory name. |
b2443c8
to
cf12b66
Compare
@dbanty Now rebased |
cf12b66
to
23b0de8
Compare
@dbanty Now rebased again |
23b0de8
to
859d9ca
Compare
Seems like the main reason for switching the names around was to import the generated code to do a more unit-test thing within the e2e test. The golden-record stuff is really intended to be a snapshot test, an easy way for me to see in reviews how the changes impact the generated code. This makes it easy to pick out accidental changes. We probably want to have more specific tests of the generated code to make sure they do what's intended eventually, but I think we'd want to target those more (e.g. just generate one specific Jinja template with specific params and make sure it does what it's supposed to). I haven't decided on a strategy to achieve that yet. So my recommendation here would be to drop out the unit test of the generated code and move the name back to golden-record so it's more obvious what changed. |
I guess in my mind it was an end-to-end test of the library, but no worries, I'll change it to a unit test. |
Yeah I should probably change the name. It was intended to be integration tests as well but those got really hard to maintain and didn't add much value so it became just snapshot tests. We probably need some middle ground targeted integration tests that are separate from the unit tests of the generator itself but not as complicated as the full-on end-to-end generation snapshot. |
0c2e3eb
to
0a5d7f8
Compare
I couldn't find a way to convert my "end-to-end" test to a unit test, but I suppose the fact that I've added those extra bits to |
cbe40af
to
b5b5833
Compare
@dbanty Now rebased, could we get this into the next release? |
Yes, sorry! I keep starting to review this and getting pulled away 😅. I have a few questions that I'll try and put some comments on today so this can move forward. |
end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py
Outdated
Show resolved
Hide resolved
Great, so it seems like there are a few action items then, some of which may be handled in separate tasks:
Some of those things may already be done by the time I comment this because some new commits just came in from @csymeonides-mf 😆 . Thanks for all the feedback and discussion around this! |
bc3d0f3
to
08fd630
Compare
Ok, I don't think I've done all the things on your list, but hopefully enough for now! |
I've set this back to draft because when I tested it with a string field (not JSON) I realised that httpx doesn't handle them correctly - it converts them into files. Maybe I should be JSON-encoding strings as well? But that sounds wrong. Putting them in @p1-ra if you have any ideas that would be much appreciated. |
@dbanty this also made me realise that the e2e test I had written earlier would have caught this problem... do you have any advice on how we can re-introduce that test in a way that fits your approach? As I said earlier I couldn't find a way to unit-test this, because it involves running the code which has been generated from the jinja templates. |
5ab8f17
to
172921d
Compare
@dbanty All fixed now! |
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 great work, thank you! Just a couple suggestions then I think we're good to go.
As far as being able to run the e2e-generated code for better testing, I have two ideas:
- Generate tests for the generated code. I have seen other generators include tests in the box before, so maybe that's something folks want anyway?
- Use
update
instead ofgenerate
when regenerating golden-record and manually maintain atests
directory ingolden-record
which tests the generated code. If we wanted to we could even go so far as spawning a local server to test against (this project actually used to do that using FastAPI when it first started).
In either case, we could then just run pytest
in that directory to run those tests. Thoughts on either of those paths? This would be in a different, future PR, I just agree that we need some more thorough tests on the generated code to be more confident in changes going forward.
openapi_python_client/templates/property_templates/list_property.py.jinja
Outdated
Show resolved
Hide resolved
openapi_python_client/templates/property_templates/model_property.py.jinja
Outdated
Show resolved
Hide resolved
This sounds great to me, though maybe we still want a separate test that runs |
33bc36a
to
9b301b2
Compare
9b301b2
to
7cbeb7e
Compare
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.
Awesome! Thanks so much for putting all this work into this!
…r complex types (#372). Thanks @csymeonides-mf! * fix: Detect File fields correctly * fix: Optional File field caused missing import error * fix: Non-string multipart fields must be stringified * chore: Reformat * fix: Put non-file fields as tuples in the files dict * refactor: Avoid runtime type checks * fix: Declaring types is necessary * fix: Remove dead code * fix: Non-JSON non-file multipart props need to be text/plain * refactor: Avoid breaking change Co-authored-by: Constantinos Symeonides <[email protected]>
…r complex types (#372). Thanks @csymeonides-mf! * fix: Detect File fields correctly * fix: Optional File field caused missing import error * fix: Non-string multipart fields must be stringified * chore: Reformat * fix: Put non-file fields as tuples in the files dict * refactor: Avoid runtime type checks * fix: Declaring types is necessary * fix: Remove dead code * fix: Non-JSON non-file multipart props need to be text/plain * refactor: Avoid breaking change Co-authored-by: Constantinos Symeonides <[email protected]>
No description provided.