From 1a0fcce39dcea33237d33de2b8d29c0ad4f43951 Mon Sep 17 00:00:00 2001 From: Nicolas Joyard <joyard.nicolas@gmail.com> Date: Wed, 8 Jun 2016 08:22:41 +0200 Subject: [PATCH] Add tests for dossier views --- memopol/tests/base.py | 15 ++ .../DossiersTest.test_dossier_detail/content | 192 ++++++++++++++++++ .../DossiersTest.test_dossier_list/content | 182 +++++++++++++++++ memopol/tests/test_dossiers.py | 27 +++ memopol/tests/test_group_list.py | 15 +- 5 files changed, 419 insertions(+), 12 deletions(-) create mode 100644 memopol/tests/response_fixtures/DossiersTest.test_dossier_detail/content create mode 100644 memopol/tests/response_fixtures/DossiersTest.test_dossier_list/content create mode 100644 memopol/tests/test_dossiers.py diff --git a/memopol/tests/base.py b/memopol/tests/base.py index 1c4fe97b..8075a3bd 100644 --- a/memopol/tests/base.py +++ b/memopol/tests/base.py @@ -3,6 +3,8 @@ import os.path from django.test import Client +from responsediff.response import Response + class UrlGetTestMixin(object): url = None @@ -35,3 +37,16 @@ class UrlGetTestMixin(object): with open(expected, 'r') as f: self.assertHtmlInResult(f.read()) + + +class ResponseDiffMixin(object): + + def responsediff_test(self, url, numQueries): + # Setup session variables + self.client.get(url) + + with self.assertNumQueries(numQueries): + response = self.client.get(url) + + expected = Response.for_test(self) + expected.assertNoDiff(response) diff --git a/memopol/tests/response_fixtures/DossiersTest.test_dossier_detail/content b/memopol/tests/response_fixtures/DossiersTest.test_dossier_detail/content new file mode 100644 index 00000000..0f0f6ae3 --- /dev/null +++ b/memopol/tests/response_fixtures/DossiersTest.test_dossier_detail/content @@ -0,0 +1,192 @@ +<!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.3c5ffeab3cbf.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"> + + + <h1> Resolution on the Anti-Counterfeiting Trade Agreement (ACTA)</h1> + <p> + <strong>2010/2935(RSP)</strong> + + </p> + <h2> + Recommendations + + </h2> + <table class='table'> + <tr> + <th> + Proposal + </th> + <th> + Title + </th> + <th> + Recommendation + </th> + <th> + Status + </th> + <th><i aria-label="for" class="fa fa-thumbs-up vote_positive" title="for" ></i></th> + <th><i aria-label="against" class="fa fa-thumbs-down vote_negative" title="against" ></i></th> + <th><i aria-label="abstain" class="fa fa-circle-o vote_abstain" title="abstain" ></i></th> + + </tr> + + <tr> + <td> + RC-B7-0617/2010 - Accord commercial anti-contrefaçon (ACAC) - Considérant X + <br /> + <small> + B7-0617/2010 + Considérant X + </small> + </td> + <td>Stop acta !</td> + <td><i aria-label="for" class="fa fa-thumbs-up vote_positive" title="for" ></i></td> + <td>adopted</td> + <td>329</td> + <td>249</td> + <td>75</td> + + + </tr> + + <tr> + <td> + RC-B7-0617/2010 - Accord commercial anti-contrefaçon (ACAC) - Considérant CC + <br /> + <small> + B7-0617/2010 + Considérant CC + </small> + </td> + <td>Stop acta !</td> + <td><i aria-label="for" class="fa fa-thumbs-up vote_positive" title="for" ></i></td> + <td>adopted</td> + <td>315</td> + <td>312</td> + <td>14</td> + + + </tr> + + <tr> + <td> + RC-B7-0617/2010 - Accord commercial anti-contrefaçon (ACAC) - Résolution + <br /> + <small> + B7-0617/2010 + Résolution + </small> + </td> + <td>Stop acta !</td> + <td><i aria-label="for" class="fa fa-thumbs-up vote_positive" title="for" ></i></td> + <td>rejected</td> + <td>306</td> + <td>322</td> + <td>26</td> + + + </tr> + + </table> + + </div> + + +<div id='footer' class='container-fluid'> + + Memopol is free software + <a href="https://github.com/political-memory/political_memory">released</a> + under the terms of the + <a href="http://www.gnu.org/licenses/agpl.html">GNU aGPLV3+</a> + + <a href='https://github.com/political-memory/political_memory/issues'> + Bug tracking system + </a> + <a href='https://github.com/political-memory/political_memory/issues/new'> + Report a bug + </a> + <br /> + Provided by <a href="http://www.laquadrature.net/">La Quadrature du Net</a> + +</div> + + </body> +</html> diff --git a/memopol/tests/response_fixtures/DossiersTest.test_dossier_list/content b/memopol/tests/response_fixtures/DossiersTest.test_dossier_list/content new file mode 100644 index 00000000..5bc66b59 --- /dev/null +++ b/memopol/tests/response_fixtures/DossiersTest.test_dossier_list/content @@ -0,0 +1,182 @@ +<!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.3c5ffeab3cbf.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"> + + <h1> + Dossiers + + </h1> + <table class='table'> + <tr> + <th> + Title + </th> + <th> + Recommendations + </th> + <th> + Reference + + </th> + </tr> + + <tr> + <td> + <a href='/votes/dossier/28147/'> + Resolution on the Anti-Counterfeiting Trade Agreement (ACTA) + </a> + </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'> + Number of results : 1 + <br /> + 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 id='footer' class='container-fluid'> + + Memopol is free software + <a href="https://github.com/political-memory/political_memory">released</a> + under the terms of the + <a href="http://www.gnu.org/licenses/agpl.html">GNU aGPLV3+</a> + + <a href='https://github.com/political-memory/political_memory/issues'> + Bug tracking system + </a> + <a href='https://github.com/political-memory/political_memory/issues/new'> + Report a bug + </a> + <br /> + Provided by <a href="http://www.laquadrature.net/">La Quadrature du Net</a> + +</div> + + </body> +</html> diff --git a/memopol/tests/test_dossiers.py b/memopol/tests/test_dossiers.py new file mode 100644 index 00000000..f87a49fd --- /dev/null +++ b/memopol/tests/test_dossiers.py @@ -0,0 +1,27 @@ +# -*- coding: utf8 -*- + +from django.test import TestCase + +from representatives_votes.models import Dossier + +from .base import ResponseDiffMixin + + +class DossiersTest(ResponseDiffMixin, TestCase): + fixtures = ['smaller_sample.json'] + + def test_dossier_list(self): + # 1 query for dossier count + # 1 query for dossiers + # 1 query for proposals + # 1 query for recommendations + self.responsediff_test('/votes/dossier/', 4) + + def test_dossier_detail(self): + # Get 1st dossier in dataset + dossier = Dossier.objects.order_by('pk')[0] + + # 1 query for the dossier + # 1 query for proposals + # 1 query for recommendations + self.responsediff_test('/votes/dossier/%s/' % dossier.pk, 3) diff --git a/memopol/tests/test_group_list.py b/memopol/tests/test_group_list.py index 3f320a0c..ba8d19a4 100644 --- a/memopol/tests/test_group_list.py +++ b/memopol/tests/test_group_list.py @@ -2,23 +2,14 @@ from django.test import TestCase -from responsediff.response import Response +from .base import ResponseDiffMixin -class GroupListTest(TestCase): +class GroupListTest(ResponseDiffMixin, TestCase): fixtures = ['smaller_sample.json'] def group_test(self, kind, numQueries): - url = '/legislature/group/%s/' % kind - - # Setup session variables - self.client.get(url) - - with self.assertNumQueries(numQueries): - response = self.client.get(url) - - expected = Response.for_test(self) - expected.assertNoDiff(response) + self.responsediff_test('/legislature/group/%s/' % kind, numQueries) def test_chambers(self): # 1 query for chambers -- GitLab