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

[FEATURE] Filters for hooks #1852

Open
Stranger6667 opened this issue Oct 18, 2023 · 0 comments
Open

[FEATURE] Filters for hooks #1852

Stranger6667 opened this issue Oct 18, 2023 · 0 comments
Assignees
Labels
Component: Hooks Extensibility and customization Difficulty: Intermediate Requires some experience Priority: Medium Planned for regular releases Type: Feature New functionalities or enhancements UX: Usability Enhances user experience

Comments

@Stranger6667
Copy link
Member

Continuation of #1673

Extend the hook system to allow users to specify the scope of hook functions through a decorator instead of implementing conditions inside the hook function body. This would simplify the filtering process and make it easier to use.

# Filter via custom function
def select_operations(context):
    # Or any complex logic here
    return context.operation.method == "PATCH" and context.operation.path == "/users/{user_id}/"
    

# Apply hook only if `select_operations` returned `True`
@schemathesis.hook.apply_to(select_operations)
def filter_query(context, query):
    return query["key"] != "42"


# Apply hook to everything except `GET /users/{user_id}/`
@schemathesis.hook.skip_for(method="GET", path="/users/{user_id}/")
def map_path_parameters(context, path_parameters):
    path_parameters["user_id"] = 42
    return path_parameters


# Simple filter hook for all operations
@schemathesis.hook
def filter_query(context, query):
    return query["key"] != "42"
@Stranger6667 Stranger6667 added Priority: Medium Planned for regular releases Type: Feature New functionalities or enhancements Difficulty: Intermediate Requires some experience UX: Usability Enhances user experience Component: Hooks Extensibility and customization labels Oct 18, 2023
@Stranger6667 Stranger6667 self-assigned this Oct 18, 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 Priority: Medium Planned for regular releases Type: Feature New functionalities or enhancements UX: Usability Enhances user experience
Projects
None yet
Development

No branches or pull requests

1 participant