Clean up URL prefixers for each test (bug 560541).
This commit is contained in:
Родитель
08d93fb7ef
Коммит
db5afb8445
|
@ -60,11 +60,6 @@ class TestHomepage(test_utils.TestCase):
|
|||
class TestDetailPage(test_utils.TestCase):
|
||||
fixtures = ['base/addons', 'addons/listed', 'addons/persona']
|
||||
|
||||
def tearDown(self):
|
||||
"""Return URL prefixer to default."""
|
||||
prefixer = amo.urlresolvers.get_url_prefix()
|
||||
prefixer.app = settings.DEFAULT_APP
|
||||
|
||||
def test_anonymous_user(self):
|
||||
"""Does the page work for an anonymous user?"""
|
||||
# extensions
|
||||
|
|
|
@ -6,6 +6,12 @@ import caching.base
|
|||
from translations.fields import TranslatedFieldMixin
|
||||
from translations import transformer
|
||||
|
||||
from .signals import register_signals
|
||||
|
||||
|
||||
# Register Django signals this app listens to.
|
||||
register_signals()
|
||||
|
||||
|
||||
class TransformQuerySet(queryset_transform.TransformQuerySet):
|
||||
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
from django import http
|
||||
from django.conf import settings
|
||||
|
||||
import test_utils.signals
|
||||
|
||||
from . import urlresolvers
|
||||
|
||||
|
||||
def register_signals():
|
||||
"""
|
||||
Register signal handlers.
|
||||
Called from models.py to make sure Django finds it.
|
||||
"""
|
||||
# Clean up URL prefix cache when a new test is invoked.
|
||||
test_utils.signals.pre_setup.connect(default_prefixer)
|
||||
test_utils.signals.post_teardown.connect(clean_url_prefixes)
|
||||
|
||||
|
||||
def clean_url_prefixes(sender, **kwargs):
|
||||
"""Wipe the URL prefixer(s) after each test."""
|
||||
urlresolvers.clean_url_prefixes()
|
||||
|
||||
|
||||
def default_prefixer(sender, **kwargs):
|
||||
"""Make sure each test starts with a default URL prefixer."""
|
||||
request = http.HttpRequest()
|
||||
request.META['SCRIPT_NAME'] = ''
|
||||
prefixer = urlresolvers.Prefixer(request)
|
||||
prefixer.app = settings.DEFAULT_APP
|
||||
prefixer.locale = settings.LANGUAGE_CODE
|
||||
urlresolvers.set_url_prefix(prefixer)
|
|
@ -24,6 +24,11 @@ def get_url_prefix():
|
|||
return _prefixes.get(currentThread())
|
||||
|
||||
|
||||
def clean_url_prefixes():
|
||||
"""Purge prefix cache."""
|
||||
_prefixes.clear()
|
||||
|
||||
|
||||
def get_app_redirect(app):
|
||||
"""Redirect request to another app."""
|
||||
prefixer = get_url_prefix()
|
||||
|
|
|
@ -30,11 +30,11 @@ def test_reviews_link():
|
|||
eq_(PyQuery(s)('strong').text(), '37 reviews')
|
||||
|
||||
# without collection uuid
|
||||
eq_(PyQuery(s)('a').attr('href'), '/en-US/firefox/addon/1/#reviews')
|
||||
eq_(PyQuery(s)('a').attr('href'), '/addon/1/#reviews')
|
||||
|
||||
# with collection uuid
|
||||
myuuid = 'f19a8822-1ee3-4145-9440-0a3640201fe6'
|
||||
s = render('{{ myaddon|reviews_link(myuuid) }}', {'myaddon': a,
|
||||
'myuuid': myuuid})
|
||||
eq_(PyQuery(s)('a').attr('href'),
|
||||
'/en-US/firefox/addon/1/?collection_uuid=%s#reviews' % myuuid)
|
||||
'/addon/1/?collection_uuid=%s#reviews' % myuuid)
|
||||
|
|
|
@ -64,5 +64,5 @@ class TestFlagged(test_utils.TestCase):
|
|||
|
||||
def test_settings():
|
||||
# Are you there, settings page?
|
||||
response = test.Client().get(reverse('zadmin.settings'))
|
||||
response = test.Client().get(reverse('zadmin.settings'), follow=True)
|
||||
eq_(response.status_code, 200)
|
||||
|
|
Загрузка…
Ссылка в новой задаче