-
Notifications
You must be signed in to change notification settings - Fork 3
Add custom label for percolate query subscriptions #1610
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
Add custom label for percolate query subscriptions #1610
Conversation
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.
Works great! Made a suggestion for improving the new test. I thought of a few minor nitpicks that might be nice-to-haves but aren't critical and aren't mentioned in the issue:
Prepopulatedisplay_labelfor existing channel-based percolate queries (tochannel.title)?When new percolate queries for channels are created, maybe assign the channel title as the initial display_label value
nvm about the above two, channel title might change- Might be nice to add
display_labeltoPercolateQueryAdminso they can be seen/searched in django admin:
Also left some other inline code comments, but those are probably out of the scope of this PR. Just the test change should be enough for approval.
| "certification": None, | ||
| "yearly_decay_percent": None, | ||
| } | ||
| test_label = "new courses about cats" |
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.
source_description doesn't seem to be getting tested here, suggest doing something like this:
@pytest.mark.django_db
@pytest.mark.parametrize("test_label", ["new courses about cats", ""])
@pytest.mark.parametrize("is_channel_query", [True, False])
def test_percolate_query_display_labels(
mocker, mocked_es, test_label, is_channel_query
):
"""
Test that makes sure we display the display label for a percolate query if it is defined
"""
mocker.patch(
"learning_resources_search.indexing_api.index_percolators", autospec=True
)
mocker.patch(
"learning_resources_search.indexing_api._update_document_by_id", autospec=True
)
channel = ChannelFactory.create(
search_filter="department=physics", channel_type="department"
)
original_query = {"department": ["physics"]} if is_channel_query else {
"q": "testing search filter",
"certification": None,
"yearly_decay_percent": None,
}
query = PercolateQueryFactory.create(
original_query=original_query,
query=original_query,
display_label=test_label,
)
assert query.source_description() == (
test_label
if test_label
else channel.title
if is_channel_query
else query.original_url_params()
)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.
fixed test
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.
Delete this line, it is overriding the parameterized value:
test_label = "new courses about cats"Also:
original_query = {"department": ["physics"]} if is_channel_query else {
"q": "testing search filter",
"certification": None,
"yearly_decay_percent": None,
}| return self.display_label | ||
| if channel: | ||
| return channel.title | ||
| return self.original_url_params() |
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.
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.
One thing I found a bit counterintuitive but is outside the scope of this PR: the source_description is used as the title in this list while source_label is shown underneath that. I would expect the opposite.
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.
working on another pr for sending the emails I can see about changing this there.
| return "saved_search" | ||
|
|
||
| def source_description(self): | ||
| channel = self.source_channel() |
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.
Outside of this scope's PR changes, but should this function also take the source_type into consideration?
def source_channel(self):
original_query_params = self.original_url_params()
channels_filtered = Channel.objects.filter(search_filter=original_query_params)
if channels_filtered.exists() and self.source_type == CHANNEL_SUBSCRIPTION_TYPE:
return channels_filtered.first()
return NoneThere 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.
potentially. - im currently working on another PR that involves sending actual emails for percolated searches so this might change there
mbertrand
left a comment
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.
👍
* adding display label and migration to percolate queries * regenerating specs * adding test and method for returning label * fixing migration * adding display label to admin * adding test for source description * fixing search conditionals in test


What are the relevant tickets?
Closes https://github.com/mitodl/hq/issues/5598
Description (What does it do?)
This PR adds a "display label" field to percolate queries which overrides any other label for display on the frontend
Screenshots (if appropriate):
How can this be tested?