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

Do not include current extension in 'Other popular extensions' #22946

Merged
merged 6 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions src/olympia/addons/tests/test_utils_.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
DeleteTokenSigner,
get_addon_recommendations,
get_addon_recommendations_invalid,
get_filtered_fallbacks,
is_outcome_recommended,
validate_version_number_is_gt_latest_signed_listed_version,
verify_mozilla_trademark,
Expand Down Expand Up @@ -103,7 +104,7 @@ def test_recommended(self, incr_mock):
def test_recommended_no_results(self, incr_mock):
self.recommendation_server_mock.return_value = []
recommendations, outcome, reason = get_addon_recommendations('a@b', True)
assert recommendations == TAAR_LITE_FALLBACKS
assert recommendations == TAAR_LITE_FALLBACKS[:4]
chrstinalin marked this conversation as resolved.
Show resolved Hide resolved
assert outcome == TAAR_LITE_OUTCOME_REAL_FAIL
assert reason is TAAR_LITE_FALLBACK_REASON_EMPTY
self.recommendation_server_mock.assert_called_with(
Expand All @@ -113,11 +114,14 @@ def test_recommended_no_results(self, incr_mock):
assert incr_mock.call_args_list[0][0] == (
f'services.addon_recommendations.{TAAR_LITE_FALLBACK_REASON_EMPTY}',
)
# Fallback filters out the current guid if it exists in TAAR_LITE_FALLBACKS
recommendations, _, _ = get_addon_recommendations(TAAR_LITE_FALLBACKS[0], True)
assert recommendations == TAAR_LITE_FALLBACKS[1:]

def test_recommended_timeout(self, incr_mock):
self.recommendation_server_mock.return_value = None
recommendations, outcome, reason = get_addon_recommendations('a@b', True)
assert recommendations == TAAR_LITE_FALLBACKS
assert recommendations == TAAR_LITE_FALLBACKS[:4]
assert outcome == TAAR_LITE_OUTCOME_REAL_FAIL
assert reason is TAAR_LITE_FALLBACK_REASON_TIMEOUT
self.recommendation_server_mock.assert_called_with(
Expand All @@ -131,18 +135,33 @@ def test_recommended_timeout(self, incr_mock):
def test_not_recommended(self, incr_mock):
recommendations, outcome, reason = get_addon_recommendations('a@b', False)
assert not self.recommendation_server_mock.called
assert recommendations == TAAR_LITE_FALLBACKS
assert recommendations == TAAR_LITE_FALLBACKS[:4]
assert outcome == TAAR_LITE_OUTCOME_CURATED
assert reason is None
assert incr_mock.call_count == 0

def test_invalid_fallback(self, incr_mock):
recommendations, outcome, reason = get_addon_recommendations_invalid()
assert not self.recommendation_server_mock.called
assert recommendations == TAAR_LITE_FALLBACKS
assert recommendations == TAAR_LITE_FALLBACKS[:4]
assert outcome == TAAR_LITE_OUTCOME_REAL_FAIL
assert reason == TAAR_LITE_FALLBACK_REASON_INVALID
assert incr_mock.call_count == 0
# Fallback filters out the current guid if it exists in TAAR_LITE_FALLBACKS
recommendations, _, _ = get_addon_recommendations_invalid(
TAAR_LITE_FALLBACKS[0]
)
assert recommendations == TAAR_LITE_FALLBACKS[1:]

def test_get_filtered_fallbacks(self, _):
# Fallback filters out the current guid if it exists in TAAR_LITE_FALLBACKS
recommendations = get_filtered_fallbacks(TAAR_LITE_FALLBACKS[2])
assert recommendations == TAAR_LITE_FALLBACKS[:2] + TAAR_LITE_FALLBACKS[3:]
# Fallback returns the first four if it does not.
recommendations, outcome, reason = get_addon_recommendations_invalid(
'random-guid'
)
assert recommendations == TAAR_LITE_FALLBACKS[:4]

def test_is_outcome_recommended(self, incr_mock):
assert is_outcome_recommended(TAAR_LITE_OUTCOME_REAL_SUCCESS)
Expand Down
12 changes: 9 additions & 3 deletions src/olympia/addons/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def _check(name):
'[email protected]', # Tree Style Tab
'[email protected]', # LanguageTool
'{2e5ff8c8-32fe-46d0-9fc8-6b8986621f3c}', # Search by Image
'simple-tab-groups@drive4ik', # Simple Tab Groups
]

TAAR_LITE_OUTCOME_REAL_SUCCESS = 'recommended'
Expand Down Expand Up @@ -90,22 +91,27 @@ def get_addon_recommendations(guid_param, taar_enable):
else:
outcome = TAAR_LITE_OUTCOME_CURATED
if not guids:
guids = TAAR_LITE_FALLBACKS
guids = get_filtered_fallbacks(guid_param)
return guids, outcome, fail_reason


def is_outcome_recommended(outcome):
return outcome == TAAR_LITE_OUTCOME_REAL_SUCCESS


def get_addon_recommendations_invalid():
def get_addon_recommendations_invalid(current_guid=None):
return (
TAAR_LITE_FALLBACKS,
get_filtered_fallbacks(current_guid),
TAAR_LITE_OUTCOME_REAL_FAIL,
TAAR_LITE_FALLBACK_REASON_INVALID,
)


def get_filtered_fallbacks(current_guid=None):
KevinMind marked this conversation as resolved.
Show resolved Hide resolved
# Filter out the current_guid from TAAR_LITE_FALLBACKS
return [guid for guid in TAAR_LITE_FALLBACKS if guid != current_guid][:4]


def compute_last_updated(addon):
"""Compute the value of last_updated for a single add-on."""
from olympia.addons.models import Addon
Expand Down
2 changes: 1 addition & 1 deletion src/olympia/addons/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ def filter_queryset(self, qs):
guids,
self.ab_outcome,
self.fallback_reason,
) = get_addon_recommendations_invalid()
) = get_addon_recommendations_invalid(guid_param)
return qs.query(query.Bool(must=[Q('terms', guid=guids)]))
return results

Expand Down
Loading