Commit 0f93fb46 authored by Nicolas Joyard's avatar Nicolas Joyard Committed by Nicolas Joyard
Browse files

Use django_perf_rec for db queries and cache

parent 50fe62c7
ParltrackVotesTest.test_parltrack_import_single_dossier:
- db: 'SELECT ... FROM "representatives_chamber" WHERE "representatives_chamber"."abbreviation" = #'
- db: SAVEPOINT `#`
- db: 'SELECT ... FROM "representatives_votes_dossier" WHERE "representatives_votes_dossier"."reference" = #'
- db: INSERT INTO "representatives_votes_dossier" (...) VALUES (...) RETURNING "representatives_votes_dossier"."id"
- db: 'SELECT ... FROM "representatives_votes_document" WHERE ("representatives_votes_document"."dossier_id" = # AND "representatives_votes_document"."kind" = #)'
- db: INSERT INTO "representatives_votes_document" (...) VALUES (...) RETURNING "representatives_votes_document"."id"
- db: RELEASE SAVEPOINT `#`
- db: 'SELECT ... FROM "representatives_representative" INNER JOIN "representatives_website" ON ( "representatives_representative"."id" = "representatives_website"."representative_id" ) WHERE "representatives_website"."kind" = # ORDER BY ...'
- db: SELECT ... FROM "representatives_votes_dossier"
- db: SAVEPOINT `#`
- db: 'SELECT ... FROM "representatives_votes_proposal" WHERE "representatives_votes_proposal"."title" = #'
- db: INSERT INTO "representatives_votes_proposal" (...) VALUES (...) RETURNING "representatives_votes_proposal"."id"
- db: 'SELECT ... FROM "representatives_votes_vote" WHERE ("representatives_votes_vote"."proposal_id" = # AND "representatives_votes_vote"."representative_id" = #)'
- db: INSERT INTO "representatives_votes_vote" (...) VALUES (...) RETURNING "representatives_votes_vote"."id"
- db: 'SELECT ... FROM "representatives_votes_vote" WHERE ("representatives_votes_vote"."proposal_id" = # AND "representatives_votes_vote"."representative_id" = #)'
- db: INSERT INTO "representatives_votes_vote" (...) VALUES (...) RETURNING "representatives_votes_vote"."id"
- db: RELEASE SAVEPOINT `#`
- db: 'SELECT ... FROM "representatives_votes_dossier" WHERE "representatives_votes_dossier"."reference" = #'
- db: 'SELECT ... FROM "representatives_votes_dossier" WHERE ("representatives_votes_dossier"."reference" = # AND "representatives_votes_dossier"."text" = # AND "representatives_votes_dossier"."title" = #)'
- db: 'SELECT ... FROM "representatives_votes_dossier" WHERE "representatives_votes_dossier"."reference" = #'
- db: 'SELECT ... FROM "representatives_chamber" WHERE "representatives_chamber"."abbreviation" = #'
- db: 'SELECT ... FROM "representatives_votes_document" WHERE ("representatives_votes_document"."chamber_id" = # AND "representatives_votes_document"."dossier_id" = # AND "representatives_votes_document"."kind" = # AND "representatives_votes_document"."link" = # AND "representatives_votes_document"."title" = #)'
- db: 'SELECT ... FROM "representatives_votes_dossier" WHERE "representatives_votes_dossier"."reference" = #'
- db: 'SELECT ... FROM "representatives_votes_dossier" WHERE "representatives_votes_dossier"."id" = #'
- db: 'SELECT ... FROM "representatives_votes_dossier" WHERE "representatives_votes_dossier"."reference" = #'
- db: 'SELECT ... FROM "representatives_votes_proposal" WHERE ("representatives_votes_proposal"."dossier_id" = # AND "representatives_votes_proposal"."title" = #)'
- db: 'SELECT ... FROM "representatives_votes_proposal" WHERE ("representatives_votes_proposal"."datetime" = #::timestamptz AND "representatives_votes_proposal"."description" = # AND "representatives_votes_proposal"."dossier_id" = # AND "representatives_votes_proposal"."kind" = # AND "representatives_votes_proposal"."reference" = # AND "representatives_votes_proposal"."title" = # AND "representatives_votes_proposal"."total_abstain" = # AND "representatives_votes_proposal"."total_against" = # AND "representatives_votes_proposal"."total_for" = #)'
- db: 'SELECT ... FROM "representatives_votes_dossier" WHERE "representatives_votes_dossier"."reference" = #'
- db: 'SELECT ... FROM "representatives_votes_proposal" WHERE ("representatives_votes_proposal"."dossier_id" = # AND "representatives_votes_proposal"."title" = #)'
- db: 'SELECT ... FROM "representatives_representative" WHERE "representatives_representative"."slug" = #'
- db: 'SELECT ... FROM "representatives_votes_vote" WHERE ("representatives_votes_vote"."position" = # AND "representatives_votes_vote"."proposal_id" = # AND "representatives_votes_vote"."representative_id" = # AND "representatives_votes_vote"."representative_name" = #)'
- db: 'SELECT ... FROM "representatives_votes_dossier" WHERE "representatives_votes_dossier"."reference" = #'
- db: 'SELECT ... FROM "representatives_votes_proposal" WHERE ("representatives_votes_proposal"."dossier_id" = # AND "representatives_votes_proposal"."title" = #)'
- db: 'SELECT ... FROM "representatives_representative" WHERE "representatives_representative"."slug" = #'
- db: 'SELECT ... FROM "representatives_votes_vote" WHERE ("representatives_votes_vote"."position" = # AND "representatives_votes_vote"."proposal_id" = # AND "representatives_votes_vote"."representative_id" = # AND "representatives_votes_vote"."representative_name" = #)'
ParltrackVotesTest.test_parltrack_sync_dossier:
- db: 'SELECT ... FROM "representatives_chamber" WHERE "representatives_chamber"."abbreviation" = #'
- db: SAVEPOINT `#`
- db: 'SELECT ... FROM "representatives_votes_dossier" WHERE "representatives_votes_dossier"."reference" = #'
- db: 'UPDATE "representatives_votes_dossier" SET ... WHERE "representatives_votes_dossier"."id" = #'
- db: 'SELECT ... FROM "representatives_votes_document" WHERE ("representatives_votes_document"."dossier_id" = # AND "representatives_votes_document"."kind" = #)'
- db: INSERT INTO "representatives_votes_document" (...) VALUES (...) RETURNING "representatives_votes_document"."id"
- db: RELEASE SAVEPOINT `#`
- db: 'SELECT ... FROM "representatives_votes_dossier" WHERE ("representatives_votes_dossier"."reference" = # AND "representatives_votes_dossier"."text" = # AND "representatives_votes_dossier"."title" = #)'
......@@ -48,7 +48,7 @@ class ParltrackVotesTest(TestBase):
with mock.patch('representatives_votes.contrib.parltrack.import_votes'
'.Command.should_skip') as should_skip:
should_skip.return_value = False
with self.assertNumQueries(35):
with self.record_performance():
self._test_import('single', import_dossiers.import_single)
def test_parltrack_sync_dossier(self):
......@@ -74,7 +74,7 @@ class ParltrackVotesTest(TestBase):
with open(mock_file, 'r') as mock_stream:
urlopen.return_value = mock_stream
with self.assertNumQueries(8):
with self.record_performance():
self._test_import('sync', callback)
urlopen.assert_called_with(expected_url)
RepresentativeManagerTest.test_dossier:
- db: 'SELECT ... FROM "representatives_votes_dossier" WHERE "representatives_votes_dossier"."id" = #'
- db: SELECT ... FROM "representatives_votes_proposal" WHERE "representatives_votes_proposal"."dossier_id" IN (#) ORDER BY "representatives_votes_proposal"."id" ASC
- db: SELECT ... FROM "representatives_votes_document" WHERE "representatives_votes_document"."dossier_id" IN (#) ORDER BY "representatives_votes_document"."id" ASC
RepresentativeManagerTest.test_dossiers:
- db: SELECT ... FROM "representatives_votes_dossier" ORDER BY "representatives_votes_dossier"."id" ASC
RepresentativeManagerTest.test_proposal:
- db: 'SELECT ... FROM "representatives_votes_proposal" WHERE "representatives_votes_proposal"."id" = #'
- db: SELECT ... FROM "representatives_votes_vote" WHERE "representatives_votes_vote"."proposal_id" IN (#) ORDER BY "representatives_votes_vote"."representative_id" ASC
RepresentativeManagerTest.test_proposals:
- db: SELECT ... FROM "representatives_votes_proposal" ORDER BY "representatives_votes_proposal"."id" ASC
RepresentativeManagerTest.test_vote:
- db: 'SELECT ... FROM "representatives_votes_vote" INNER JOIN "representatives_votes_proposal" ON ( "representatives_votes_vote"."proposal_id" = "representatives_votes_proposal"."id" ) LEFT OUTER JOIN "representatives_representative" ON ( "representatives_votes_vote"."representative_id" = "representatives_representative"."id" ) WHERE "representatives_votes_vote"."id" = #'
RepresentativeManagerTest.test_votes:
- db: SELECT ... FROM "representatives_votes_vote" INNER JOIN "representatives_votes_proposal" ON ( "representatives_votes_vote"."proposal_id" = "representatives_votes_proposal"."id" ) LEFT OUTER JOIN "representatives_representative" ON ( "representatives_votes_vote"."representative_id" = "representatives_representative"."id" ) ORDER BY ...
from django import test
from core.tests import BaseTest as CoreBaseTest
from responsediff.response import Response
class RepresentativeManagerTest(test.TestCase):
class RepresentativeManagerTest(CoreBaseTest):
fixtures = ['representatives_votes_test.json']
def functional_test(self, queries, url):
def functional_test(self, url):
client = test.client.Client()
client.get(url)
with self.assertNumQueries(queries):
with self.record_performance():
result = client.get(
url,
HTTP_ACCEPT='application/json; indent=4',
......@@ -18,23 +19,19 @@ class RepresentativeManagerTest(test.TestCase):
Response.for_test(self).assertNoDiff(result)
def test_dossier(self):
# One for dossier
# One for proposals
# One for documents
self.functional_test(3, '/api/dossiers/1/')
self.functional_test('/api/dossiers/1/')
def test_dossiers(self):
self.functional_test(1, '/api/dossiers/')
self.functional_test('/api/dossiers/')
def test_proposal(self):
# One for proposal and dossier + 1 for votes
self.functional_test(2, '/api/proposals/1/')
self.functional_test('/api/proposals/1/')
def test_proposals(self):
self.functional_test(1, '/api/proposals/')
self.functional_test('/api/proposals/')
def test_vote(self):
self.functional_test(1, '/api/votes/1/')
self.functional_test('/api/votes/1/')
def test_votes(self):
self.functional_test(1, '/api/votes/')
self.functional_test('/api/votes/')
Supports Markdown
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