Commit 5553bbfe authored by Nicolas Joyard's avatar Nicolas Joyard

Fix tests and add custom header tests

parent f1d6180d
......@@ -99,6 +99,10 @@ MIDDLEWARE_CLASSES = (
'django.contrib.sites.middleware.CurrentSiteMiddleware',
)
if 'debug_toolbar' in INSTALLED_APPS:
MIDDLEWARE_CLASSES += (
'debug_toolbar.middleware.DebugToolbarMiddleware',
)
#
# Sessions
#
......
......@@ -8,6 +8,7 @@ class BaseTest(ResponseDiffTestMixin, test.TestCase):
"""
Common queries
- 1 for settings
- 5 for search forms
- 1 for chambers
- 1 for countries
......@@ -18,7 +19,7 @@ class BaseTest(ResponseDiffTestMixin, test.TestCase):
- 1 for representatives
- 1 for themes
"""
left_pane_queries = 7
left_pane_queries = 8
def setUp(self):
RepresentativeScore.refresh()
......
from .base import BaseTest
class NavigationPaneTest(BaseTest):
url = '/'
def test_queries(self):
# First query to set session variables
self.client.get(self.url)
with self.assertNumQueries(self.left_pane_queries):
self.client.get(self.url)
def test_rep_search_chambers(self):
self.selector_test('#form-rep #chamber-rep option')
def test_rep_search_countries(self):
self.selector_test('#form-rep #country option')
def test_rep_search_parties(self):
self.selector_test('#form-rep #party option')
def test_rep_search_committee(self):
self.selector_test('#form-rep #committee option')
def test_rep_search_delegation(self):
self.selector_test('#form-rep #delegation option')
def test_dossier_search_chambers(self):
self.selector_test('#form-dossier #chamber-dossier option')
......@@ -29,6 +29,7 @@ class HomeView(PositionFormMixin, RepresentativeViewMixin,
qs = qs.filter(Q(representative_score__score__lt=0) |
Q(representative_score__score__gt=0))
qs = self.prefetch_for_representative_country_and_main_mandate(qs)
qs = qs.select_related('representative_score')
random.seed(datetime.date.today().isoformat())
index = random.randint(0, qs.count() - 1)
......@@ -52,6 +53,9 @@ class HomeView(PositionFormMixin, RepresentativeViewMixin,
num = int(Setting.objects.get(pk='HOMEPAGE_LATEST_VOTES').value)
c['latest_votes'] = Proposal.objects \
.filter(recommendation__isnull=False) \
.select_related('dossier', 'recommendation') \
.prefetch_related('themes', 'dossier__themes',
'dossier__documents__chamber') \
.order_by('-datetime')[0:num]
return c
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment