Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
Merge branch 'ver-logging'
Browse files Browse the repository at this point in the history
  • Loading branch information
kumar303 committed Oct 6, 2011
2 parents d2e1a01 + 28c6df9 commit 5260ac5
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 10 deletions.
2 changes: 1 addition & 1 deletion apps/amo/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ class DELETE_REVIEW(_LOG):
editor_event = True


class BULK_VALIDATION_UPDATED(_LOG):
class MAX_APPVERSION_UPDATED(_LOG):
id = 46
action_class = None
format = _(u'Application max version for {version} updated.')
Expand Down
34 changes: 29 additions & 5 deletions apps/devhub/tests/test_views_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,15 @@ def test_changing_platform_search_engine(self):

class TestVersionEditCompat(TestVersionEdit):

def get_form(self, url=None):
if not url:
url = self.url
av = self.version.apps.get()
eq_(av.min.version, '2.0')
eq_(av.max.version, '3.7a1pre')
f = self.client.get(url).context['compat_form'].initial_forms[0]
return initial(f)

def formset(self, *args, **kw):
defaults = formset(prefix='files')
defaults.update(kw)
Expand All @@ -655,20 +664,33 @@ def test_add_appversion(self):
eq_(r.status_code, 302)
apps = self.get_version().compatible_apps.keys()
eq_(sorted(apps), sorted([amo.FIREFOX, amo.THUNDERBIRD]))
eq_(list(ActivityLog.objects.all().values_list('action')),
[(amo.LOG.MAX_APPVERSION_UPDATED.id,)])

def test_update_appversion(self):
av = self.version.apps.get()
eq_(av.min.version, '2.0')
eq_(av.max.version, '3.7a1pre')
f = self.client.get(self.url).context['compat_form'].initial_forms[0]
d = initial(f)
d = self.get_form()
d.update(min=self.v1.id, max=self.v4.id)
r = self.client.post(self.url,
self.formset(d, initial_count=1))
eq_(r.status_code, 302)
av = self.version.apps.get()
eq_(av.min.version, '1.0')
eq_(av.max.version, '4.0')
eq_(list(ActivityLog.objects.all().values_list('action')),
[(amo.LOG.MAX_APPVERSION_UPDATED.id,)])

def test_ajax_update_appversion(self):
url = reverse('devhub.ajax.compat.update',
args=['a3615', self.version.id])
d = self.get_form(url)
d.update(min=self.v1.id, max=self.v4.id)
r = self.client.post(url, self.formset(d, initial_count=1))
eq_(r.status_code, 200)
av = self.version.apps.get()
eq_(av.min.version, '1.0')
eq_(av.max.version, '4.0')
eq_(list(ActivityLog.objects.all().values_list('action')),
[(amo.LOG.MAX_APPVERSION_UPDATED.id,)])

def test_delete_appversion(self):
# Add thunderbird compat so we can delete firefox.
Expand All @@ -680,6 +702,8 @@ def test_delete_appversion(self):
eq_(r.status_code, 302)
apps = self.get_version().compatible_apps.keys()
eq_(apps, [amo.THUNDERBIRD])
eq_(list(ActivityLog.objects.all().values_list('action')),
[(amo.LOG.MAX_APPVERSION_UPDATED.id,)])

def test_unique_apps(self):
f = self.client.get(self.url).context['compat_form'].initial_forms[0]
Expand Down
16 changes: 16 additions & 0 deletions apps/devhub/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ def ajax_compat_update(request, addon_id, addon, version_id):
for compat in compat_form.save(commit=False):
compat.version = version
compat.save()
for form in compat_form.forms:
if (isinstance(form, forms.CompatForm) and
'max' in form.changed_data):
_log_max_version_change(addon, version, form.instance)
return jingo.render(request, 'devhub/addons/ajax_compat_update.html',
dict(addon=addon, version=version,
compat_form=compat_form))
Expand Down Expand Up @@ -1097,6 +1101,10 @@ def version_edit(request, addon_id, addon, version_id):
for compat in data['compat_form'].save(commit=False):
compat.version = version
compat.save()
for form in data['compat_form'].forms:
if (isinstance(form, forms.CompatForm) and
'max' in form.changed_data):
_log_max_version_change(addon, version, form.instance)
messages.success(request, _('Changes successfully saved.'))
return redirect('devhub.versions.edit', addon.slug, version_id)

Expand All @@ -1105,6 +1113,14 @@ def version_edit(request, addon_id, addon, version_id):
return jingo.render(request, 'devhub/versions/edit.html', data)


def _log_max_version_change(addon, version, appversion):
details = {'version': version.version,
'target': appversion.version.version,
'application': appversion.application.pk}
amo.log(amo.LOG.MAX_APPVERSION_UPDATED,
addon, version, details=details)


def _get_file_history(version):
file_ids = [f.id for f in version.all_files]
addon = version.addon
Expand Down
6 changes: 4 additions & 2 deletions apps/zadmin/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,12 @@ def notify_success(version_pks, job_pk, data, **kw):
else:
stats['author_emailed'] += 1
send_mail(*args, **kwargs)
amo.log(amo.LOG.BULK_VALIDATION_UPDATED,
app_id = job.target_version.application.pk
amo.log(amo.LOG.MAX_APPVERSION_UPDATED,
version.addon, version,
details={'version': version.version,
'target': job.target_version.version})
'target': job.target_version.version,
'application': app_id})
log.info('[%s@%s] bulk update stats for job %s: {%s}'
% (len(version_pks), notify_success.rate_limit, job_pk,
', '.join('%s: %s' % (k, stats[k])
Expand Down
4 changes: 2 additions & 2 deletions apps/zadmin/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def test_update_pks_logs(self):
self.create_result(self.job, self.create_file(self.version))
eq_(ActivityLog.objects.for_addons(self.addon).count(), 0)
self.client.post(self.update_url, self.data)
upd = amo.LOG.BULK_VALIDATION_UPDATED.id
upd = amo.LOG.MAX_APPVERSION_UPDATED.id
logs = ActivityLog.objects.for_addons(self.addon).filter(action=upd)
eq_(logs.count(), 1)
eq_(logs[0].user, get_task_user())
Expand Down Expand Up @@ -451,7 +451,7 @@ def test_notify_mail_preview(self):
eq_([e.subject for e in rs], ['the subject'])
# version should not be bumped since it's in preview mode:
eq_(self.version.apps.all()[0].max, self.max)
upd = amo.LOG.BULK_VALIDATION_UPDATED.id
upd = amo.LOG.MAX_APPVERSION_UPDATED.id
logs = ActivityLog.objects.for_addons(self.addon).filter(action=upd)
eq_(logs.count(), 0)

Expand Down

0 comments on commit 5260ac5

Please sign in to comment.