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

[BUG] Setting body after make_case() causes request to be sent without a body #2208

Closed
3 tasks done
simonhammes opened this issue May 18, 2024 · 2 comments · Fixed by #2260
Closed
3 tasks done

[BUG] Setting body after make_case() causes request to be sent without a body #2208

simonhammes opened this issue May 18, 2024 · 2 comments · Fixed by #2260
Assignees
Labels
Status: Needs Triage Requires initial assessment to categorize and prioritize Type: Bug Errors or unexpected behavior

Comments

@simonhammes
Copy link

First off: Great library 💯


Checklist

  • I checked the FAQ section of the documentation
  • I looked for similar issues in the issue tracker
  • I am using the latest version of Schemathesis

Describe the bug

The body is not sent if it is manipulated after calling make_case(). Setting body when calling make_case() works.

Related: #1094, #1188

To Reproduce

import schemathesis
from schemathesis import Case

schema = schemathesis.from_path(
    './petstore.yaml',
    base_url='http://127.0.0.1:4010',
    validate_schema=True,
)

def test_api():
    # This does not work:
    add_pet: Case = schema.get_operation_by_id('addPet').make_case() 
    add_pet.body = {'name': 'ABC'}
    response = add_pet.call_and_validate()
    # This will print None
    print(response.request.body)

    # This works instead:
    add_pet: Case = schema.get_operation_by_id('addPet').make_case(body={'name': 'ABC'})
    response = add_pet.call_and_validate()
    # This will print the request body
    print(response.request.body)

    # Capture stdout
    assert False

🚨 Mandatory 🚨: Steps to reproduce the behavior:

  1. Download OpenAPI specification
  2. Start mock server (e.g. using Prism)
  3. pytest main.py

Please include a minimal API schema causing this issue:

https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.0/petstore.yaml

Expected behavior

The body should be sent since the media type is specified in the OpenAPI specification.

Environment

- OS: Linux
- Python version: 3.12
- Schemathesis version: 3.28.1
- Spec version: OpenAPI 3.0.0
@simonhammes simonhammes added Status: Needs Triage Requires initial assessment to categorize and prioritize Type: Bug Errors or unexpected behavior labels May 18, 2024
@Stranger6667
Copy link
Member

@simonhammes

Thank you! I've been busy with other issues, but I hope to get back to this in a week or so. Sorry for the delay.

@Stranger6667
Copy link
Member

The fix will be available in the next release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs Triage Requires initial assessment to categorize and prioritize Type: Bug Errors or unexpected behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants