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

Fix test_utils.make_mocked_request behaviour for empty payload #7168

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rahulnht
Copy link

What do these changes do?

Fixes #7167

In case of empty payload when initialized, it now assigns the payload as EMPTY_RESPONSE instance of EmptyStreamReader available via aiohttp/streams.py

Are there changes in behavior for the user?

No

Related issue number

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES folder
    • name it <issue_id>.<type> for example (588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the pr
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files."

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Jan 13, 2023
@@ -632,7 +633,7 @@ def make_mocked_request(
protocol.writer = writer

if payload is sentinel:
payload = mock.Mock()
payload = EMPTY_PAYLOAD
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels to me like everything here should be a mock. Maybe instead we should autospec it? That should ensure it gets an appropriate mock with the correct methods.

Suggested change
payload = EMPTY_PAYLOAD
payload = create_autospec(StreamResponse, spec_set=True, instance=True)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same should really be done to all the rest of this code... Would make the code safer and more maintainable.

@codecov
Copy link

codecov bot commented Jan 13, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (743c21f) 97.37% compared to head (6249960) 97.37%.
Report is 524 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7168   +/-   ##
=======================================
  Coverage   97.37%   97.37%           
=======================================
  Files         106      106           
  Lines       31093    31098    +5     
  Branches     3875     3875           
=======================================
+ Hits        30278    30283    +5     
  Misses        613      613           
  Partials      202      202           
Flag Coverage Δ
CI-GHA 97.28% <100.00%> (+<0.01%) ⬆️
OS-Linux 96.93% <100.00%> (-0.01%) ⬇️
OS-Windows 95.35% <100.00%> (+<0.01%) ⬆️
OS-macOS 96.50% <100.00%> (+<0.01%) ⬆️
Py-3.10.9 97.03% <100.00%> (+<0.01%) ⬆️
Py-3.11.0 95.60% <100.00%> (+<0.01%) ⬆️
Py-3.7.15 96.75% <100.00%> (+<0.01%) ⬆️
Py-3.7.9 95.23% <100.00%> (+<0.01%) ⬆️
Py-3.8.10 95.13% <100.00%> (-0.01%) ⬇️
Py-3.8.15 96.65% <100.00%> (+<0.01%) ⬆️
Py-3.9.13 95.12% <100.00%> (-0.01%) ⬇️
Py-3.9.16 96.66% <100.00%> (+<0.01%) ⬆️
Py-pypy7.3.10 ?
Py-pypy7.3.11 94.17% <100.00%> (-0.01%) ⬇️
VM-macos 96.50% <100.00%> (+<0.01%) ⬆️
VM-ubuntu 96.93% <100.00%> (-0.01%) ⬇️
VM-windows 95.35% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@webknjaz webknjaz added backport-3.9 Trigger automatic backporting to the 3.9 release branch by Patchback robot backport-3.10 Trigger automatic backporting to the 3.10 release branch by Patchback robot labels Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-3.9 Trigger automatic backporting to the 3.9 release branch by Patchback robot backport-3.10 Trigger automatic backporting to the 3.10 release branch by Patchback robot bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

make_mocked_request() behavior is broken when no payload is specified
3 participants