fix unit tests, signal has to be sent at end of from_upload (bug 647483)

This commit is contained in:
Andy McKay 2011-04-12 17:36:55 -07:00
Родитель 24231c5b7c
Коммит c3ea7b23d5
3 изменённых файлов: 21 добавлений и 15 удалений

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

@ -15,7 +15,7 @@ from editors.sql_model import RawSQLModel
from translations.fields import TranslatedField
from tower import ugettext as _
from users.models import UserProfile
from versions.models import Version
from versions.models import Version, version_uploaded
import commonware.log
@ -215,18 +215,17 @@ class EditorSubscription(amo.models.ModelBase):
use_blacklist=False)
def send_notifications(sender, instance, **kw):
if kw.get('raw') or not kw.get('created') or instance.is_beta:
def send_notifications(signal=None, sender=None):
if sender.is_beta:
return
subscribers = instance.addon.editorsubscription_set.all()
subscribers = sender.addon.editorsubscription_set.all()
if not subscribers:
return
for subscriber in subscribers:
subscriber.send_notification(instance)
subscriber.send_notification(sender)
subscriber.delete()
models.signals.post_save.connect(send_notifications, sender=Version,
dispatch_uid='version_send_notifications')
version_uploaded.connect(send_notifications, dispatch_uid='send_notifications')

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

@ -8,7 +8,8 @@ import test_utils
import amo
from addons.models import Addon
from versions.models import Version, ApplicationsVersions, VersionSummary
from versions.models import (Version, version_uploaded,
ApplicationsVersions, VersionSummary)
from files.models import Platform, File
from applications.models import Application, AppVersion
from editors.models import (EditorSubscription, send_notifications,
@ -227,21 +228,21 @@ class TestEditorSubscription(test_utils.TestCase):
'Mozilla Add-ons: Delicious Bookmarks Updated')
def test_notifications(self):
send_notifications(Version, self.version, created=True)
send_notifications(sender=self.version)
eq_(len(mail.outbox), 2)
emails = sorted([o.to for o in mail.outbox])
eq_(emails, [[u'del@icio.us'], [u'regular@mozilla.com']])
def test_notifications_clean(self):
send_notifications(Version, self.version, created=True)
send_notifications(Version, self.version)
eq_(EditorSubscription.objects.count(), 0)
mail.outbox = []
send_notifications(Version, self.version, created=True)
send_notifications(Version, self.version)
eq_(len(mail.outbox), 0)
def test_notifications_beta(self):
self.version.all_files[0].update(status=amo.STATUS_BETA)
send_notifications(Version, self.version, created=True)
version_uploaded.send(sender=self.version)
eq_(len(mail.outbox), 0)
def test_signal_edit(self):
@ -249,13 +250,16 @@ class TestEditorSubscription(test_utils.TestCase):
eq_(len(mail.outbox), 0)
def test_signal_create(self):
Version.objects.create(addon=self.addon)
v = Version.objects.create(addon=self.addon)
version_uploaded.send(sender=v)
eq_(len(mail.outbox), 2)
eq_(mail.outbox[0].subject,
'Mozilla Add-ons: Delicious Bookmarks Updated')
def test_signal_create_twice(self):
Version.objects.create(addon=self.addon)
v = Version.objects.create(addon=self.addon)
version_uploaded.send(sender=v)
mail.outbox = []
Version.objects.create(addon=self.addon)
v = Version.objects.create(addon=self.addon)
version_uploaded.send(sender=v)
eq_(len(mail.outbox), 0)

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

@ -3,6 +3,7 @@ import os
from django.conf import settings
from django.db import models
import django.dispatch
import jinja2
import commonware.log
@ -100,6 +101,7 @@ class Version(amo.models.ModelBase):
# After the upload has been copied to all
# platforms, remove the upload.
upload.path.unlink()
version_uploaded.send(sender=v)
return v
@property
@ -242,6 +244,7 @@ def update_status(sender, instance, **kw):
pass
version_uploaded = django.dispatch.Signal()
models.signals.post_save.connect(update_status, sender=Version,
dispatch_uid='version_update_status')
models.signals.post_delete.connect(update_status, sender=Version,