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

Rename misleading test client argument name #3661

Conversation

DoctorJohn
Copy link
Member

@DoctorJohn DoctorJohn commented Oct 7, 2024

Description

This PR renames the asserts_errors of our user-facing test clients to assert_no_errors as proposed in #3580. The old option is still available but will raise a deprecation warning.

Also, before this PR, only the Django test client had tests. Now, all test clients share the tests. (That's why this PR is a little bigger than one might expect).

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Documentation

Issues Fixed or Closed by This PR

Summary by Sourcery

Rename the asserts_errors argument to assert_no_errors in test clients for clarity, add shared tests for all clients, and document the change with a release note.

Enhancements:

  • Rename the asserts_errors argument to assert_no_errors in test clients to better reflect its purpose, while maintaining backward compatibility with a deprecation warning for the old argument.

Documentation:

  • Add a release note documenting the renaming of the asserts_errors option to assert_no_errors in test clients, highlighting the backward compatibility and deprecation warning.

Tests:

  • Add shared tests for all test clients, including AIHOTTP, ASGI, and Django, to ensure consistent behavior across different environments.
  • Introduce tests to verify the deprecation warning for the asserts_errors argument and the functionality of the assert_no_errors option.

Copy link
Contributor

sourcery-ai bot commented Oct 7, 2024

Reviewer's Guide by Sourcery

This pull request renames the asserts_errors argument to assert_no_errors in the test clients for AIOHTTP, ASGI, and Django. The change is backwards-compatible, with the old option raising a deprecation warning. The PR also adds shared tests for all test clients, improving test coverage.

Class diagram for test client argument changes

classDiagram
    class GraphQLTestClient {
        +query(query: str, variables: Optional[Dict[str, Mapping]] = None, headers: Optional[Dict[str, object]] = None, asserts_errors: Optional[bool] = None, assert_no_errors: Optional[bool] = True, files: Optional[Dict[str, object]] = None) Response
    }
    class AiohttpGraphQLTestClient {
        +query(query: str, variables: Optional[Dict[str, Mapping]] = None, headers: Optional[Dict[str, object]] = None, asserts_errors: Optional[bool] = None, assert_no_errors: Optional[bool] = True, files: Optional[Dict[str, object]] = None) Response
    }
    class AsgiGraphQLTestClient {
        +query(query: str, variables: Optional[Dict[str, Mapping]] = None, headers: Optional[Dict[str, object]] = None, asserts_errors: Optional[bool] = None, assert_no_errors: Optional[bool] = True, files: Optional[Dict[str, object]] = None) Response
    }
    class DjangoGraphQLTestClient {
        +query(query: str, variables: Optional[Dict[str, Mapping]] = None, headers: Optional[Dict[str, object]] = None, asserts_errors: Optional[bool] = None, assert_no_errors: Optional[bool] = True, files: Optional[Dict[str, object]] = None) Response
    }
    GraphQLTestClient <|-- AiohttpGraphQLTestClient
    GraphQLTestClient <|-- AsgiGraphQLTestClient
    GraphQLTestClient <|-- DjangoGraphQLTestClient
Loading

File-Level Changes

Change Details Files
Rename asserts_errors to assert_no_errors in test clients
  • Add new assert_no_errors parameter with default value True
  • Implement deprecation warning for asserts_errors
  • Update logic to use assert_no_errors while maintaining backwards compatibility
strawberry/aiohttp/test/client.py
strawberry/test/client.py
Add shared tests for all test clients
  • Create new test fixtures for AIOHTTP, ASGI, and Django clients
  • Implement parametrized tests for deprecated asserts_errors option
  • Add tests for both asserts_errors and assert_no_errors options
tests/test/conftest.py
tests/test/test_client.py
Update release information
  • Add RELEASE.md file with minor release type
  • Document the renaming of asserts_errors to assert_no_errors
RELEASE.md
Remove Django-specific test file
  • Delete tests/django/test_graphql_test_client.py
tests/django/test_graphql_test_client.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @DoctorJohn - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider updating the documentation to highlight the deprecation of the asserts_errors argument and the introduction of assert_no_errors. This will help users understand the change and encourage them to update their code.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 2 issues found
  • 🟢 Complexity: all looks good
  • 🟡 Documentation: 1 issue found

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

tests/test/test_client.py Show resolved Hide resolved
tests/test/test_client.py Show resolved Hide resolved
RELEASE.md Outdated Show resolved Hide resolved
@botberry
Copy link
Member

botberry commented Oct 7, 2024

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


The AIOHTTP, ASGI, and Django test clients' asserts_errors option has been renamed to assert_no_errors to better reflect its purpose.
This change is backwards-compatible, but the old option name will raise a deprecation warning.

Here's the tweet text:

🆕 Release (next) is out! Thanks to @NucleonJohn for the PR 👏

Get it here 👉 https://strawberry.rocks/release/(next)

@DoctorJohn DoctorJohn force-pushed the fix-misleading-name-of-the-asserts-errors-flag branch from 8c3b051 to f5c5c87 Compare October 7, 2024 02:55
Copy link

codspeed-hq bot commented Oct 7, 2024

CodSpeed Performance Report

Merging #3661 will not alter performance

Comparing DoctorJohn:fix-misleading-name-of-the-asserts-errors-flag (846a474) with main (b30f5f1)

Summary

✅ 15 untouched benchmarks

@DoctorJohn DoctorJohn force-pushed the fix-misleading-name-of-the-asserts-errors-flag branch from 3697f8f to 0e6d88d Compare October 7, 2024 03:32
@DoctorJohn DoctorJohn force-pushed the fix-misleading-name-of-the-asserts-errors-flag branch from 0e6d88d to 846a474 Compare October 7, 2024 03:40
Copy link

codecov bot commented Oct 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.93%. Comparing base (34b40d4) to head (846a474).
Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3661      +/-   ##
==========================================
+ Coverage   96.82%   96.93%   +0.11%     
==========================================
  Files         503      504       +1     
  Lines       33409    33448      +39     
  Branches     5583     5600      +17     
==========================================
+ Hits        32348    32423      +75     
+ Misses        830      793      -37     
- Partials      231      232       +1     

Copy link
Member

@patrick91 patrick91 left a comment

Choose a reason for hiding this comment

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

Nice, thanks!

Maybe we should consolidate the test clients in future (we have private ones in the tests folder :D)

@patrick91 patrick91 merged commit c25bb39 into strawberry-graphql:main Oct 7, 2024
115 of 117 checks passed
@DoctorJohn
Copy link
Member Author

Maybe we should consolidate the test clients in the future (we have private ones in the tests folder :D)

Yeah, I think that's a great idea. I didn't even know we had a public test client because it doesn't appear to be documented and did not really have tests. Our internal test client is much more capable and could be a good basis for a unified test client.

@DoctorJohn DoctorJohn deleted the fix-misleading-name-of-the-asserts-errors-flag branch November 20, 2024 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TestClient asserts_errors flag behaviour is counter intuitive
3 participants