-
Notifications
You must be signed in to change notification settings - Fork 19
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
[uss_qualifier/scenarios/utm/data_exchange_validation] Refactor filtering of mock_uss_interactions #831
Conversation
979a813
to
8085fe3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, modulo a little improvement on doc or naming for one of the filter.
def operation_filter( | ||
op_id: OperationID, | ||
**query_params: str, | ||
) -> Callable[[Interaction], bool]: | ||
""" | ||
Returns an `is_applicable` filter that filters according to operation ID. | ||
|
||
Raises: | ||
KeyError: if query_params contains a non-existing parameter | ||
IndexError: if query_params is missing a parameter | ||
""" | ||
op = api.OPERATIONS[op_id] | ||
op_path = op.path.format(**query_params) # raises KeyError, IndexError | ||
|
||
def is_applicable(interaction: Interaction) -> bool: | ||
return interaction.query.request.method == op.verb and re.search( | ||
op_path, interaction.query.request.url | ||
) | ||
|
||
return is_applicable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation and/or name of this method could be improved: at first glance it looks like it might allow one to return "all queries for this operation ID regardless of parameters, and you can optionally specify parameters to narrow it down". The docstring 'Raises' part does hint at the fact that this is incorrect, but is a bit obscure.
(Ie, the passed query_params MUST be all the parameters required for the passed operation ID)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated doc to clarify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Elegant, I like it :)
…ring of mock_uss_interactions
8085fe3
to
6c69eb3
Compare
Issue #797
Stack on top of #829, please consider only last commit.
This refactors the way
mock_uss_interactions
filters interactions by generalizing the filtering by functions that already existed. On top of simplifying the logic, this enables invoking that function without any filters, which we will need in an upcoming PR.op_id
andquery_params
is replaced by filter functionoperation_filter
direction
is replaced by filter functiondirection_filter
is_op_intent_notification_with_id
is renamed intonotif_op_intent_id_filter
_is_notification_sent_to_url_with_op_intent_id
is replaced by newbase_url_filter
combined with existingnotif_op_intent_id_filter