Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Allow passing a SITE_ID header to request a specific site. Most usefu…
Browse files Browse the repository at this point in the history
…l for tests. Bug 609154.
  • Loading branch information
Fred Wenzel committed Nov 10, 2010
1 parent aad142c commit bced1a9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
9 changes: 4 additions & 5 deletions apps/dashboard/tests.py
@@ -1,5 +1,7 @@
from nose.tools import eq_

from django.conf import settings

from jingo import register
import jinja2
import test_utils
Expand All @@ -21,12 +23,9 @@ def test_dashboard(self):


class TestMobileDashboard(test_utils.TestCase):
def setUp(self):
from django.conf import settings
settings.SITE_ID = 2

def test_dashboard(self):
r = self.client.get(reverse('dashboard'), follow=True)
r = self.client.get(reverse('dashboard'), follow=True,
SITE_ID=settings.MOBILE_SITE_ID)
eq_(r.status_code, 200)


Expand Down
19 changes: 19 additions & 0 deletions apps/feedback/tests.py
Expand Up @@ -2,12 +2,14 @@

from django import http
from django.conf import settings
from django.contrib.sites.models import Site
from django.core.exceptions import ValidationError
from django.test import TestCase
from input.urlresolvers import reverse

from nose.tools import eq_
from product_details import product_details
from pyquery import pyquery

from . import FIREFOX, MOBILE
from .utils import detect_language, ua_parse, smart_truncate
Expand Down Expand Up @@ -223,3 +225,20 @@ def test_submissions_without_url(self):
# Neither valid nor invalid URLs cause anything but a 200 response.
eq_(r.status_code, 200)
assert r.content.find('Thanks') >= 0

def test_submission_autocomplete_off(self):
"""
Ensure both mobile and desktop submission pages have autocomplete off.
"""
def autocomplete_check(site_id):
r = self.client.get(reverse('feedback.sad'), HTTP_USER_AGENT=(
self.FX_UA % '20.0'), SITE_ID=site_id, follow=True)
doc = pyquery.PyQuery(r.content)
form = doc('#feedbackform form')

assert form
eq_(form.attr('autocomplete'), 'off')
print r

autocomplete_check(settings.DESKTOP_SITE_ID)
autocomplete_check(settings.MOBILE_SITE_ID)
10 changes: 8 additions & 2 deletions apps/input/middleware.py
Expand Up @@ -78,8 +78,14 @@ def process_request(self, request):
''.join((settings.CACHE_PREFIX, 'dom:', domain)),
settings.CACHE_COUNT_TIMEOUT)
except (Site.DoesNotExist, KeyError):
# Serve Desktop site.
settings.SITE_ID = settings.DESKTOP_SITE_ID
# If Site ID picked in header, serve that, otherwise default
# to Desktop site.
site_header = request.META.get('SITE_ID')
if site_header in (settings.DESKTOP_SITE_ID,
settings.MOBILE_SITE_ID):
settings.SITE_ID = site_header
else:
settings.SITE_ID = settings.DESKTOP_SITE_ID
else:
settings.SITE_ID = site.id

Expand Down
1 change: 0 additions & 1 deletion apps/input/tests.py
Expand Up @@ -78,7 +78,6 @@ def test_locale_fallback(self):
eq_(res.status_code, 301)
self.assertTrue(res['Location'].rstrip('/').endswith(pattern[1]))


def test_mobilesite_nohost(self):
"""Make sure we serve the desktop site if there's no HTTP_HOST set."""
# This won't contain HTTP_HOST. Must not fail.
Expand Down
2 changes: 1 addition & 1 deletion apps/search/tests.py
Expand Up @@ -37,7 +37,7 @@ def setUp(self):
super(SphinxTestCase, self).setUp()

from django.conf import settings
settings.SITE_ID = 1
settings.SITE_ID = settings.DESKTOP_SITE_ID

if not SphinxTestCase.sphinx_is_running:
if (not settings.SPHINX_SEARCHD or
Expand Down

0 comments on commit bced1a9

Please sign in to comment.