Skip to content
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): improve create_req and create_asgi_req #2249

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

iuliachiriac
Copy link

@iuliachiriac iuliachiriac commented Jul 14, 2024

Summary of Changes

This PR changes create_req and create_asgi_req to make their behaviour consistent with simulate_request by:

  • adding missing parameters: content_type, json, params, params_csv
  • adding call to _prepare_sim_args function (which was also moved to helpers.py), which does a series of checks on request attributes and sets Content-Type
  • enabling passing arbitrary WSGI/ASGI envs through extra argument

Related Issues

#1793

Pull Request Checklist

  • Applied changes to both WSGI and ASGI code paths and interfaces (where applicable).
  • Added tests for changed code.
  • Prefixed code comments with GitHub nick and an appropriate prefix.
  • Coding style is consistent with the rest of the framework.
  • Updated documentation for changed code.
    • Added docstrings for any new classes, functions, or modules.
    • Updated docstrings for any modifications to existing code.
    • Updated both WSGI and ASGI docs (where applicable).
    • Added references to new classes, functions, or modules to the relevant RST file under docs/.
    • Updated all relevant supporting documentation files under docs/.
    • A copyright notice is included at the top of any new modules (using your own name or the name of your organization).
    • Changed/added classes/methods/functions have appropriate versionadded, versionchanged, or deprecated directives.
  • Changes (and possible deprecations) have towncrier news fragments under docs/_newsfragments/, with the file name format {issue_number}.{fragment_type}.rst. (Run towncrier --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.

enable passing `json`, `params`, `params_csv`, `content_type`
enable passing arbitrary WSGI envs through `extras`
do extra checks on request attributes through `_prepare_sim_args`
move `_prepare_sim_args` to `helpers.py`
@iuliachiriac
Copy link
Author

I submitted this as a draft because I plan on addressing remaining changes in #1793 in the following days.

Copy link

codecov bot commented Jul 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (c124e3a) to head (0b23def).
Report is 42 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2249   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           63        63           
  Lines         7112      7124   +12     
  Branches      1260      1264    +4     
=========================================
+ Hits          7112      7124   +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

iuliachiriac and others added 5 commits July 18, 2024 15:55
* enable passing `json`, `params`, `params_csv`, `content_type`,
  `extras`
* do extra checks on request attributes through `_prepare_sim_args`
* set Content-Length if not passed
* add extras to ASGI scope
* test was failing with a TypeError (expected str, got MagicMock)
* keep mocked function behaviour by using a side_effect
@iuliachiriac iuliachiriac marked this pull request as ready for review July 30, 2024 09:05
@iuliachiriac iuliachiriac changed the title feat(testing): make create_req consistent with simulate_request feat(testing): improve create_req and create_asgi_req Jul 30, 2024
@vytas7
Copy link
Member

vytas7 commented Aug 30, 2024

Hi Iuliana, and thanks once again for Sprinting in Prague!
Just checking if you are planning to continue on this issue? It looks like it is not that much left here, well done so far! 💯

@iuliachiriac
Copy link
Author

Hi Iuliana, and thanks once again for Sprinting in Prague! Just checking if you are planning to continue on this issue? It looks like it is not that much left here, well done so far! 💯

Hi Vytautas! Thank you for the opportunity and the guidance! I will get back to it this week, if it't not too late, sorry for the delay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants