зеркало из https://github.com/mozilla/bedrock.git
[fix bug 1342036] Remove Firefox OS feed links
This commit is contained in:
Родитель
7eff25be7f
Коммит
3647ea0d23
|
@ -1,10 +0,0 @@
|
|||
from django.db import models
|
||||
|
||||
|
||||
class FirefoxOSFeedLink(models.Model):
|
||||
link = models.URLField(max_length=2000)
|
||||
title = models.CharField(max_length=2000)
|
||||
locale = models.CharField(max_length=10, db_index=True)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.title
|
|
@ -1,14 +1,11 @@
|
|||
from collections import OrderedDict
|
||||
|
||||
from django.core.cache import cache
|
||||
from django.conf import settings
|
||||
from django.db.utils import DatabaseError
|
||||
|
||||
import jinja2
|
||||
from django.template.loader import render_to_string
|
||||
from django_jinja import library
|
||||
|
||||
from bedrock.firefox.models import FirefoxOSFeedLink
|
||||
from bedrock.firefox.firefox_details import firefox_desktop, firefox_android, firefox_ios
|
||||
from bedrock.base.urlresolvers import reverse
|
||||
from lib.l10n_utils import get_locale
|
||||
|
@ -297,34 +294,3 @@ def firefox_url(platform, page, channel=None):
|
|||
return settings.FIREFOX_MOBILE_SYSREQ_URL
|
||||
|
||||
return reverse('firefox.%s' % page, kwargs=kwargs)
|
||||
|
||||
|
||||
@library.global_function
|
||||
def firefox_os_feed_links(locale, force_cache_refresh=False):
|
||||
if locale in settings.FIREFOX_OS_FEED_LOCALES:
|
||||
cache_key = 'firefox-os-feed-links-' + locale
|
||||
if not force_cache_refresh:
|
||||
links = cache.get(cache_key)
|
||||
if links:
|
||||
return links
|
||||
try:
|
||||
links = list(
|
||||
FirefoxOSFeedLink.objects.filter(locale=locale).order_by(
|
||||
'-id').values_list('link', 'title')[:10])
|
||||
except DatabaseError:
|
||||
links = []
|
||||
cache.set(cache_key, links)
|
||||
return links
|
||||
elif '-' in locale:
|
||||
return firefox_os_feed_links(locale.split('-')[0])
|
||||
|
||||
|
||||
@library.global_function
|
||||
def firefox_os_blog_link(locale):
|
||||
try:
|
||||
return settings.FXOS_PRESS_BLOG_LINKS[locale]
|
||||
except KeyError:
|
||||
if '-' in locale:
|
||||
return firefox_os_blog_link(locale.split('-')[0])
|
||||
else:
|
||||
return None
|
||||
|
|
|
@ -2,16 +2,14 @@ from urlparse import parse_qs, urlparse
|
|||
|
||||
from django.conf import settings
|
||||
from django.test.client import RequestFactory
|
||||
from django.test.utils import override_settings
|
||||
|
||||
from django_jinja.backend import Jinja2
|
||||
from mock import patch, Mock
|
||||
from nose.tools import assert_false, eq_, ok_
|
||||
from nose.tools import eq_, ok_
|
||||
from pyquery import PyQuery as pq
|
||||
|
||||
from product_details import product_details
|
||||
from bedrock.mozorg.tests import TestCase
|
||||
from bedrock.firefox.templatetags import helpers
|
||||
|
||||
jinja_env = Jinja2.get_default()
|
||||
|
||||
|
@ -449,77 +447,6 @@ class TestFirefoxURL(TestCase):
|
|||
ok_(self._render('android', 'notes', 'alpha').endswith('/firefox/android/aurora/notes/'))
|
||||
|
||||
|
||||
@override_settings(FIREFOX_OS_FEED_LOCALES=['xx'])
|
||||
@patch('bedrock.firefox.templatetags.helpers.cache')
|
||||
@patch('bedrock.firefox.templatetags.helpers.FirefoxOSFeedLink')
|
||||
class FirefoxOSFeedLinksTest(TestCase):
|
||||
def test_no_feed_for_locale(self, FirefoxOSFeedLink, cache):
|
||||
"""
|
||||
Should return None without checking cache or db.
|
||||
"""
|
||||
eq_(helpers.firefox_os_feed_links('yy'), None)
|
||||
assert_false(cache.get.called)
|
||||
assert_false(FirefoxOSFeedLink.objects.filter.called)
|
||||
|
||||
def test_force_cache_refresh(self, FirefoxOSFeedLink, cache):
|
||||
"""
|
||||
Should force cache update of first 10 values without cache.get()
|
||||
"""
|
||||
|
||||
(FirefoxOSFeedLink.objects.filter.return_value.order_by.return_value
|
||||
.values_list.return_value) = range(20)
|
||||
eq_(helpers.firefox_os_feed_links('xx', force_cache_refresh=True),
|
||||
range(10))
|
||||
assert_false(cache.get.called)
|
||||
FirefoxOSFeedLink.objects.filter.assert_called_with(locale='xx')
|
||||
cache.set.assert_called_with('firefox-os-feed-links-xx', range(10))
|
||||
|
||||
def test_cache_miss(self, FirefoxOSFeedLink, cache):
|
||||
"""
|
||||
Should update cache with first 10 items from db query
|
||||
"""
|
||||
cache.get.return_value = None
|
||||
(FirefoxOSFeedLink.objects.filter.return_value.order_by.return_value
|
||||
.values_list.return_value) = range(20)
|
||||
eq_(helpers.firefox_os_feed_links('xx'), range(10))
|
||||
cache.get.assert_called_with('firefox-os-feed-links-xx')
|
||||
FirefoxOSFeedLink.objects.filter.assert_called_with(locale='xx')
|
||||
cache.set.assert_called_with('firefox-os-feed-links-xx', range(10))
|
||||
|
||||
def test_hyphenated_cached(self, FirefoxOSFeedLink, cache):
|
||||
"""
|
||||
Should construct cache key with only first part of hyphenated locale.
|
||||
"""
|
||||
eq_(helpers.firefox_os_feed_links('xx-xx'), cache.get.return_value)
|
||||
cache.get.assert_called_with('firefox-os-feed-links-xx')
|
||||
assert_false(FirefoxOSFeedLink.objects.filter.called)
|
||||
|
||||
|
||||
class FirefoxOSBlogLinkTest(TestCase):
|
||||
def test_correct_link_returned_for_es(self):
|
||||
"""
|
||||
Should return the corect link for the es-ES locale
|
||||
"""
|
||||
blog_link_es = 'https://blog.mozilla.org/press-es/category/firefox-os/'
|
||||
|
||||
eq_(helpers.firefox_os_blog_link('es-ES'), blog_link_es)
|
||||
|
||||
def test_correct_link_returned_for_locale_prefix(self):
|
||||
"""
|
||||
Should return the latam link for the es-mx and es-ar locale
|
||||
"""
|
||||
blog_link_latam = 'https://blog.mozilla.org/press-latam/category/firefox-os/'
|
||||
|
||||
eq_(helpers.firefox_os_blog_link('es-mx'), blog_link_latam)
|
||||
eq_(helpers.firefox_os_blog_link('es-ar'), blog_link_latam)
|
||||
|
||||
def test_none_returned(self):
|
||||
"""
|
||||
Should return None as the locale will not be found
|
||||
"""
|
||||
eq_(helpers.firefox_os_blog_link('esmx'), None)
|
||||
|
||||
|
||||
class TestFirefoxFooterLinks(TestCase):
|
||||
def test_show_all_links(self):
|
||||
"""Should show all links by default"""
|
||||
|
|
|
@ -682,17 +682,6 @@ PRESS_BLOGS = {
|
|||
'pl': 'press-pl/',
|
||||
}
|
||||
|
||||
FXOS_PRESS_BLOG_LINKS = {
|
||||
'en': 'https://blog.mozilla.org/press/category/firefox-os/',
|
||||
'de': 'https://blog.mozilla.org/press-de/category/firefox-os/',
|
||||
'es-ES': 'https://blog.mozilla.org/press-es/category/firefox-os/',
|
||||
'es': 'https://blog.mozilla.org/press-latam/category/firefox-os/',
|
||||
'fr': 'https://blog.mozilla.org/press-fr/category/firefox-os/',
|
||||
'it': 'https://blog.mozilla.org/press-it/category/firefox-os/',
|
||||
'pb-BR': 'https://blog.mozilla.org/press-br/category/firefox-os/',
|
||||
'pl': 'https://blog.mozilla.org/press-pl/category/firefox-os/',
|
||||
}
|
||||
|
||||
MOBILIZER_LOCALE_LINK = {
|
||||
'en-US': 'https://wiki.mozilla.org/FirefoxOS/Community/Mobilizers',
|
||||
'hu': 'https://www.facebook.com/groups/mobilizerhungary/',
|
||||
|
@ -1194,18 +1183,6 @@ REST_FRAMEWORK = {
|
|||
'DEFAULT_FILTER_BACKENDS': ('rna.filters.TimestampedFilterBackend',)
|
||||
}
|
||||
|
||||
FIREFOX_OS_FEEDS = (
|
||||
('de', 'https://blog.mozilla.org/press-de/category/firefox-os/feed/'),
|
||||
('en-US', 'https://blog.mozilla.org/blog/category/firefox-os/feed/'),
|
||||
('es-ES', 'https://blog.mozilla.org/press-es/category/firefox-os/feed/'),
|
||||
('es', 'https://blog.mozilla.org/press-latam/category/firefox-os/feed/'),
|
||||
('fr', 'https://blog.mozilla.org/press-fr/category/firefox-os/feed/'),
|
||||
('it', 'https://blog.mozilla.org/press-it/category/firefox-os/feed/'),
|
||||
('pl', 'https://blog.mozilla.org/press-pl/category/firefox-os/feed/'),
|
||||
('pt-BR', 'https://blog.mozilla.org/press-br/category/firefox-os/feed/'),
|
||||
)
|
||||
FIREFOX_OS_FEED_LOCALES = [feed[0] for feed in FIREFOX_OS_FEEDS]
|
||||
|
||||
TABLEAU_DB_URL = config('TABLEAU_DB_URL', default=None)
|
||||
|
||||
ADMINS = MANAGERS = config('ADMINS', cast=json.loads,
|
||||
|
|
|
@ -99,10 +99,6 @@ def schedule_database_jobs():
|
|||
call_command('cron update_ical_feeds')
|
||||
call_command('cron cleanup_ical_events')
|
||||
|
||||
@scheduled_job('interval', hours=1)
|
||||
def update_firefox_os_feeds():
|
||||
call_command('runscript update_firefox_os_feeds')
|
||||
|
||||
@scheduled_job('interval', hours=1)
|
||||
def update_blog_feeds():
|
||||
call_command('update_blog_feeds --database bedrock')
|
||||
|
|
|
@ -15,4 +15,3 @@ fi
|
|||
./manage.py l10n_update
|
||||
#requires twitter api credentials not distributed publicly
|
||||
./manage.py cron update_tweets
|
||||
./manage.py runscript update_firefox_os_feeds
|
||||
|
|
|
@ -13,5 +13,4 @@ deis run -a $DEIS_APPLICATION -- '\
|
|||
./manage.py update_product_details_files --database bedrock; \
|
||||
./manage.py update_externalfiles; \
|
||||
./manage.py update_security_advisories; \
|
||||
./manage.py cron update_tweets; \
|
||||
./manage.py runscript update_firefox_os_feeds'
|
||||
./manage.py cron update_tweets'
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
from django.test.utils import override_settings
|
||||
|
||||
from mock import Mock, patch
|
||||
|
||||
from bedrock.firefox.models import FirefoxOSFeedLink
|
||||
from bedrock.mozorg.tests import TestCase
|
||||
|
||||
from scripts import update_firefox_os_feeds
|
||||
|
||||
|
||||
class TestUpdateFirefoxOSFeeds(TestCase):
|
||||
@override_settings(FIREFOX_OS_FEEDS=[('xx', 'http://example.com/feed'),
|
||||
('yy', 'http://example.com/feed2')])
|
||||
@patch('scripts.update_firefox_os_feeds.create_or_update_fxos_feed_links')
|
||||
@patch('scripts.update_firefox_os_feeds.parse')
|
||||
def test_run_exception_handling(self, parse, create_or_update_fxos_feed_links):
|
||||
parse.side_effect = [Exception('test'), 'parsed feed']
|
||||
update_firefox_os_feeds.run()
|
||||
create_or_update_fxos_feed_links.assert_called_with('yy', 'parsed feed')
|
||||
|
||||
@patch('scripts.update_firefox_os_feeds.create_or_update_fxos_feed_link')
|
||||
def test_create_or_update_fxos_feed_links(
|
||||
self, create_or_update_fxos_feed_link):
|
||||
update_firefox_os_feeds.create_or_update_fxos_feed_links(
|
||||
'xx',
|
||||
{'entries': [{}, {'link': 'http://example.com', 'title': 'Title'}]})
|
||||
create_or_update_fxos_feed_link.assert_called_with(
|
||||
'xx', 'http://example.com', 'Title')
|
||||
|
||||
@patch('scripts.update_firefox_os_feeds.FirefoxOSFeedLink.objects')
|
||||
def test_create_or_update_fxos_feed_link(self, objects):
|
||||
objects.get_or_create.return_value = ('feed_link', True)
|
||||
update_firefox_os_feeds.create_or_update_fxos_feed_link(
|
||||
'xx', 'http://example.com', 'Title')
|
||||
objects.get_or_create.assert_called_with(
|
||||
locale='xx', link='http://example.com', defaults={'title': 'Title'})
|
||||
|
||||
@patch('scripts.update_firefox_os_feeds.FirefoxOSFeedLink.objects')
|
||||
def test_create_or_update_fxos_feed_link_update_title(self, objects):
|
||||
feed_link = Mock(title='Old Title')
|
||||
objects.get_or_create.return_value = (feed_link, False)
|
||||
update_firefox_os_feeds.create_or_update_fxos_feed_link(
|
||||
'xx', 'http://example.com', 'Title')
|
||||
objects.get_or_create.assert_called_with(
|
||||
locale='xx', link='http://example.com', defaults={'title': 'Title'})
|
||||
feed_link.save.assert_called_with(update_fields=['title'])
|
|
@ -1,33 +0,0 @@
|
|||
from __future__ import print_function
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from feedparser import parse
|
||||
|
||||
from bedrock.firefox.models import FirefoxOSFeedLink
|
||||
|
||||
|
||||
def create_or_update_fxos_feed_link(locale, link, title):
|
||||
feed_link, created = FirefoxOSFeedLink.objects.get_or_create(
|
||||
locale=locale, link=link, defaults={'title': title})
|
||||
if not created and title != feed_link.title:
|
||||
feed_link.title = title
|
||||
feed_link.save(update_fields=['title'])
|
||||
|
||||
|
||||
def create_or_update_fxos_feed_links(locale, parsed_feed):
|
||||
for entry in parsed_feed.get('entries', []):
|
||||
link = entry.get('link')
|
||||
title = entry.get('title')
|
||||
if link and title:
|
||||
create_or_update_fxos_feed_link(locale, link, title)
|
||||
|
||||
|
||||
def run(*args):
|
||||
for locale, url in settings.FIREFOX_OS_FEEDS:
|
||||
try:
|
||||
parsed_feed = parse(url)
|
||||
except:
|
||||
print('Unable to fetch and parse ' + url)
|
||||
else:
|
||||
create_or_update_fxos_feed_links(locale, parsed_feed)
|
Загрузка…
Ссылка в новой задаче