Commit 5fbcc1ac authored by Nicolas Joyard's avatar Nicolas Joyard
Browse files

Add sorting tests

parent fafdd052
<!DOCTYPE html>
<html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8" />
<link rel="icon" type="image/png" href="/static/collected/img/favicon.ico" />
<!-- Set the viewport width to device width for mobile -->
<meta name="viewport" content="width=device-width" />
<title>
Home
- The Political Memory of </title>
<link rel="stylesheet" href="/static/collected/libs/bootstrap/dist/css/bootstrap.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/fontawesome/css/font-awesome.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/flag-icon-css/css/flag-icon.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/CACHE/css/base.586b8f5e9bff.css" type="text/css" />
<script type="text/javascript" src="/static/collected/libs/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="/static/collected/libs/bootstrap/dist/js/bootstrap.js"></script>
</head>
<body >
<!-- -load memopol_tags cache -->
<div id='header' class='container-fluid'>
<a id='logo' href='/'>
<img src='/static/collected/images/logo.png' />
</a>
<h1>
<a id='header_banner' href='/'>
Political Memory
</a>
</h1>
<p class='organization'>
</p>
</div>
<div id='nav' class='container-fluid'>
<ul class='nav'>
<li>
<a href='/legislature/representative/'>
Representatives
</a>
</li>
<li>
<a href='/legislature/group/country/'>
Countries
</a>
</li>
<li>
<a href='/legislature/group/chamber/'>
Chambers
</a>
</li>
<li>
<a href='/legislature/group/group/'>
Parties
</a>
</li>
<li>
<a href='/legislature/group/delegation/'>
Delegations
</a>
</li>
<li>
<a href='/legislature/group/committee/'>
Committees
</a>
</li>
<li>
<a href='/votes/dossier/'>
Dossiers
</a>
</li>
</ul>
</div>
<div class="container-fluid main-container">
<form class='filter-form' action='/votes/dossier/' method='get'>
<div class="form-group has-success"><label class="control-label" for="id_search">Search</label><input class="form-control" id="id_search" name="search" placeholder="Search" title="Filter" type="text" /><span class="help-block">Filter
</span></div>
<div class="form-group has-success"><label class="control-label" for="id_chamber">Chamber</label><select class="form-control" id="id_chamber" name="chamber" title="Filter">
<option value="" selected="selected">---------</option>
<option value="1">European Parliament [EP]</option>
</select><span class="help-block">Filter
</span></div>
<div class="form-group">
<button class='btn btn-primary' type='submit'>
<span class="glyphicon glyphicon-filter"></span> Filter
</button>
</div>
</form>
<div class='pagination-block'>
<nav>
<ul class='pagination pagination-sm'>
</ul>
</nav>
<div class='count'>
<div class='count-block'>
Number of results : 1
</div>
<div class='sorting-block'>
Order by :
<a href='?&sort_by=nb_proposals'>proposals</a>
|
<a href='?&sort_by=nb_recomm'>recommendations</a>
|
<a href='?&sort_by=reference'>reference</a>
|
title
&ndash;
<a href='?&sort_dir=asc'>ascending</a>
| descending
</div>
<div class='page-size-block'>
Number of displayed results :
12
(
<a href='?&paginate_by=12'>12</a>
/
<a href='?&paginate_by=24'>24</a>
/
<a href='?&paginate_by=48'>48</a>
/
<a href='?&paginate_by=96'>96</a>
)
</div>
</div>
</div>
<h1>
Dossiers
</h1>
<table class='table'>
<tr>
<th>
Chambers
</th>
<th>
Title
</th>
<th>
Recommendations
</th>
<th>
Proposals
</th>
<th>
Reference
</th>
</tr>
<tr>
<td>
<span class="chamber-icon" style="background-image: url(/static/collected/images/chamber-ep.png)" title="European Parliament"></span>
</td>
<td>
<a href='/votes/dossier/28147/'>
Resolution on the Anti-Counterfeiting Trade Agreement (ACTA)
</a>
</td>
<td>3</td>
<td>3</td>
<td>2010/2935(RSP)</td>
</tr>
</table>
<div class='pagination-block'>
<nav>
<ul class='pagination pagination-sm'>
</ul>
</nav>
<div class='count'>
<div class='count-block'>
Number of results : 1
</div>
<div class='sorting-block'>
Order by :
<a href='?&sort_by=nb_proposals'>proposals</a>
|
<a href='?&sort_by=nb_recomm'>recommendations</a>
|
<a href='?&sort_by=reference'>reference</a>
|
title
&ndash;
<a href='?&sort_dir=asc'>ascending</a>
| descending
</div>
<div class='page-size-block'>
Number of displayed results :
12
(
<a href='?&paginate_by=12'>12</a>
/
<a href='?&paginate_by=24'>24</a>
/
<a href='?&paginate_by=48'>48</a>
/
<a href='?&paginate_by=96'>96</a>
)
</div>
</div>
</div>
</div>
<div id='footer' class='container-fluid'>
<div class='license-links'>
Memopol is
<a href='https://github.com/political-memory/political_memory'>free software</a>
released under the terms of the
<a href='http://www.gnu.org/licenses/agpl.html'>GNU aGPLV3+</a>
</div>
<div class='footer-link'>
<a href='https://github.com/political-memory/political_memory/issues/new'>Report a bug</a>
</div>
<div class='footer-link'>
<a href='http://www.memopol.org/'>Blog</a>
</div>
<div class='footer-link'>
<a href='http://memopol.readthedocs.io/en/master/'>Documentation</a>
</div>
<div class='footer-separator'></div>
<div class='footer-link'>
Developed by
<a href='http://www.laquadrature.net/'>La Quadrature du Net</a>
</div>
<div class='footer-link'>
EP data provided by
<a href='http://parltrack.euwiki.org/'>Parltrack</a>
</div>
</div>
</body>
</html>
......@@ -47,6 +47,19 @@ class DossiersTest(ResponseDiffMixin, TestCase):
q = 'no-dossier-will-have-that-title-ever'
self.responsediff_test('/votes/dossier/?search=%s' % q, 2)
def test_dossier_sorting(self):
# session setup
self.client.get('/votes/dossier/?sort_by=title&sort_dir=desc')
# 1 query for chamber list (search form)
# 1 query for dossier count
# 1 query for dossiers
# 1 query for proposals
# 1 query for recommendations
# 1 query for documents
# 1 query for document chambers
self.responsediff_test('/votes/dossier/', 7)
def test_dossier_detail(self):
# Get 1st dossier in dataset
dossier = Dossier.objects.order_by('pk')[0]
......
......@@ -66,6 +66,18 @@ class RepresentativeListTest(UrlGetTestMixin, TestCase):
expected = Response.for_test(self)
expected.assertNoDiff(self.response)
def sorting_test(self, num_queries, field='', dir=''):
url = '%s?sort_by=%s&sort_dir=%s' % (self.url, field, dir)
# Cancel out one-time queries (session)
self.client.get('%s&paginate_by=12&active_only=1' % url)
with self.assertNumQueries(num_queries):
self.response = self.client.get(self.url)
expected = Response.for_test(self)
expected.assertNoDiff(self.response)
def test_page1_paginateby12_active_displaylist(self):
self.functional_test(1, 12, 1, 'list')
......@@ -137,3 +149,13 @@ class RepresentativeListTest(UrlGetTestMixin, TestCase):
(as the first count query returns 0)
"""
self.filter_test(3, 'non-existing-rep-name')
def test_sorting(self):
"""
- A count for pagination
- One query for chambers (filters)
- One query for countries (filters)
- One query for representative + score
- One query for mandates (including country + main_mandate)
"""
self.sorting_test(5, 'score', 'desc')
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