From c3ea7b23d5a4822ecaa7e855430c53af04ea04e0 Mon Sep 17 00:00:00 2001 From: Andy McKay Date: Tue, 12 Apr 2011 17:36:55 -0700 Subject: [PATCH] fix unit tests, signal has to be sent at end of from_upload (bug 647483) --- apps/editors/models.py | 13 ++++++------- apps/editors/tests/test_models.py | 20 ++++++++++++-------- apps/versions/models.py | 3 +++ 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/apps/editors/models.py b/apps/editors/models.py index 58eb5d7cfc..ed60abcfaa 100644 --- a/apps/editors/models.py +++ b/apps/editors/models.py @@ -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') diff --git a/apps/editors/tests/test_models.py b/apps/editors/tests/test_models.py index 25aecbb49f..3c72fab267 100644 --- a/apps/editors/tests/test_models.py +++ b/apps/editors/tests/test_models.py @@ -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) diff --git a/apps/versions/models.py b/apps/versions/models.py index 581d2d2a41..a1c2be360f 100644 --- a/apps/versions/models.py +++ b/apps/versions/models.py @@ -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,