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

Ability to pass parameters directly #8

Closed
Stranger6667 opened this issue Aug 24, 2019 · 0 comments · Fixed by #1965
Closed

Ability to pass parameters directly #8

Stranger6667 opened this issue Aug 24, 2019 · 0 comments · Fixed by #1965
Assignees
Labels
Component: Hooks Extensibility and customization Difficulty: Intermediate Requires some experience Type: Feature New functionalities or enhancements

Comments

@Stranger6667
Copy link
Member

Stranger6667 commented Aug 24, 2019

When testing some endpoint that implies having some id in the path or any other part:

/api/items/{item_id}

It will be helpful to put real item_id into parameters if it is known before the test:

@schema.parametrize(path_parameters={"item_id": 42})
def test_items(case):
    case.path_parameters  # {"item_id": 42}

Under the hood, these parameters could be passed as st.just into the case strategy, be available in the case fixture.

Goals:

  • Improve the usefulness of generated test cases. Some endpoints require pre-defined parameters to work (otherwise it could be almost always 404 or similar);
  • Improve performance, since just is faster than from_schema (though in some cases it could be slower)

Alternative - all parameters are named (kinda, since requestBody is a separate one), we can pass the something like this to parametrize:

@schema.parametrize(overrides={"item_id": st.just(42)})
def test_items(case):
    ...

In this case, the data generation is more flexible - we can generate whatever we need with Hypothesis strategies

Implementation notes:

  • Check if the parameter name is valid and exists in the schema
  • During Open API -> JSON Schema translation do not include parameters, that are in the "overrides" dictionary
  • Create a dynamic st.composite strategy that draws from the reduced schema first and then draws from the provided strategies.
@Stranger6667 Stranger6667 added Priority: Medium Planned for regular releases Type: Feature New functionalities or enhancements Priority: Low Cosmetic or low-impact changes and removed enhancement Priority: Medium Planned for regular releases labels Oct 2, 2019
@Stranger6667 Stranger6667 added Priority: Medium Planned for regular releases and removed Priority: Low Cosmetic or low-impact changes labels Oct 21, 2019
@Stranger6667 Stranger6667 added Difficulty: Intermediate Requires some experience Priority: High Important but not urgent and removed Priority: Medium Planned for regular releases labels Sep 28, 2020
@Stranger6667 Stranger6667 added this to the 2.7 milestone Oct 6, 2020
@Stranger6667 Stranger6667 removed this from the 2.7 milestone Oct 20, 2020
@Stranger6667 Stranger6667 added Component: Hooks Extensibility and customization and removed Priority: High Important but not urgent labels Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Hooks Extensibility and customization Difficulty: Intermediate Requires some experience Type: Feature New functionalities or enhancements
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants