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 a test for HTTPUnauthorized with a Unicode string body argument #5731

Merged
merged 3 commits into from
Jun 7, 2021

Conversation

paulefoe
Copy link
Member

@paulefoe paulefoe commented May 24, 2021

What do these changes do?

Allows previous behavior when constructing HTTPUnauthorized with a body argument as a string

Are there changes in behavior for the user?

Users are now able to send HTTPUnauthorized response with a string

#5657

This commit fixes #5657

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."

@paulefoe paulefoe requested a review from asvetlov as a code owner May 24, 2021 03:02
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label May 24, 2021
@paulefoe paulefoe requested a review from webknjaz May 24, 2021 03:02
@paulefoe
Copy link
Member Author

I'm not sure how to fix mypy here, should I move value property to StringPayload and say that it returns str?

@@ -697,6 +697,8 @@ def body(
def text(self) -> Optional[str]:
if self._body is None:
return None
if isinstance(self._body, Payload):
Copy link
Member

Choose a reason for hiding this comment

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

Could you explain this bit? I expected the fix to be in the exception initializer.

@paulefoe
Copy link
Member Author

Now that I look at it, I think that the test is wrong and everything works correctly on 3.8.

The reason is, on master, the response from HTTPUnauthorized uses exc.text which I tested here, but in 3.8 it's not used, the response forms without using the text property of exception.

I'll look tomorrow if the test can be rewritten or should be deleted entirely.

@paulefoe
Copy link
Member Author

I think I should remove the last line for the test, where it access text test just the initialization and status, or maybe just the initialization.

def test_unicode_text_body_unauthorized() -> None:
    """
    Test that HTTPUnauthorized can be initialized with a string.
    """
    with pytest.warns(
        DeprecationWarning, match="body argument is deprecated for http web exceptions"
    ):
        resp = web.HTTPUnauthorized(body="text")
    assert resp.status == 401

@paulefoe paulefoe requested a review from webknjaz June 7, 2021 02:33
@webknjaz webknjaz changed the title Fixed constructing HTTPUnauthorized with a body argument that is a Unicode string after regression. Fix a test for HTTPUnauthorized with a Unicode string body argument Jun 7, 2021
@webknjaz webknjaz merged commit 6ba6ecd into aio-libs:3.8 Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

2 participants