check that urls have hashes or modified and flushes occur on changes (bug 600885)

This commit is contained in:
Andy McKay 2010-11-10 17:03:11 -08:00
Родитель 46874e07bb
Коммит e0ca93d188
5 изменённых файлов: 73 добавлений и 3 удалений

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

@ -251,7 +251,8 @@ class Addon(amo.models.ModelBase):
'*/addon/%d/privacy/' % self.id,
'*/addon/%d/versions/*' % self.id,
'*/api/*/addon/%d' % self.id,
# TODO(clouserw) preview images
self.icon_url,
self.thumbnail_url,
]
urls.extend('*/user/%d/' % u.id for u in self.listed_authors)

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

@ -1,13 +1,16 @@
from datetime import date
import itertools
from urlparse import urlparse
from django.conf import settings
from django.core.cache import cache
from mock import patch
from nose.tools import eq_, assert_not_equal
import test_utils
import amo
from amo.signals import _connect, _disconnect
from addons.models import (Addon, AddonDependency, AddonPledge,
AddonRecommendation, AddonType, Category, Feature,
Persona, Preview)
@ -383,3 +386,45 @@ class TestListedAddonTwoVersions(test_utils.TestCase):
def test_listed_two_versions(self):
Addon.objects.get(id=2795) # bug 563967
class TestFlushURLs(test_utils.TestCase):
fixtures = ['base/addon_5579',
'base/previews',
'base/addon_4664_twitterbar',
'addons/persona']
def setUp(self):
settings.ADDON_ICON_URL = (
'%s/%s/%s/images/addon_icon/%%d/?modified=%%s' % (
settings.STATIC_URL, settings.LANGUAGE_CODE, settings.DEFAULT_APP))
settings.PREVIEW_THUMBNAIL_URL = (settings.STATIC_URL +
'/img/uploads/previews/thumbs/%s/%d.png?modified=%d')
settings.PREVIEW_FULL_URL = (settings.STATIC_URL +
'/img/uploads/previews/full/%s/%d.png?modified=%d')
_connect()
def tearDown(self):
_disconnect()
def is_url_hashed(self, url):
return urlparse(url).query.find('modified') > -1
@patch('amo.tasks.flush_front_end_cache_urls.apply_async')
def test_addon_flush(self, flush):
addon = Addon.objects.get(pk=159)
addon.icon_type = "image/png"
addon.save()
for url in (addon.thumbnail_url, addon.icon_url):
assert url in flush.call_args[1]['args'][0]
assert self.is_url_hashed(url), url
@patch('amo.tasks.flush_front_end_cache_urls.apply_async')
def test_preview_flush(self, flush):
addon = Addon.objects.get(pk=4664)
preview = addon.previews.all()[0]
preview.save()
for url in (preview.thumbnail_url, preview.image_url):
assert url in flush.call_args[1]['args'][0]
assert self.is_url_hashed(url), url

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

@ -1329,6 +1329,8 @@ class TestVersionEditFiles(TestVersionEdit):
'Bookmarks</a>')
eq_(r.status_code, 302)
eq_(self.version.files.count(), 0)
r = self.client.get(self.url)
eq_(r.status_code, 200)
def test_edit_status(self):
f = self.client.get(self.url).context['file_form'].forms[0]

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

@ -132,7 +132,9 @@ class UserProfile(amo.models.ModelBase):
return reverse('users.profile', args=[self.id])
def flush_urls(self):
urls = ['*/user/%d/' % self.id]
urls = ['*/user/%d/' % self.id,
self.picture_url,
]
return urls

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

@ -1,14 +1,17 @@
from datetime import date
import hashlib
from urlparse import urlparse
from django.contrib.auth.models import User
from django.core import mail
from django.utils import encoding
import test_utils
from mock import patch
from nose.tools import eq_
import test_utils
import amo
from amo.signals import _connect, _disconnect
from addons.models import Addon, AddonUser
from bandwagon.models import Collection
from reviews.models import Review
@ -174,3 +177,20 @@ class TestBlacklistedEmailDomain(test_utils.TestCase):
def test_blocked(self):
eq_(BlacklistedEmailDomain.blocked('mailinator.com'), True)
assert not BlacklistedEmailDomain.blocked('mozilla.com')
class TestFlushURLs(test_utils.TestCase):
fixtures = ['base/user_2519']
def setUp(self):
_connect()
def tearDown(self):
_disconnect()
@patch('amo.tasks.flush_front_end_cache_urls.apply_async')
def test_flush(self, flush):
user = UserProfile.objects.get(pk=2519)
user.save()
assert user.picture_url in flush.call_args[1]['args'][0]
assert urlparse(user.picture_url).query.find('modified') > -1