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

feat(testing): add msgpack support #2394

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

arthurprioli
Copy link

@arthurprioli arthurprioli commented Oct 28, 2024

Summary of Changes

Added the msgpack parameter in simulate_request, working in a similar way than the JSON one, when msgpack is not None we pass the content type as MEDIA_MSGPACK and it is fully documented on the comments and documentation.

Related Issues

Fixes #1026.
Relates to #333.

Pull Request Checklist

This is just a reminder about the most common mistakes. Please make sure that you tick all appropriate boxes. But please read our contribution guide at least once; it will save you a few review cycles!

If an item doesn't apply to your pull request, check it anyway to make it apparent that there's nothing to do.

  • Applied changes to both WSGI and ASGI code paths and interfaces (where applicable).
  • Added tests for changed code.
    Couldn't find out where to place coverage tests for request_simulation and how to test msgpack parameter.
  • Prefixed code comments with GitHub nick and an appropriate prefix.
    Didn't understand where to put the prefix with my GitHub nick.
  • Coding style is consistent with the rest of the framework.
  • Updated documentation for changed code.
    • Added docstrings for any new classes, functions, or modules.
    • Updated docstrings for any modifications to existing code.
    • Updated both WSGI and ASGI docs (where applicable).
    • Added references to new classes, functions, or modules to the relevant RST file under docs/.
    • Updated all relevant supporting documentation files under docs/.
    • A copyright notice is included at the top of any new modules (using your own name or the name of your organization).
    • [ ] Changed/added classes/methods/functions have appropriate versionadded, versionchanged, or deprecated directives.
      Didn't understand where to put the versionchanged prefix and if I should put it.
  • Changes (and possible deprecations) have towncrier news fragments under docs/_newsfragments/, with the file name format {issue_number}.{fragment_type}.rst. (Run towncrier --draft to ensure it renders correctly.)

If you have any questions to any of the points above, just submit and ask! This checklist is here to help you, not to deter you from contributing!

PR template inspired by the attrs project.

@arthurprioli arthurprioli marked this pull request as draft October 29, 2024 12:54
Copy link

codecov bot commented Oct 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.92%. Comparing base (66eb886) to head (f226b5b).

Additional details and impacted files
@@             Coverage Diff             @@
##            master    #2394      +/-   ##
===========================================
- Coverage   100.00%   99.92%   -0.08%     
===========================================
  Files           64       64              
  Lines         7726     7732       +6     
  Branches      1071     1072       +1     
===========================================
  Hits          7726     7726              
- Misses           0        5       +5     
- Partials         0        1       +1     

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


🚨 Try these New Features:

Copy link
Member

@CaselIT CaselIT left a comment

Choose a reason for hiding this comment

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

looks mostly fine, thanks!

The only comment that needs to be solved is the docstirng one

falcon/testing/client.py Outdated Show resolved Hide resolved
tests/test_testing.py Show resolved Hide resolved
@arthurprioli arthurprioli requested a review from CaselIT October 30, 2024 20:27
@vytas7 vytas7 changed the title 1026 add messsagepack support feat(testing): add msgpack support Nov 4, 2024
@arthurprioli arthurprioli marked this pull request as ready for review November 10, 2024 12:17
.. towncrier release notes start


Misc
Copy link
Member

Choose a reason for hiding this comment

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

Please do not render out newsfragments yourself; a Falcon release manager does that when the time comes.
Moreover, this fragment looks stale, it is already release as part of Falcon 4.0.2.

@vytas7 vytas7 marked this pull request as draft November 10, 2024 19:19
@vytas7 vytas7 marked this pull request as ready for review November 10, 2024 19:19
@vytas7 vytas7 marked this pull request as draft November 10, 2024 19:19
Copy link
Member

@vytas7 vytas7 left a comment

Choose a reason for hiding this comment

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

Hi again, and thanks for this pull request!
I think it is a great start, but it still needs work to bring it out from Draft (that I've just converted it to), and later to merge it.

(See the inline comments.)

falcon/testing/client.py Outdated Show resolved Hide resolved
Copy link
Member

@vytas7 vytas7 Nov 10, 2024

Choose a reason for hiding this comment

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

We need more extensive tests for this new feature.
You have a couple of test cases there, but we should also check whether the simulated body is correct, not just the content type.

I would suggest to use pytest.mark.parametrize(...) to create multiple test cases from different test data, but the same test code.

We also want to test the combination of msgpack= together with other parameters such as json=, etc, in order to verify that the documented precedence order is correct.

Copy link
Author

Choose a reason for hiding this comment

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

I have a doubt about that, with json we pass parameters (json), (json, headers), (json,content-type), (json, headers, content-type), I did similar tests with both msgpack and json with msgpack, but mintests still breaks. What's the best way to parametrize it? And how do I check if simulated body is correct?

Copy link
Member

Choose a reason for hiding this comment

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

Newsfragment file missing. You don't need to manually include it in 4.1.0.rst, but rather create a separate newsfragment file. Please check our docs how to contribute these files.

falcon/testing/client.py Show resolved Hide resolved
Copy link
Member

@vytas7 vytas7 Nov 10, 2024

Choose a reason for hiding this comment

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

We also need to add/adapt tests checking what happens when msgpack is not installed.
Judging from the tox -e mintest output, this case is not always handled as expected in the proposed changeset, at least not in the tests.

Copy link
Author

Choose a reason for hiding this comment

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

How would I do that? Would it be with a try, except statement while importing msgpack? Or is there a better way for testing it?

Copy link
Member

Choose a reason for hiding this comment

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

Please check other existing tests, e.g., tests/test_media_multipart.py, or many others.

You can reuse the following pattern:

# Somewhere in the beginning of the file, towards the end of the import blocks:
try:
    import msgpack
except ImportError:
    msgpack = None

Then, later, shield your tests in question with the pytest.mark.skipif(...) decorator, e.g.:

@pytest.mark.skipif(msgpack is None, reason='msgpack is required for this test')
def test_my_new_msgpack_parameter(some_param, ...):
    ...

@@ -14,9 +14,21 @@ on GitHub.

.. NOTE(vytas): No changes to the supported platforms (yet).


Copy link
Member

Choose a reason for hiding this comment

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

A diff still remains in this file against master. Please revert all your changes to this release template.

Copy link
Member

Choose a reason for hiding this comment

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

Please check other existing tests, e.g., tests/test_media_multipart.py, or many others.

You can reuse the following pattern:

# Somewhere in the beginning of the file, towards the end of the import blocks:
try:
    import msgpack
except ImportError:
    msgpack = None

Then, later, shield your tests in question with the pytest.mark.skipif(...) decorator, e.g.:

@pytest.mark.skipif(msgpack is None, reason='msgpack is required for this test')
def test_my_new_msgpack_parameter(some_param, ...):
    ...

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.

Add MessagePack support to the test client
3 participants