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

tests: branches coverage in responses.py, staticfiles.py, templating.py, middleware/wsgi.py and endpoints.py #2804

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

Conversation

lealre
Copy link
Contributor

@lealre lealre commented Dec 16, 2024

Summary

Related to issue #2452.

responses.py - 117→124

Test with samesite = None added.

staticfiles.py - 207→212

Test with etag not matching the headers["if-none-match"].

templating.py - 46→56

It seems that TestClient adds {'http.response.debug': {}} to the scope on every HTTP request (line 310), making the statement always True.
Added pragma: no branch and needs confirmation.

middleware/wsgi.py - 124→exit

self.response_started is initialized as False in WSGIResponder and is only used in WSGIMiddleware (line 79). Removing the if statement does not affect the tests.
Added pragma: no branch and needs confirmation.

endpoints.py - 77→72

It seems there are only two possible options inside the while loop.
Added pragma: no branch and needs confirmation.

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

…ting.py`, `middleware/wsgi.py` and `endpoints.py`
@@ -43,7 +43,7 @@ def __init__(
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
request = self.context.get("request", {})
extensions = request.get("extensions", {})
if "http.response.debug" in extensions:
if "http.response.debug" in extensions: # pragma: no branch
Copy link
Member

Choose a reason for hiding this comment

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

This can be tested without the TestClient.

We have some tests that don't use the TestClient.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's right, I didn't think about it.

Added a test to the case based on other similar tests

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