Skip to content

Commit

Permalink
fix for bug 554149 + tests for has_eula and latest_xpi_url
Browse files Browse the repository at this point in the history
  • Loading branch information
jbalogh committed Mar 22, 2010
1 parent aa6c663 commit 05f47af
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/addons/models.py
Expand Up @@ -390,7 +390,7 @@ def num_users(self):
@amo.cached_property
def raised(self):
qs = self.contributions.aggregate(raised=Sum('amount'))
return qs['raised']
return qs['raised'] or 0

def __unicode__(self):
return '%s ($%s, %s)' % (self.addon.name, self.target, self.deadline)
Expand Down
21 changes: 20 additions & 1 deletion apps/addons/tests/test_models.py
Expand Up @@ -186,8 +186,21 @@ def test_is_category_featured(self):
assert a.is_category_featured(amo.FIREFOX, 'en-US'), (
'category featured add-on not recognized')

def test_has_eula(self):
addon = lambda: Addon.objects.get(pk=3615)
assert not addon().has_eula

class TestAddonPledgeModel(test.TestCase):
a = addon()
a.eula = ''
a.save()
assert not addon().has_eula

a.eula = 'eula'
a.save()
assert addon().has_eula


class TestAddonPledgeModel(test_utils.TestCase):
fixtures = ['stats/test_models.json']

def test_ongoing(self):
Expand Down Expand Up @@ -216,3 +229,9 @@ def test_contributions(self):
# Only the two valid contributions must be counted.
eq_(mypledge.num_users, 2)
self.assertAlmostEqual(mypledge.raised, 4.98)

def test_raised(self):
"""AddonPledge.raised should never return None."""
pledge = AddonPledge.objects.create(addon_id=4, target=230,
deadline=date.today())
eq_(pledge.raised, 0)
13 changes: 13 additions & 0 deletions apps/files/tests.py
@@ -1,5 +1,7 @@
from django import test

from nose.tools import eq_

from files.models import File


Expand All @@ -16,3 +18,14 @@ def test_get_absolute_url(self):
assert f.get_absolute_url(src).endswith(
'downloads/file/11993/'
'del.icio.us_bookmarks-1.0.43-fx.xpi?src=crystalmethod')

def test_latest_url(self):
# With platform.
f = File.objects.get(id=61321)
expected = '/downloads/latest/{0}/platform:3/addon-{0}-latest.jar'
eq_(expected.format(f.version.addon_id), f.latest_xpi_url())

# No platform.
f = File.objects.get(id=11993)
expected = '/downloads/latest/{0}/addon-{0}-latest.xpi'
eq_(expected.format(f.version.addon_id), f.latest_xpi_url())

0 comments on commit 05f47af

Please sign in to comment.