From 494ad71b250e93c97cb659a235502ba5652dc62c Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Wed, 8 May 2013 19:05:15 -0700 Subject: [PATCH] Fix tests broken after refactoring editors.models. --- apps/editors/helpers.py | 2 +- apps/editors/models.py | 2 +- apps/editors/tests/test_helpers.py | 12 +++++------- apps/editors/tests/test_models.py | 25 ++++++++++++++----------- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/apps/editors/helpers.py b/apps/editors/helpers.py index bb3d3e831c..1cf0159978 100644 --- a/apps/editors/helpers.py +++ b/apps/editors/helpers.py @@ -204,7 +204,7 @@ class EditorQueueTable(SQLTable, ItemStateTable): def render_platforms(self, row): icons = [] html = u'
' - for platform in row.file_platforms: + for platform in row.file_platform_ids: icons.append(html % (amo.PLATFORMS[int(platform)].shortname, amo.PLATFORMS[int(platform)].name)) return u''.join(icons) diff --git a/apps/editors/models.py b/apps/editors/models.py index f24dcdd6b8..ab27ddb413 100644 --- a/apps/editors/models.py +++ b/apps/editors/models.py @@ -160,7 +160,7 @@ class ViewQueue(RawSQLModel): return self.premium_type in amo.ADDON_PREMIUMS @property - def file_platforms(self): + def file_platform_ids(self): return self._explode_concat(self._file_platform_ids) @property diff --git a/apps/editors/tests/test_helpers.py b/apps/editors/tests/test_helpers.py index 510807a3d4..57e8ae7691 100644 --- a/apps/editors/tests/test_helpers.py +++ b/apps/editors/tests/test_helpers.py @@ -45,7 +45,6 @@ class TestViewPendingQueueTable(amo.tests.TestCase): row.addon_name = 'フォクすけといっしょ'.decode('utf8') row.addon_slug = 'test' row.latest_version = u'0.12' - row.latest_version_id = 1234 self.table.set_page(page) a = pq(self.table.render_addon_name(row)) @@ -113,9 +112,8 @@ class TestAdditionalInfoInQueue(amo.tests.TestCase): qs = Mock() self.table = helpers.ViewPendingQueueTable(qs) self.row = Mock() - self.row.latest_version_id = 1 self.row.is_site_specific = False - self.row.file_platforms = [amo.PLATFORM_ALL.id] + self.row.file_platform_ids = [amo.PLATFORM_ALL.id] self.row.external_software = False self.row.binary = False self.row.binary_components = False @@ -128,7 +126,7 @@ class TestAdditionalInfoInQueue(amo.tests.TestCase): eq_(self.table.render_additional_info(self.row), u'Site Specific') def test_platform(self): - self.row.file_platforms = [amo.PLATFORM_LINUX.id] + self.row.file_platform_ids = [amo.PLATFORM_LINUX.id] assert "plat-sprite-linux" in self.table.render_platforms(self.row) def test_combo(self): @@ -138,12 +136,12 @@ class TestAdditionalInfoInQueue(amo.tests.TestCase): u'Site Specific, Requires External Software') def test_all_platforms(self): - self.row.file_platforms = [amo.PLATFORM_ALL.id] + self.row.file_platform_ids = [amo.PLATFORM_ALL.id] assert "plat-sprite-all" in self.table.render_platforms(self.row) def test_mixed_platforms(self): - self.row.file_platforms = [amo.PLATFORM_ALL.id, - amo.PLATFORM_LINUX.id] + self.row.file_platform_ids = [amo.PLATFORM_ALL.id, + amo.PLATFORM_LINUX.id] assert "plat-sprite-linux" in self.table.render_platforms(self.row) assert "plat-sprite-all" in self.table.render_platforms(self.row) diff --git a/apps/editors/tests/test_models.py b/apps/editors/tests/test_models.py index f2a886e156..e940af2adb 100644 --- a/apps/editors/tests/test_models.py +++ b/apps/editors/tests/test_models.py @@ -21,25 +21,29 @@ from users.models import UserProfile def create_addon_file(name, version_str, addon_status, file_status, platform=amo.PLATFORM_ALL, application=amo.FIREFOX, - admin_review=False, addon_type=amo.ADDON_EXTENSION): - app, created = Application.objects.get_or_create(id=application.id, - guid=application.guid) - app_vr, created = AppVersion.objects.get_or_create(application=app, - version='1.0') - pl, created = Platform.objects.get_or_create(id=platform.id) + admin_review=False, addon_type=amo.ADDON_EXTENSION, + created=None): + app, created_ = Application.objects.get_or_create(id=application.id, + guid=application.guid) + app_vr, created_ = AppVersion.objects.get_or_create(application=app, + version='1.0') + pl, created_ = Platform.objects.get_or_create(id=platform.id) try: ad = Addon.objects.get(name__localized_string=name) except Addon.DoesNotExist: ad = Addon.objects.create(type=addon_type, name=name) if admin_review: ad.update(admin_review=True) - vr, created = Version.objects.get_or_create(addon=ad, version=version_str) - va, created = ApplicationsVersions.objects.get_or_create( + vr, created_ = Version.objects.get_or_create(addon=ad, version=version_str) + va, created_ = ApplicationsVersions.objects.get_or_create( version=vr, application=app, min=app_vr, max=app_vr) file_ = File.objects.create(version=vr, filename=u"%s.xpi" % name, platform=pl, status=file_status) # Update status *after* there are files: Addon.objects.get(pk=ad.id).update(status=addon_status) + if created: + vr.update(created=created) + file_.update(created=created) return {'addon': ad, 'version': vr, 'file': file_} @@ -62,12 +66,11 @@ class TestQueue(amo.tests.TestCase): __test__ = False # this is an abstract test case def test_latest_version(self): - self.new_file(version=u'0.1') - self.new_file(version=u'0.2') + self.new_file(version=u'0.1', created=self.days_ago(2)) + self.new_file(version=u'0.2', created=self.days_ago(1)) latest = self.new_file(version=u'0.3') row = self.Queue.objects.get() eq_(row.latest_version, '0.3') - eq_(row.latest_version_id, latest['version'].id) def test_file_platforms(self): # Here's a dupe platform in another version: