From 8526841a2688ef167a9efd8ba6f94ccd15c68ad5 Mon Sep 17 00:00:00 2001 From: Mathieu Pillard Date: Mon, 27 Jan 2014 12:59:20 -0800 Subject: [PATCH] Fix reindexing upsold app when upsell changes (bug 956820) --- mkt/webapps/models.py | 4 ++-- mkt/webapps/tests/test_utils_.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/mkt/webapps/models.py b/mkt/webapps/models.py index 9b03b730f1..04f5857552 100644 --- a/mkt/webapps/models.py +++ b/mkt/webapps/models.py @@ -1790,8 +1790,8 @@ Webapp._meta.translated_fields = [ def update_search_index(sender, instance, **kw): from . import tasks if not kw.get('raw'): - if instance.upsold: - tasks.index_webapps.delay([instance.upsold.id]) + if instance.upsold and instance.upsold.free_id: + tasks.index_webapps.delay([instance.upsold.free_id]) tasks.index_webapps.delay([instance.id]) diff --git a/mkt/webapps/tests/test_utils_.py b/mkt/webapps/tests/test_utils_.py index 9235a0d31f..48c4d49d63 100644 --- a/mkt/webapps/tests/test_utils_.py +++ b/mkt/webapps/tests/test_utils_.py @@ -716,6 +716,27 @@ class TestESAppToDict(amo.tests.ESTestCase): res = self.serialize() eq_(res['upsell'], False) + def test_upsell_is_made_public_later(self): + upsell = amo.tests.app_factory(status=amo.STATUS_PENDING) + self.make_premium(upsell) + self.app._upsell_from.create(premium=upsell) + + # Don't use .reload() because it doesn't reset cached_property. + upsell = Webapp.objects.get(pk=upsell.pk) + upsell.update(status=amo.STATUS_PUBLIC) + + # Note that we shouldn't have to call self.app.save(), because saving + # the upsell should have triggered the reindex of self.app. + self.refresh('webapp') + + res = self.serialize() + eq_(res['upsell']['id'], upsell.id) + eq_(res['upsell']['app_slug'], upsell.app_slug) + eq_(res['upsell']['name'], upsell.name) + eq_(res['upsell']['icon_url'], upsell.get_icon_url(128)) + self.assertApiUrlEqual(res['upsell']['resource_uri'], + '/apps/app/%s/' % upsell.id) + def test_upsell_excluded_from_region(self): upsell = amo.tests.app_factory() upsell.addonexcludedregion.create(region=mkt.regions.US.id)