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

Add tests for ASGI specification compliance #50

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

Commits on Dec 29, 2021

  1. Add tests for ASGI specification compliance

    There are a number of tests that currently xfail in this suite.
    The intention is to fix the issues one by one, or in cases where
    the issue is a WONTFIX, change the test and/or indicate as such
    in the xfail reason.
    
    There is still a need for a couple more tests in the websocket
    section, and probably could do with some more type-oriented
    negative tests (e.g. testing what happens if you send a message
    with the wrong type in the event values, like with 'status')
    LucidDan committed Dec 29, 2021
    Configuration menu
    Copy the full SHA
    0610b93 View commit details
    Browse the repository at this point in the history
  2. Allow http.response.body event with no 'body' key

    Fixes test_http:test_response_body_can_be_missing()
    LucidDan committed Dec 29, 2021
    Configuration menu
    Copy the full SHA
    b5f4d74 View commit details
    Browse the repository at this point in the history
  3. Allow http.response.start event with no 'headers' key

    Fixes test_http:test_response_headers_can_be_missing()
    LucidDan committed Dec 29, 2021
    Configuration menu
    Copy the full SHA
    dbe96c4 View commit details
    Browse the repository at this point in the history
  4. Ensure websocket events include 'asgi' in scope

    Fixes test_websocket :
     test_asgi_version_is_present_in_websocket_scope() and
     test_websocket_spec_version_is_missing_or_correct()
    LucidDan committed Dec 29, 2021
    Configuration menu
    Copy the full SHA
    f655b85 View commit details
    Browse the repository at this point in the history
  5. Disable lifespan protocol if apps do not support it

    Fixes test_lifespan:test_lifespan_not_supported_is_allowed()
    
    This fix was somewhat challenging to achieve without breaking
    other things or backward compatibility issues.
    
    In the end, I think the most elegant solution is to adopt
    more Pythonic exceptions in the TestClient, as demonstrated in
    the commit. However, since this is a less trivial change, I
    have only used TestClientError in the lifespan related code,
     leaving all other code using raw Exceptions still.
    
    I think TestClientError (or possibly even multiple exception classes
    for different purposes) should actually be adopted throughout
    all the code, albeit with the caveat that it might cause some issues
    if anyone is doing really rigid exception assertions in their test
    code. For most cases (including my own code that is already using
    async_asgi_testclient) I believe the average
     'with pytest.raises(Exception)' assertions should still work,
     since TestClientError is a sub-class of Exception.
    
    A side-benefit of the TestClientError is it would allow access to
    the original Message structure, instead of having to decode a string
    repr of the event message.
    LucidDan committed Dec 29, 2021
    Configuration menu
    Copy the full SHA
    3ff2e15 View commit details
    Browse the repository at this point in the history
  6. Remove test for custom scope

    Removed test for contamination between calls with a custom scope.
    Probably deserves documentation because it could be a gotcha for people,
    but it doesn't deserve to be in this test suite.
    LucidDan committed Dec 29, 2021
    Configuration menu
    Copy the full SHA
    732b1e6 View commit details
    Browse the repository at this point in the history
  7. Fix formatting

    Had a few issues with formatting and the black version, this commit cleans that up.
    LucidDan committed Dec 29, 2021
    Configuration menu
    Copy the full SHA
    2037ec9 View commit details
    Browse the repository at this point in the history

Commits on Jun 2, 2023

  1. Configuration menu
    Copy the full SHA
    b6f93cd View commit details
    Browse the repository at this point in the history
  2. Notify the user if lifespan protocol raised an exception

    Re: https://github.com/vinissimus/async-asgi-testclient/pull/50/files#r785889284
    
    The asserts where we access the log message in the test is a bit rough, it could probably be refactored to be a little cleaner.
    LucidDan committed Jun 2, 2023
    Configuration menu
    Copy the full SHA
    3f79e78 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    cbb6100 View commit details
    Browse the repository at this point in the history