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

[uss_qualifier/scenarios/utm/data_exchange_validation] Refactor filtering of mock_uss_interactions #831

Merged
merged 1 commit into from
Nov 12, 2024

Conversation

mickmis
Copy link
Contributor

@mickmis mickmis commented Oct 30, 2024

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.

  • Usage of parameters op_id and query_params is replaced by filter function operation_filter
  • Usage of parameter direction is replaced by filter function direction_filter
  • is_op_intent_notification_with_id is renamed into notif_op_intent_id_filter
  • _is_notification_sent_to_url_with_op_intent_id is replaced by new base_url_filter combined with existing notif_op_intent_id_filter

Copy link
Contributor

@Shastick Shastick left a 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.

Comment on lines 187 to 207
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
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated doc to clarify.

Copy link
Member

@BenjaminPelletier BenjaminPelletier left a 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 :)

@mickmis mickmis merged commit eeac880 into interuss:main Nov 12, 2024
20 checks passed
@mickmis mickmis deleted the 797/interactions branch November 12, 2024 13:01
github-actions bot added a commit that referenced this pull request Nov 12, 2024
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.

3 participants