test for deleted files and cope with unicode (bug 608853)

This commit is contained in:
Andy McKay 2010-11-02 10:45:45 -07:00
Родитель a2ebf037dc
Коммит effab025eb
4 изменённых файлов: 53 добавлений и 38 удалений

Просмотреть файл

@ -10,28 +10,28 @@ _LOG = namedtuple('LOG', 'id format')
class CREATE_ADDON:
id = 1
format = _('{user.name} created addon {addon.name}')
format = _(u'{user.name} created addon {addon.name}')
keep = True
class EDIT_PROPERTIES:
id = 2
format = _('{user.name} edited addon {addon.name} properties')
format = _(u'{user.name} edited addon {addon.name} properties')
class EDIT_DESCRIPTIONS:
id = 3
format = _('{user.name} edited addon {addon.name} description')
format = _(u'{user.name} edited addon {addon.name} description')
class EDIT_CATEGORIES:
id = 4
format = _('{user.name} edited categories for {addon.name}')
format = _(u'{user.name} edited categories for {addon.name}')
class ADD_USER_WITH_ROLE:
id = 5
format = _('{user.name} added {0.name} to '
format = _(u'{user.name} added {0.name} to '
'addon {addon.name} with role {1}')
keep = True
@ -39,113 +39,118 @@ class ADD_USER_WITH_ROLE:
class REMOVE_USER_WITH_ROLE:
id = 6
# L10n: {0} is the user being removed, {1} is their role.
format = _('{user.name} removed {0} with role {1}')
format = _(u'{user.name} removed {0} with role {1}')
keep = True
class EDIT_CONTRIBUTIONS:
id = 7
format = _('{user.name} edited contributions for {addon.name}')
format = _(u'{user.name} edited contributions for {addon.name}')
class SET_INACTIVE:
id = 8
format = _('{user.name} set addon {addon.name} inactive')
format = _(u'{user.name} set addon {addon.name} inactive')
keep = True
class UNSET_INACTIVE:
id = 9
format = _('{user.name} activated addon {addon.name}')
format = _(u'{user.name} activated addon {addon.name}')
keep = True
class SET_PUBLIC_STATS:
id = 10
format = _('{user.name} set stats public for {addon}')
format = _(u'{user.name} set stats public for {addon}')
keep = True
class UNSET_PUBLIC_STATS:
id = 11
format = _('{user.name} set stats private for {addon}')
format = _(u'{user.name} set stats private for {addon}')
keep = True
class CHANGE_STATUS:
id = 12
# L10n: {0} is the status
format = _('{user.name} changed {addon} status to {0}')
format = _(u'{user.name} changed {addon} status to {0}')
keep = True
class ADD_PREVIEW:
id = 13
format = _('{user.name} added preview to {addon}')
format = _(u'{user.name} added preview to {addon}')
class EDIT_PREVIEW:
id = 14
format = _('{user.name} edited preview for {addon}')
format = _(u'{user.name} edited preview for {addon}')
class DELETE_PREVIEW:
id = 15
format = _('{user.name} deleted preview from {addon}')
format = _(u'{user.name} deleted preview from {addon}')
class ADD_VERSION:
id = 16
format = _('{user.name} added version {0.version} to {addon}')
format = _(u'{user.name} added version {0.version} to {addon}')
keep = True
class EDIT_VERSION:
id = 17
format = _('{user.name} edited version {0.version} of {addon}')
format = _(u'{user.name} edited version {0.version} of {addon}')
class DELETE_VERSION:
id = 18
format = _('{user.name} deleted version {0.version} from {addon}')
format = _(u'{user.name} deleted version {0.version} from {addon}')
keep = True
class ADD_FILE_TO_VERSION:
id = 19
format = _('{user.name} added file {0.name} to '
format = _(u'{user.name} added file {0.name} to '
'version {0.version} of {addon}')
class DELETE_FILE_FROM_VERSION:
""" Expecting: addon, filename, version
Because the file is being deleted, filename and version
should be strings and not the object.
"""
id = 20
format = _('{user.name} deleted file {0.name} '
'from {addon} version {0.version}')
format = _(u'{user.name} deleted file {0} '
'from {addon} version {1}')
class APPROVE_VERSION:
id = 21
format = _('Version {0.version} of {addon} approved')
format = _(u'Version {0.version} of {addon} approved')
keep = True
class RETAIN_VERSION:
id = 22
format = _('{user.name} retained version {0.version} of {addon}')
format = _(u'{user.name} retained version {0.version} of {addon}')
keep = True
class ESCALATE_VERSION:
id = 23
# L10n: {0.version} is the version of an addon.
format = _('{user.name} escalated review of {addon} {0.version}')
format = _(u'{user.name} escalated review of {addon} {0.version}')
keep = True
class REQUEST_VERSION:
id = 24
# L10n: {0.version} is the version of an addon.
format = _('{user.name} requested more information regarding '
format = _(u'{user.name} requested more information regarding '
'{addon} {0.version}')
keep = True
@ -153,51 +158,51 @@ class REQUEST_VERSION:
class ADD_TAG:
id = 25
# L10n: {0} is the tag name.
format = _('{user.name} added tag {0} to {addon}')
format = _(u'{user.name} added tag {0} to {addon}')
class REMOVE_TAG:
id = 26
# L10n: {0} is the tag name.
format = _('{user.name} removed tag {0} from {addon}')
format = _(u'{user.name} removed tag {0} from {addon}')
class ADD_TO_COLLECTION:
id = 27
format = _('{user.name} added addon {addon} to a collection {0.name}')
format = _(u'{user.name} added addon {addon} to a collection {0.name}')
class REMOVE_FROM_COLLECTION:
id = 28
forma = _('{user.name} removed addon {addon} from a collection {0.name}')
forma = _(u'{user.name} removed addon {addon} from a collection {0.name}')
class ADD_REVIEW:
id = 29
format = _('{user.name} wrote a review about {addon}')
format = _(u'{user.name} wrote a review about {addon}')
class ADD_RECOMMENDED_CATEGORY:
id = 31
# L10n: {0} is a category name.
format = _('{addon} featured in {0}')
format = _(u'{addon} featured in {0}')
class REMOVE_RECOMMENDED_CATEGORY:
id = 32
# L10n: {0} is a category name.
format = _('{addon} no longer featured in {0}')
format = _(u'{addon} no longer featured in {0}')
class ADD_RECOMMENDED:
id = 33
format = _('{addon} is now featured')
format = _(u'{addon} is now featured')
keep = True
class REMOVE_RECOMMENDED:
id = 34
format = _('{addon} is no longer featured')
format = _(u'{addon} is no longer featured')
keep = True
@ -205,7 +210,7 @@ class ADD_APPVERSION:
id = 35
# L10n: {0} is the application, {1.min/max} is the min/max version of the
# app
format = _('addon now supports {0} {1.min}-{1.max}')
format = _(u'addon now supports {0} {1.min}-{1.max}')
class CUSTOM_TEXT:

Просмотреть файл

@ -136,7 +136,7 @@ class ActivityLog(amo.models.ModelBase):
serialize_me = []
for arg in args:
if isinstance(arg, str):
if isinstance(arg, (str, unicode)):
serialize_me.append({'str': arg})
else:
serialize_me.append(dict(((unicode(arg._meta), arg.pk),)))
@ -175,6 +175,7 @@ class ActivityLog(amo.models.ModelBase):
if isinstance(arg, Addon) and not addon:
addon = arg
break
return log_type.format.format(*arguments, user=self.user, addon=addon)
def __unicode__(self):

Просмотреть файл

@ -17,6 +17,7 @@ from amo.urlresolvers import reverse
from addons.models import Addon, AddonUser, Charity
from applications.models import AppVersion
from devhub.forms import ContribForm
from devhub.models import ActivityLog
from files.models import File, Platform
from users.models import UserProfile
from versions.models import License, Version
@ -942,7 +943,15 @@ class TestVersionEditFiles(TestVersionEdit):
forms = map(initial,
self.client.get(self.url).context['file_form'].forms)
forms[0]['DELETE'] = True
eq_(ActivityLog.objects.count(), 0)
r = self.client.post(self.url, self.formset(*forms, prefix='files'))
eq_(ActivityLog.objects.count(), 1)
log = ActivityLog.objects.all()[0]
eq_(log.to_string(), u'55021 \u0627\u0644\u062a\u0637\u0628 deleted '
'file delicious_bookmarks-2.1.072-fx.xpi from '
'3615: Delicious Bookmarks '
'version 2.1.072')
eq_(r.status_code, 302)
eq_(self.version.files.count(), 0)

Просмотреть файл

@ -309,8 +309,8 @@ def version_edit(request, addon_id, addon, version_id):
for deleted in data['file_form'].deleted_forms:
file = deleted.cleaned_data['id']
ActivityLog(request, amo.LOG.DELETE_FILE_FROM_VERSION,
(file, addon))
ActivityLog.log(request, amo.LOG.DELETE_FILE_FROM_VERSION,
(file.filename, file.version, addon))
if 'compat_form' in data:
for compat in data['compat_form'].save(commit=False):