Skip to content

Commit 676c8f1

Browse files
committed
update theme check to return correct version (bug 880490)
1 parent 0e635df commit 676c8f1

File tree

5 files changed

+31
-11
lines changed

5 files changed

+31
-11
lines changed

apps/addons/models.py

+7
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,13 @@ def compatible_version(self, app_id, app_version=None, platform=None,
796796

797797
return version
798798

799+
def increment_version(self):
800+
"""Increment version number by 1."""
801+
version = self.latest_version or self.current_version
802+
version.version = str(float(version.version) + 1)
803+
# Set the current version.
804+
self.update(_current_version=version.save())
805+
799806
def invalidate_d2c_versions(self):
800807
"""Invalidates the cache of compatible versions.
801808

apps/addons/tests/test_theme_update.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import amo.tests
1313
from addons.models import Addon
14+
from versions.models import Version
1415
from services import theme_update
1516

1617

@@ -79,7 +80,7 @@ def setUp(self):
7980
'author': 'persona_author',
8081
'updateURL': (settings.VAMO_URL +
8182
'/en-US/themes/update-check/15663'),
82-
'version': '1.1',
83+
'version': '0',
8384
'footerURL': '/15663/BCBG_Persona_footer2.png'
8485
}
8586

@@ -118,7 +119,9 @@ def test_get_json_good_ids(self):
118119

119120
self.addon = Addon.objects.get()
120121
self.addon.summary = 'yolo'
122+
self.addon.current_version = Version.objects.get()
121123
self.addon.save()
124+
self.addon.increment_version()
122125

123126
# Testing `addon_id` from AMO.
124127
self.check_good(
@@ -128,7 +131,8 @@ def test_get_json_good_ids(self):
128131
self.good.update({
129132
'id': '813',
130133
'updateURL': (settings.VAMO_URL +
131-
'/en-US/themes/update-check/813?src=gp')
134+
'/en-US/themes/update-check/813?src=gp'),
135+
'version': '1'
132136
})
133137

134138
self.check_good(

mkt/reviewers/tasks.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ def send_mail(cleaned_data, theme_lock):
3838
if action == rvw.ACTION_APPROVE:
3939
subject = _('Thanks for submitting your Theme')
4040
template = 'reviewers/themes/emails/approve.html'
41-
theme.addon.update(status=amo.STATUS_PUBLIC)
4241

4342
elif action == rvw.ACTION_REJECT:
4443
subject = _('A problem with your Theme submission')
@@ -87,6 +86,8 @@ def approve_rereview(theme):
8786
set_modified_on=[reupload.theme.addon])
8887
rereview.delete()
8988

89+
theme.addon.increment_version()
90+
9091

9192
@task
9293
def reject_rereview(theme):

mkt/reviewers/tests/test_views_themes.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,15 @@ def test_basic_queue(self):
108108
len(expected))
109109

110110
@mock.patch.object(settings, 'LOCAL_MIRROR_URL', '')
111+
@mock.patch('addons.tasks.version_changed')
111112
@mock.patch('mkt.reviewers.tasks.send_mail_jinja')
112113
@mock.patch('mkt.reviewers.tasks.create_persona_preview_images')
113114
@mock.patch('amo.storage_utils.copy_stored_file')
114115
def test_commit(self, copy_file_mock, create_preview_mock,
115-
send_mail_jinja_mock):
116+
send_mail_jinja_mock, version_changed_mock):
116117
if self.flagged:
117118
return
119+
118120
themes = []
119121
for x in range(5):
120122
themes.append(self.theme_factory().persona)
@@ -143,6 +145,8 @@ def test_commit(self, copy_file_mock, create_preview_mock,
143145
form_data['form-%s-comment' % index] = comment
144146
form_data['form-%s-reject_reason' % index] = reject_reason
145147

148+
old_version = themes[4].addon.current_version.version
149+
146150
# Commit.
147151
res = self.client.post(reverse('reviewers.themes.commit'), form_data)
148152
self.assert3xx(res, reverse('reviewers.themes.queue_themes'))
@@ -168,12 +172,16 @@ def test_commit(self, copy_file_mock, create_preview_mock,
168172
# leaving only 2 RQT objects. Can't flag a rereview theme yet, and
169173
# moreinfo does nothing but email the artist.
170174
eq_(RereviewQueueTheme.objects.count(), 2)
175+
176+
# Test version incremented.
177+
eq_(themes[4].addon.reload().current_version.version,
178+
str(float(old_version) + 1))
171179
else:
172180
eq_(themes[0].addon.status, amo.STATUS_REVIEW_PENDING)
173181
eq_(themes[1].addon.status, amo.STATUS_REVIEW_PENDING)
174182
eq_(themes[2].addon.status, amo.STATUS_REJECTED)
175183
eq_(themes[3].addon.status, amo.STATUS_REJECTED)
176-
eq_(themes[4].addon.status, amo.STATUS_PUBLIC)
184+
eq_(themes[4].addon.reload().status, amo.STATUS_PUBLIC)
177185
eq_(ActivityLog.objects.count(), 4 if self.rereview else 5)
178186

179187
expected_calls = [

services/theme_update.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,15 @@ def get_update(self):
7575
"""
7676

7777
sql = """
78-
SELECT p.persona_id, a.id, a.slug,
78+
SELECT p.persona_id, a.id, a.slug, v.version,
7979
t_name.localized_string AS name,
8080
t_desc.localized_string AS description,
8181
p.display_username, p.header,
8282
p.footer, p.accentcolor, p.textcolor,
8383
UNIX_TIMESTAMP(a.modified) AS modified
8484
FROM addons AS a
8585
LEFT JOIN personas AS p ON p.addon_id=a.id
86+
LEFT JOIN versions AS v ON a.current_version=v.id
8687
LEFT JOIN translations AS t_name
8788
ON t_name.id=a.name AND t_name.locale=%(locale)s
8889
LEFT JOIN translations AS t_desc
@@ -95,9 +96,9 @@ def get_update(self):
9596
row = self.cursor.fetchone()
9697

9798
row_to_dict = lambda row: dict(zip((
98-
'persona_id', 'addon_id', 'slug', 'name', 'description',
99-
'username', 'header', 'footer', 'accentcolor', 'textcolor',
100-
'modified'),
99+
'persona_id', 'addon_id', 'slug', 'current_version', 'name',
100+
'description', 'username', 'header', 'footer', 'accentcolor',
101+
'textcolor', 'modified'),
101102
list(row)))
102103

103104
if row:
@@ -147,9 +148,8 @@ def get_json(self):
147148
'textcolor': '#%s' % text if text else None,
148149
'updateURL': self.locale_url(settings.VAMO_URL,
149150
'/themes/update-check/' + id_),
150-
# TODO: Change this when we add versions (bug 851881).
151151
# 04-25-2013: Bumped for GP migration so we get new `updateURL`s.
152-
'version': '1.1'
152+
'version': row.get('current_version', 0)
153153
}
154154

155155
# If this theme was originally installed from getpersonas.com,

0 commit comments

Comments
 (0)