This commit is contained in:
Jeff Balogh 2011-08-18 11:21:21 -07:00
Родитель 2da971c9e4
Коммит 018bc18ca1
11 изменённых файлов: 100 добавлений и 216 удалений

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

@ -71,12 +71,12 @@ class AddonManager(amo.models.ManagerBase):
return self.filter(_current_version__isnull=False,
status__in=statuses)
def featured(self, app):
def featured(self, app, lang=None, type=None):
"""
Filter for all featured add-ons for an application in all locales.
"""
ids = FeaturedManager.featured_ids(app)
return amo.models.manual_order(self.valid(), ids, 'addons.id')
ids = FeaturedManager.featured_ids(app, lang, type)
return amo.models.manual_order(self.listed(app), ids, 'addons.id')
def listed(self, app, *status):
"""

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

@ -56,66 +56,19 @@ class TestHomepage(amo.tests.TestCase):
super(TestHomepage, self).setUp()
self.base_url = reverse('home')
def test_promo_box_public_addons(self):
"""Only public add-ons in the promobox."""
r = self.client.get(self.base_url, follow=True)
doc = pq(r.content)
assert doc('.addon-view .item').length > 0
Addon.objects.update(status=amo.STATUS_UNREVIEWED)
cache.clear()
r = self.client.get(self.base_url, follow=True)
doc = pq(r.content)
eq_(doc('.addon-view .item').length, 0)
def test_promo_box(self):
"""Test that promobox features have proper translations."""
r = self.client.get(self.base_url, follow=True)
doc = pq(r.content)
eq_(doc('.lead a')[0].text, 'WebDev')
def test_thunderbird(self):
"""Thunderbird homepage should have the Thunderbird title."""
r = self.client.get('/en-US/thunderbird/')
doc = pq(r.content)
eq_('Add-ons for Thunderbird', doc('title').text())
def test_default_feature(self):
response = self.client.get(self.base_url, follow=True)
eq_(response.status_code, 200)
eq_(response.context['filter'].field, 'featured')
def test_featured(self):
response = self.client.get(self.base_url + '?browse=featured',
follow=True)
eq_(response.status_code, 200)
eq_(response.context['filter'].field, 'featured')
featured = response.context['addon_sets']['featured']
ids = [a.id for a in featured]
eq_(set(ids), set([2464, 7661]))
for addon in featured:
assert addon.is_featured(amo.FIREFOX, settings.LANGUAGE_CODE)
def _test_invalid_feature(self):
response = self.client.get(self.base_url + '?browse=xxx')
self.assertRedirects(response, '/en-US/firefox/', status_code=301)
def test_no_unreviewed(self):
response = self.client.get(self.base_url)
for addons in response.context['addon_sets'].values():
for addon in addons:
addon_lists = 'popular featured hotness personas'.split()
for key in addon_lists:
for addon in response.context[key]:
assert addon.status != amo.STATUS_UNREVIEWED
def test_filter_opts(self):
response = self.client.get(self.base_url)
opts = [k[0] for k in response.context['filter'].opts]
eq_(opts, 'featured popular new updated'.split())
def test_added_date(self):
doc = pq(self.client.get(self.base_url).content)
s = doc('#list-new .item .updated').text()
assert s.strip().startswith('Added'), s
class TestPromobox(amo.tests.TestCase):
fixtures = ['addons/ptbr-promobox']
@ -421,15 +374,6 @@ class TestDetailPage(amo.tests.TestCase):
eq_(response.status_code, 200)
eq_(response.context['addon'].id, 15663)
def test_review_microdata_extension(self):
a = Addon.objects.get(id=3615)
a.name = '<script>alert("fff")</script>'
a.save()
response = self.client.get(reverse('addons.detail', args=['a3615']))
html = pq(response.content)('table caption').html()
assert '&lt;script&gt;alert("fff")&lt;/script&gt;' in html
assert '<script>' not in html
def test_review_microdata_personas(self):
a = Addon.objects.get(id=15663)
a.name = '<script>alert("fff")</script>'
@ -467,19 +411,6 @@ class TestDetailPage(amo.tests.TestCase):
doc = pq(self.client.get(url).content)
assert doc(m)
def test_listed(self):
"""Show certain things for hosted but not listed add-ons."""
hosted_resp = self.client.get(reverse('addons.detail', args=['a3615']),
follow=True)
hosted = pq(hosted_resp.content)
listed_resp = self.client.get(reverse('addons.detail', args=['a3723']),
follow=True)
listed = pq(listed_resp.content)
eq_(hosted('#releasenotes').length, 1)
eq_(listed('#releasenotes').length, 0)
def test_more_about(self):
# Don't show more about box if there's nothing to populate it.
addon = Addon.objects.get(id=3615)
@ -515,25 +446,6 @@ class TestDetailPage(amo.tests.TestCase):
beta = get_pq_content()
eq_(beta('#beta-channel').length, 0)
def test_other_addons(self):
"""Test "other add-ons by author" list."""
# Grab a user and give them some add-ons.
u = UserProfile.objects.get(pk=55021)
thisaddon = u.addons.all()[0]
qs = Addon.objects.valid().exclude(pk=thisaddon.pk)
other_addons = order_by_translation(qs, 'name')[:3]
for addon in other_addons:
AddonUser.objects.create(user=u, addon=addon)
page = self.client.get(reverse('addons.detail', args=[thisaddon.slug]),
follow=True)
doc = pq(page.content)
eq_(doc('.other-author-addons li').length, other_addons.count())
for i in range(other_addons.count()):
link = doc('.other-author-addons li a').eq(i)
eq_(link.attr('href'), other_addons[i].get_url_path())
def test_type_redirect(self):
"""
If current add-on's type is unsupported by app, redirect to an
@ -580,7 +492,7 @@ class TestDetailPage(amo.tests.TestCase):
response = self.client.get(reverse('addons.detail', args=[addon.slug]),
follow=True)
doc = pq(response.content)
eq_(doc('#addon-summary a[href^="%s"]' %
eq_(doc('aside a.home[href^="%s"]' %
settings.REDIRECT_URL).length, 1)
def test_no_privacy_policy(self):
@ -670,32 +582,6 @@ class TestDetailPage(amo.tests.TestCase):
follow=True)
eq_(response.status_code, 404)
def test_other_author_addons(self):
"""
Make sure the list of other author addons doesn't include this one.
"""
r = self.client.get(reverse('addons.detail', args=['a3615']))
doc = pq(r.content)
eq_(len([a.attrib['value'] for a
in doc('#addons-author-addons-select option')
if a.attrib['value'] == '3615']), 0)
# Test "other addons" redirect functionality with valid and
# invalid input.
forward_to = lambda input: self.client.get(reverse(
'addons.detail', args=[3615]), {
'addons-author-addons-select': input})
# Valid input.
response = forward_to('3615')
eq_(response.status_code, 301)
assert response['Location'].find('3615') > 0
# Textual input.
response = forward_to('abc')
eq_(response.status_code, 400)
# Unicode input.
response = forward_to(u'\u271D')
eq_(response.status_code, 400)
def test_detailed_review_link(self):
self.client.login(username='regular@mozilla.com', password='password')
r = self.client.get(reverse('addons.detail', args=['a3615']))
@ -722,21 +608,22 @@ class TestDetailPage(amo.tests.TestCase):
def test_search_engine_works_with(self):
"""We don't display works-with info for search engines."""
addon = Addon.objects.filter(type=amo.ADDON_SEARCH)[0]
r = self.client.get(reverse('addons.detail', args=[addon.slug]))
headings = pq(r.content)('table[itemscope] th')
assert not any(th.text.strip().lower() == 'works with'
r = self.client.get(reverse('addons.detail_more', args=[addon.slug]),
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
headings = pq(r.content)('#detail-relnotes .item-info h5')
assert not any(th.text.strip().lower() == 'works with:'
for th in headings)
# Make sure we find Works with for an extension.
r = self.client.get(reverse('addons.detail', args=['a3615']))
headings = pq(r.content)('table[itemscope] th')
assert any(th.text.strip().lower() == 'works with'
headings = pq(r.content)('#detail-relnotes .item-info h5')
assert any(th.text.strip().lower() == 'works with:'
for th in headings)
def test_show_profile(self):
addon = Addon.objects.get(id=3615)
url = reverse('addons.detail', args=[addon.slug])
selector = '.secondary a[href="%s"]' % addon.meet_the_dev_url()
selector = '.author a[href="%s"]' % addon.meet_the_dev_url()
assert not (addon.the_reason or addon.the_future)
assert not pq(self.client.get(url).content)(selector)
@ -746,7 +633,7 @@ class TestDetailPage(amo.tests.TestCase):
assert pq(self.client.get(url).content)(selector)
def test_no_restart(self):
no_restart = '<div id="no-restart"'
no_restart = '<span class="no-restart">No Restart</span>'
addon = Addon.objects.get(id=3615)
url = reverse('addons.detail', args=[addon.slug])
f = addon.current_version.all_files[0]
@ -911,7 +798,9 @@ class TestTagsBox(amo.tests.TestCase):
def test_tag_box(self):
"""Verify that we don't show duplicate tags."""
r = self.client.get(reverse('addons.detail', args=[8680]), follow=True)
r = self.client.get(reverse('addons.detail_more', args=[8680]),
follow=True,
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
doc = pq(r.content)
eq_('SEO', doc('#tagbox ul').children().text())

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

@ -426,10 +426,6 @@ def home(request):
def impala_home(request):
# Add-ons.
base = Addon.objects.listed(request.APP).filter(type=amo.ADDON_EXTENSION)
featured_ext = FeaturedManager.featured_ids(request.APP, request.LANG,
type=amo.ADDON_EXTENSION)
featured_personas = FeaturedManager.featured_ids(request.APP, request.LANG,
type=amo.ADDON_PERSONA)
# This is lame for performance. Kill it with ES.
frozen = FrozenAddon.objects.values_list('addon', flat=True)
@ -437,12 +433,12 @@ def impala_home(request):
collections = Collection.objects.filter(listed=True,
application=request.APP.id,
type=amo.COLLECTION_FEATURED)
featured = base.filter(id__in=featured_ext[:18])
featured = Addon.objects.featured(request.APP, request.LANG,
amo.ADDON_EXTENSION)[:18]
popular = base.exclude(id__in=frozen).order_by('-average_daily_users')[:10]
hotness = base.exclude(id__in=frozen).order_by('-hotness')[:18]
personas = (Addon.objects.listed(request.APP)
.filter(type=amo.ADDON_PERSONA, id__in=featured_personas[:18]))
personas = Addon.objects.featured(request.APP, request.LANG,
amo.ADDON_PERSONA)[:18]
return jingo.render(request, 'addons/impala/home.html',
{'popular': popular, 'featured': featured,
'hotness': hotness, 'personas': personas,

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

@ -72,6 +72,9 @@ class TestCase(RedisTest, test_utils.TestCase):
def _pre_setup(self):
super(TestCase, self)._pre_setup()
self.reset_featured_addons()
def reset_featured_addons(self):
from addons.cron import reset_featured_addons
from addons.utils import FeaturedManager, CreaturedManager
reset_featured_addons()

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

@ -168,12 +168,6 @@ class TestStuff(amo.tests.TestCase):
fixtures = ('base/users', 'base/global-stats', 'base/configs',
'base/addon_3615')
def test_hide_stats_link(self):
r = self.client.get('/', follow=True)
doc = pq(r.content)
assert doc('.stats')
assert not doc('.stats a')
def test_data_anonymous(self):
def check(expected):
response = self.client.get('/', follow=True)
@ -191,22 +185,20 @@ class TestStuff(amo.tests.TestCase):
# Logged out
doc = get_homepage()
eq_(doc('#aux-nav .account').length, 0)
eq_(doc('#aux-nav .account.anonymous').length, 1)
eq_(doc('#aux-nav .tools').length, 0)
# Logged in, regular user = one tools link
self.client.login(username='regular@mozilla.com', password='password')
doc = get_homepage()
eq_(doc('#aux-nav .account').length, 1)
eq_(doc('#aux-nav ul.tools').length, 0)
eq_(doc('#aux-nav p.tools').length, 1)
eq_(doc('#aux-nav li.tools.nomenu').length, 1)
# Logged in, admin = multiple links
self.client.login(username='admin@mozilla.com', password='password')
doc = get_homepage()
eq_(doc('#aux-nav .account').length, 1)
eq_(doc('#aux-nav ul.tools').length, 1)
eq_(doc('#aux-nav p.tools').length, 0)
eq_(doc('#aux-nav li.tools').length, 1)
def test_heading(self):
def title_eq(url, alt, text):
@ -217,7 +209,7 @@ class TestStuff(amo.tests.TestCase):
title_eq('/firefox', 'Firefox', 'Add-ons')
title_eq('/thunderbird', 'Thunderbird', 'Add-ons')
title_eq('/mobile', 'Firefox', 'Mobile Add-ons')
title_eq('/mobile', 'Mobile', 'Mobile Add-ons')
def test_tools_loggedout(self):
r = self.client.get(reverse('home'), follow=True)
@ -250,20 +242,19 @@ class TestStuff(amo.tests.TestCase):
eq_(request.amo_user.is_developer, True)
eq_(nav.find('ul.tools').length, 1)
eq_(nav.find('ul.tools li').length, 4)
eq_(nav.find('ul.tools > li > a').length, 1)
eq_(nav.find('ul.tools > li > a').text(), "Developer")
eq_(nav.find('li.tools').length, 1)
eq_(nav.find('li.tools > a').text(), "Developer")
eq_(nav.find('li.tools li').length, 3)
item = nav.find('ul.tools ul li a').eq(0)
item = nav.find('li.tools ul li a').eq(0)
eq_(item.text(), "Manage My Add-ons")
eq_(item.attr('href'), reverse('devhub.addons'))
item = nav.find('ul.tools ul li a').eq(1)
item = nav.find('li.tools ul li a').eq(1)
eq_(item.text(), "Submit a New Add-on")
eq_(item.attr('href'), reverse('devhub.submit.1'))
item = nav.find('ul.tools ul li a').eq(2)
item = nav.find('li.tools ul li a').eq(2)
eq_(item.text(), "Developer Hub")
eq_(item.attr('href'), reverse('devhub.index'))
@ -282,24 +273,22 @@ class TestStuff(amo.tests.TestCase):
eq_(request.amo_user.is_developer, True)
eq_(acl.action_allowed(request, 'Editors', '%'), True)
eq_(nav.find('ul.tools').length, 1)
eq_(nav.find('ul.tools li').length, 5)
eq_(nav.find('ul.tools > li > a').length, 1)
eq_(nav.find('ul.tools > li > a').text(), "Tools")
eq_(nav.find('li.tools').length, 1)
eq_(nav.find('li.tools li').length, 4)
item = nav.find('ul.tools ul li a').eq(0)
item = nav.find('li.tools ul li a').eq(0)
eq_(item.text(), "Manage My Add-ons")
eq_(item.attr('href'), reverse('devhub.addons'))
item = nav.find('ul.tools ul li a').eq(1)
item = nav.find('li.tools ul li a').eq(1)
eq_(item.text(), "Submit a New Add-on")
eq_(item.attr('href'), reverse('devhub.submit.1'))
item = nav.find('ul.tools ul li a').eq(2)
item = nav.find('li.tools ul li a').eq(2)
eq_(item.text(), "Developer Hub")
eq_(item.attr('href'), reverse('devhub.index'))
item = nav.find('ul.tools ul li a').eq(3)
item = nav.find('li.tools ul li a').eq(3)
eq_(item.text(), "Editor Tools")
eq_(item.attr('href'), reverse('editors.home'))
@ -313,16 +302,14 @@ class TestStuff(amo.tests.TestCase):
eq_(request.amo_user.is_developer, False)
eq_(acl.action_allowed(request, 'Editors', '%'), True)
eq_(nav.find('ul.tools').length, 1)
eq_(nav.find('ul.tools li').length, 3)
eq_(nav.find('ul.tools > li > a').length, 1)
eq_(nav.find('ul.tools > li > a').text(), "Tools")
eq_(nav.find('li.tools').length, 1)
eq_(nav.find('li.tools > a').text(), 'Tools')
item = nav.find('ul.tools ul li a').eq(0)
item = nav.find('li.tools ul li a').eq(0)
eq_(item.text(), "Developer Hub")
eq_(item.attr('href'), reverse('devhub.index'))
item = nav.find('ul.tools ul li a').eq(1)
item = nav.find('li.tools ul li a').eq(1)
eq_(item.text(), "Editor Tools")
eq_(item.attr('href'), reverse('editors.home'))
@ -335,7 +322,7 @@ class TestStuff(amo.tests.TestCase):
doc = PyQuery(r.content)
next = urllib.urlencode({'to': '/en-US/firefox/'})
eq_('/en-US/firefox/users/login?%s' % next,
doc('#aux-nav p a')[1].attrib['href'])
doc('.account.anonymous a')[1].attrib['href'])
class TestPaypal(amo.tests.TestCase):
@ -477,7 +464,7 @@ class TestOtherStuff(amo.tests.TestCase):
def test_dictionaries_link(self):
doc = pq(test.Client().get('/', follow=True).content)
link = doc('#categoriesdropdown a[href*="language-tools"]')
link = doc('#site-nav #more a[href*="language-tools"]')
eq_(link.text(), 'Dictionaries & Language Packs')
def test_opensearch(self):
@ -495,13 +482,13 @@ class TestOtherStuff(amo.tests.TestCase):
# Test that the login link encodes parameters correctly.
r = test.Client().get('/?your=mom', follow=True)
doc = pq(r.content)
assert doc('.context a')[1].attrib['href'].endswith(
assert doc('.account.anonymous a')[1].attrib['href'].endswith(
'?to=%2Fen-US%2Ffirefox%2F%3Fyour%3Dmom'), ("Got %s" %
doc('.context a')[1].attrib['href'])
doc('.account.anonymous a')[1].attrib['href'])
r = test.Client().get('/en-US/firefox/search/?q=%B8+%EB%B2%88%EC%97%A')
r = test.Client().get('/ar/firefox/?q=%B8+%EB%B2%88%EC%97%A')
doc = pq(r.content)
link = doc('.context a')[1].attrib['href']
assert link.endswith('?to=%2Fen-US%2Ffirefox%2Fsearch%2F%3Fq%3D%25EF'
link = doc('.account.anonymous a')[1].attrib['href']
assert link.endswith('?to=%2Far%2Ffirefox%2F%3Fq%3D%25EF'
'%25BF%25BD%2B%25EB%25B2%2588%25EF%25BF%25BDA'), "Got %s" % link
test_login_link.py27unicode = True

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

@ -18,7 +18,6 @@ import amo
import amo.tests
from amo.urlresolvers import reverse
from amo.helpers import urlparams
from addons.cron import reset_featured_addons
from addons.tests.test_views import TestMobile
from addons.models import (Addon, AddonCategory, Category, AppSupport, Feature,
Persona)
@ -365,9 +364,7 @@ class TestFeaturedLocale(amo.tests.TestCase):
def reset(self):
cache.clear()
FeaturedManager.redis().flushall()
reset_featured_addons()
FeaturedManager.featured_ids.clear()
CreaturedManager.creatured_ids.clear()
self.reset_featured_addons()
def list_featured(self, content):
# Not sure we want to get into testing randomness
@ -492,18 +489,18 @@ class TestFeaturedLocale(amo.tests.TestCase):
def test_homepage(self):
url = reverse('home')
res = self.client.get(url)
assert self.extension in res.context['filter'].filter('featured')
assert self.extension in res.context['featured']
self.change_addon(self.extension, 'es-ES')
res = self.client.get(url)
assert self.extension not in res.context['filter'].filter('featured')
assert self.extension not in res.context['featured']
res = self.client.get(url.replace('en-US', 'es-ES'))
assert self.extension in res.context['filter'].filter('featured')
assert self.extension in res.context['featured']
def test_homepage_persona(self):
res = self.client.get(reverse('home'))
assert self.persona not in res.context['filter'].filter('featured')
assert self.persona not in res.context['featured']
def test_homepage_filter(self):
# Ensure that the base homepage filter is applied.
@ -513,7 +510,7 @@ class TestFeaturedLocale(amo.tests.TestCase):
.exclude(type=amo.ADDON_PERSONA)]
featured = Addon.featured_random(amo.FIREFOX, 'en-US')
actual = [p.pk for p in res.context['filter'].filter('featured')]
actual = [p.pk for p in res.context['featured']]
eq_(sorted(actual), sorted(set(listed) & set(featured)))
@ -537,22 +534,23 @@ class TestFeaturedLocale(amo.tests.TestCase):
# The order should be random within those boundaries.
another = Addon.objects.get(id=1003)
self.change_addon(another, 'en-US')
self.reset_featured_addons()
url = reverse('home')
res = self.client.get(url)
items = res.context['addon_sets']['featured']
items = res.context['featured']
eq_([1003, 3481], sorted([i.pk for i in items[0:2]]))
eq_([2464, 7661], sorted([i.pk for i in items[2:]]))
res = self.client.get(url.replace('en-US', 'es-ES'))
items = res.context['filter'].filter('featured')
items = res.context['featured']
eq_([2464, 7661], sorted([i.pk for i in items]))
self.change_addon(another, 'es-ES')
res = self.client.get(url.replace('en-US', 'es-ES'))
items = res.context['filter'].filter('featured')
items = res.context['featured']
eq_(items[0].pk, 1003)
eq_([1003, 2464, 7661], sorted([i.pk for i in items]))
@ -586,7 +584,7 @@ class TestNewFeaturedLocale(TestFeaturedLocale):
super(TestNewFeaturedLocale, self).setUp()
patcher = mock.patch.object(settings, 'NEW_FEATURES', True)
patcher.start()
reset_featured_addons()
self.reset_featured_addons()
self.addCleanup(patcher.stop)
def test_featured_random_caching(self):
@ -627,7 +625,7 @@ class TestNewFeaturedLocale(TestFeaturedLocale):
# TODO(cvan): Change the TestFeaturedLocale test
# accordingly after we switch over to the new features.
FeaturedCollection.objects.filter(collection__addons=3615)[0].delete()
super(TestNewFeaturedLocale, self).test_featured_ids()
super(TestNewFeaturedLocale, self).test_homepage_order()
def test_creatured_locale_es_ES(self):
"""Ensure 'en-US'-creatured add-ons do not exist for other locales."""
@ -738,7 +736,7 @@ class BaseSearchToolsTest(amo.tests.TestCase):
s.addoncategory_set.add(AddonCategory(addon=limon, feature=True))
s.addoncategory_set.add(AddonCategory(addon=readit, feature=True))
s.save()
reset_featured_addons()
self.reset_featured_addons()
class TestSearchToolsPages(BaseSearchToolsTest):

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

@ -30,11 +30,14 @@ class CakeTestCase(TestCase):
Given a known remora cookie, can we visit the homepage and appear
logged in?
"""
profile = UserProfile.objects.get(pk=1)
# log in using cookie -
client = self.client
client.cookies['AMOv3'] = "17f051c99f083244bf653d5798111216"
response = client.get('/en-US/firefox/')
self.assertContains(response, 'Welcome, Scott')
r = client.get('/en-US/firefox/')
eq_(pq(r.content.decode('utf-8'))('.account .user').text(),
profile.display_name)
eq_(pq(r.content)('.account .user').attr('title'), profile.email)
# test that the data copied over correctly.
profile = UserProfile.objects.get(pk=1)
@ -93,13 +96,16 @@ class CakeTestCase(TestCase):
# login with a cookie and verify we are logged in
client = self.client
client.cookies['AMOv3'] = "17f051c99f083244bf653d5798111216"
response = client.get('/en-US/firefox/')
self.assertContains(response, 'Welcome, Scott')
r = client.get('/en-US/firefox/')
profile = UserProfile.objects.get(pk=1)
eq_(pq(r.content.decode('utf-8'))('.account .user').text(),
profile.display_name)
eq_(pq(r.content)('.account .user').attr('title'), profile.email)
# logout and verify we are logged out and our AMOv3 cookie is gone
response = client.get('/en-US/firefox/users/logout')
response = client.get('/en-US/firefox/')
r = client.get('/en-US/firefox/users/logout')
r = client.get('/en-US/firefox/')
assert isinstance(response.context['user'], AnonymousUser)
assert isinstance(r.context['user'], AnonymousUser)
self.assertEqual(client.cookies.get('AMOv3').value, '')
@patch('django.db.models.fields.related.'

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

@ -14,8 +14,8 @@ class TestManagement(amo.tests.TestCase):
def test_tags_details_view(self):
"""Test that there are some tags being shown on the details page."""
url = reverse('addons.detail', args=['a3615'])
r = self.client.get(url)
url = reverse('addons.detail_more', args=['a3615'])
r = self.client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
doc = pq(r.content)
eq_(len(doc('li.tag')), 4)
assert 'Tags' in [d.text for d in doc('h3')]
@ -36,8 +36,8 @@ class TestXSS(amo.tests.TestCase):
def test_tags_xss_detail(self):
"""Test xss tag detail."""
url = reverse('addons.detail', args=['a3615'])
r = self.client.get(url)
url = reverse('addons.detail_more', args=['a3615'])
r = self.client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
doc = pq(r.content)
eq_(doc('li.tag')[0].text_content().strip(), self.xss)
@ -64,8 +64,8 @@ class TestXSSURLFail(amo.tests.TestCase):
def test_tags_xss(self):
"""Test xss tag detail."""
url = reverse('addons.detail', args=['a3615'])
r = self.client.get(url)
url = reverse('addons.detail_more', args=['a3615'])
r = self.client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
doc = pq(r.content)
eq_(doc('li.tag')[0].text_content().strip(), self.xss)

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

@ -9,6 +9,7 @@ from django.utils.http import int_to_base36
from manage import settings
from mock import Mock, patch
from nose.tools import eq_
from pyquery import PyQuery as pq
import amo
import amo.tests
@ -242,16 +243,20 @@ class TestUserLoginForm(UserFormBase):
"fields are case-sensitive."))
def test_credential_success(self):
user = UserProfile.objects.get(email='jbalogh@mozilla.com')
url = self._get_login_url()
r = self.client.post(url, {'username': 'jbalogh@mozilla.com',
r = self.client.post(url, {'username': user.email,
'password': 'foo'}, follow=True)
self.assertContains(r, "Welcome, Jeff Balogh")
self.assertTrue(self.client.session.get_expire_at_browser_close())
eq_(pq(r.content.decode('utf-8'))('.account .user').text(),
user.display_name)
eq_(pq(r.content)('.account .user').attr('title'), user.email)
r = self.client.post(url, {'username': 'jbalogh@mozilla.com',
r = self.client.post(url, {'username': user.email,
'password': 'foo',
'rememberme': 1}, follow=True)
self.assertContains(r, "Welcome, Jeff Balogh")
eq_(pq(r.content.decode('utf-8'))('.account .user').text(),
user.display_name)
eq_(pq(r.content)('.account .user').attr('title'), user.email)
# Subtract 100 to give some breathing room
age = settings.SESSION_COOKIE_AGE - 100
assert self.client.session.get_expiry_age() > age

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

@ -455,13 +455,15 @@ class TestReset(UserViewBase):
class TestLogout(UserViewBase):
def test_success(self):
self.client.login(username='jbalogh@mozilla.com', password='foo')
user = UserProfile.objects.get(email='jbalogh@mozilla.com')
self.client.login(username=user.email, password='foo')
r = self.client.get('/', follow=True)
self.assertContains(r, "Welcome, Jeff")
eq_(pq(r.content.decode('utf-8'))('.account .user').text(),
user.display_name)
eq_(pq(r.content)('.account .user').attr('title'), user.email)
r = self.client.get('/users/logout', follow=True)
self.assertNotContains(r, "Welcome, Jeff")
self.assertContains(r, "Log in")
assert not pq(r.content)('.account .user')
def test_redirect(self):
self.client.login(username='jbalogh@mozilla.com', password='foo')

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

@ -63,8 +63,6 @@ CACHE_BACKEND = 'caching.backends.locmem://'
CELERY_ALWAYS_EAGER = True
ADDONS_PATH = '/tmp/warez'
STATIC_URL = ''
IMPALA_HOMEPAGE = False
IMPALA_ADDON_DETAILS = False
TEST_SPHINX_CATALOG_PATH = TMP_PATH + '/$1/data/sphinx'
TEST_SPHINX_LOG_PATH = TMP_PATH + '/$1/log/serachd'