include lastupdated timestamp in the blocklist (bug 639527)

This commit is contained in:
Jeff Balogh 2011-03-25 13:45:23 -07:00
Родитель a793ca95ba
Коммит 5cdbb9ed45
3 изменённых файлов: 29 добавлений и 12 удалений

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

@ -1,5 +1,5 @@
<?xml version="1.0"?>
<blocklist xmlns="http://www.mozilla.org/2006/addons-blocklist">
<blocklist xmlns="http://www.mozilla.org/2006/addons-blocklist" lastupdate="{{ now }}">
{% if items %}
<emItems>
{% for guid, rows in items.items() %}

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

@ -1,3 +1,4 @@
from datetime import datetime
from xml.dom import minidom
from django.conf import settings
@ -26,6 +27,7 @@ class BlocklistTest(test_utils.TestCase):
self.fx2_url = reverse('blocklist', args=[2, amo.FIREFOX.guid, '2.0'])
self.mobile_url = reverse('blocklist', args=[2, amo.MOBILE.guid, '.9'])
self._redis = redisutils.mock_redis()
cache.clear()
def tearDown(self):
redisutils.reset_redis(self._redis)
@ -36,6 +38,10 @@ class BlocklistTest(test_utils.TestCase):
def eq_(self, x, y):
return eq_(self.normalize(x), self.normalize(y))
def dom(self, url):
r = self.client.get(url)
return minidom.parseString(r.content)
class BlocklistItemTest(BlocklistTest):
@ -45,10 +51,17 @@ class BlocklistItemTest(BlocklistTest):
self.app = BlocklistApp.objects.create(blitem=self.item,
guid=amo.FIREFOX.guid)
def test_lastupdate(self):
bl = self.dom(self.fx4_url).getElementsByTagName('blocklist')[0]
t = datetime.fromtimestamp(int(bl.getAttribute('lastupdate')) / 1000)
assert (datetime.now() - t).seconds < 5
def test_no_items(self):
self.item.delete()
r = self.client.get(self.fx4_url)
self.eq_(r.content, base_xml)
dom = self.dom(self.fx4_url)
children = dom.getElementsByTagName('blocklist')[0].childNodes
# There are only text nodes.
assert all(e.nodeType == 3 for e in children)
def test_new_cookie_per_user(self):
self.client.get(self.fx4_url)
@ -85,10 +98,6 @@ class BlocklistItemTest(BlocklistTest):
eq_(r.status_code, 200)
eq_(len(r.context['items']), 1)
def dom(self, url):
r = self.client.get(self.fx4_url)
return minidom.parseString(r.content)
def test_item_guid(self):
items = self.dom(self.fx4_url).getElementsByTagName('emItem')
eq_(len(items), 1)
@ -200,8 +209,10 @@ class BlocklistPluginTest(BlocklistTest):
self.plugin = BlocklistPlugin.objects.create(guid=amo.FIREFOX.guid)
def test_no_plugins(self):
r = self.client.get(self.mobile_url)
self.eq_(r.content, base_xml)
dom = BlocklistTest.dom(self, self.mobile_url)
children = dom.getElementsByTagName('blocklist')[0].childNodes
# There are only text nodes.
assert all(e.nodeType == 3 for e in children)
def dom(self, url=None):
url = url or self.fx4_url
@ -287,8 +298,10 @@ class BlocklistGfxTest(BlocklistTest):
driver_version='version', driver_version_comparator='compare')
def test_no_gfx(self):
r = self.client.get(self.mobile_url)
self.eq_(r.content, base_xml)
dom = self.dom(self.mobile_url)
children = dom.getElementsByTagName('blocklist')[0].childNodes
# There are only text nodes.
assert all(e.nodeType == 3 for e in children)
def test_gfx(self):
r = self.client.get(self.fx4_url)

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

@ -1,5 +1,6 @@
import collections
from datetime import datetime, timedelta
import time
import uuid
from django.core.cache import cache
@ -37,9 +38,12 @@ def _blocklist(request, apiver, app, appver):
items = get_items(apiver, app, appver)
plugins = get_plugins(apiver, app, appver)
gfxs = BlocklistGfx.objects.filter(Q(guid__isnull=True) | Q(guid=app))
# The client expects milliseconds, Python's time returns seconds.
now = int(time.time() * 1000)
return jingo.render(request, 'blocklist/blocklist.xml',
dict(items=items, plugins=plugins, gfxs=gfxs,
apiver=apiver, appguid=app, appver=appver))
apiver=apiver, appguid=app, appver=appver,
now=now))
def clear_blocklist(*args, **kw):