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
ThemePositionsTest.test_queries:
- db: 'SELECT ... FROM "memopol_themes_theme" WHERE "memopol_themes_theme"."slug" = #'
- db: SELECT ... FROM "representatives_positions_position" INNER JOIN "memopol_themes_theme_positions" ON ( "representatives_positions_position"."id" = "memopol_themes_theme_positions"."position_id" ) WHERE "memopol_themes_theme_positions"."theme_id" IN (#)
- db: SELECT ... FROM "memopol_settings_setting" WHERE "memopol_settings_setting"."key" IN (...)
- cache|get: template.cache.search_form.#
- cache|set: template.cache.search_form.#
- cache|get: template.cache.position_form.#
- db: SELECT ... FROM "memopol_themes_theme" WHERE "memopol_themes_theme"."id" IN (#)
- cache|set: template.cache.position_form.#
ThemeProposalsTest.test_queries:
- db: 'SELECT ... FROM "memopol_themes_theme" WHERE "memopol_themes_theme"."slug" = #'
- db: SELECT ... FROM "representatives_votes_proposal" INNER JOIN "memopol_themes_theme_proposals" ON ( "representatives_votes_proposal"."id" = "memopol_themes_theme_proposals"."proposal_id" ) INNER JOIN "representatives_votes_dossier" ON ( "representatives_votes_proposal"."dossier_id" = "representatives_votes_dossier"."id" ) LEFT OUTER JOIN "representatives_recommendations_recommendation" ON ( "representatives_votes_proposal"."id" = "representatives_recommendations_recommendation"."proposal_id" ) WHERE "memopol_themes_theme_proposals"."theme_id" IN (#) ORDER BY ...
- db: SELECT ... FROM "representatives_votes_document" WHERE "representatives_votes_document"."dossier_id" IN (...)
- db: SELECT ... FROM "representatives_chamber" WHERE "representatives_chamber"."id" IN (#)
- db: SELECT ... FROM "memopol_settings_setting" WHERE "memopol_settings_setting"."key" IN (...)
- cache|get: template.cache.search_form.#
- cache|set: template.cache.search_form.#
- cache|get: template.cache.position_form.#
- db: SELECT ... FROM "memopol_themes_theme" WHERE "memopol_themes_theme"."id" IN (#)
- cache|set: template.cache.position_form.#
......@@ -41,9 +41,7 @@ class ChartViewsTest(BaseTest):
# First query to set session variables
self.client.get(url)
with self.assertNumQueries(2):
# 1 query for the theme
# 1 query for theme scores
with self.record_performance():
self.client.get(url)
def test_chamber_score_queries(self):
......@@ -52,7 +50,5 @@ class ChartViewsTest(BaseTest):
# First query to set session variables
self.client.get(url)
with self.assertNumQueries(2):
# 1 query for the chamber
# 1 query for chamber scores
with self.record_performance():
self.client.get(url)
......@@ -4,13 +4,6 @@ from .base import DossierBaseTest
class DossierDocumentsTest(DossierBaseTest):
tab = 'documents'
"""
Dossier base queries plus
- 1 for documents
- 1 for related chambers
"""
queries = DossierBaseTest.queries + 2
def test_queries(self):
self.do_query_test()
......
......@@ -8,16 +8,7 @@ class DossierListTest(BaseTest):
# First query to set session variables
self.client.get(self.url)
with self.assertNumQueries(self.left_pane_queries + 6):
"""
Left pane queries plus:
- 1 for session key
- 1 for dossier count (pagination)
- 1 for dossiers
- 1 for reverse relation on documents
- 1 for reverse relation on document chambers
- 1 for reverse relation on themes
"""
with self.record_performance():
self.client.get(self.url)
def test_cards(self):
......
......@@ -4,13 +4,6 @@ from .base import DossierBaseTest
class DossierProposalsTest(DossierBaseTest):
tab = 'proposals'
"""
Dossier base queries plus
- 1 for proposals
- 1 for related themes
"""
queries = DossierBaseTest.queries + 2
def test_queries(self):
self.do_query_test()
......
......@@ -4,13 +4,6 @@ from .base import DossierBaseTest
class DossierRecommendationsTest(DossierBaseTest):
tab = 'recommendations'
"""
Dossier base queries plus
- 1 for proposals and related recommendation
- 1 for related themes
"""
queries = DossierBaseTest.queries + 2
def test_queries(self):
self.do_query_test()
......
......@@ -8,24 +8,5 @@ class HomeTest(BaseTest):
# First query to set session variables
self.client.get(self.url)
"""
- 3 for Today mep
- 1 for count reps with non null score
- 1 for random mep
- 1 for prefetch main mandate
- 6 for Latest votes
- 1 for latest votes count setting
- 1 for latest votes (proposal)
- 1 for prefetching latest votes themes
- 1 for prefetching latest votes dossier themes
- 1 for prefetching latest votes dossier documents
- 1 for prefetching latest votes dossier documents chambers
- 1 for Featured themes
- 1 for featured themes
- 1 for Chambers
- 1 for chambers and dossier/proposal counts
"""
home_queries = 11
with self.assertNumQueries(self.left_pane_queries + home_queries):
with self.record_performance():
self.client.get(self.url)
......@@ -8,14 +8,7 @@ class RepresentativeListTest(BaseTest):
# First query to set session variables
self.client.get(self.url)
with self.assertNumQueries(self.left_pane_queries + 4):
"""
Left pane queries plus:
- 1 for session key
- 1 for representative count (pagination)
- 1 for representatives
- 1 for reverse relation on country
"""
with self.record_performance():
self.client.get(self.url)
def test_cards(self):
......
......@@ -7,12 +7,6 @@ class RepresentativeMandatesTest(RepresentativeBaseTest):
# Switch to a MEP with more mandates for this test
base_url = '/representatives/renate-weber-1955-08-03/%s/'
"""
Representative queries plus
- 1 for mandates
"""
queries = RepresentativeBaseTest.queries + 1
def test_queries(self):
self.do_query_test()
......
......@@ -4,14 +4,6 @@ from .base import RepresentativeBaseTest
class RepresentativePositionsTest(RepresentativeBaseTest):
tab = 'positions'
"""
- One for positions
- One for position scores
- One for position themes
- One for position representatives
"""
queries = RepresentativeBaseTest.queries + 4
def test_queries(self):
self.do_query_test()
......
......@@ -4,13 +4,6 @@ from .base import RepresentativeBaseTest
class RepresentativeVotesTest(RepresentativeBaseTest):
tab = 'votes'
"""
- One for votes
- One for dossier scores
- Two for dossier themes (?? should be one according to the queryset !)
"""
queries = RepresentativeBaseTest.queries + 4
def test_queries(self):
self.do_query_test()
......
......@@ -4,15 +4,6 @@ from .base import ThemeBaseTest
class ThemeDossiersTest(ThemeBaseTest):
tab = 'dossiers'
"""
Theme base queries plus
- 1 for dossiers
- 1 for reverse relation on documents
- 1 for reverse relation on document chambers
- 1 for reverse relation on themes
"""
queries = ThemeBaseTest.queries + 4
def test_queries(self):
self.do_query_test()
......
......@@ -4,12 +4,6 @@ from .base import ThemeBaseTest
class ThemeLinksTest(ThemeBaseTest):
tab = 'links'
"""
Theme base queries plus
- 1 for links
"""
queries = ThemeBaseTest.queries + 1
def test_queries(self):
self.do_query_test()
......
......@@ -8,13 +8,7 @@ class ThemeListTest(BaseTest):
# First query to set session variables
self.client.get(self.url)
with self.assertNumQueries(self.left_pane_queries + 3):
"""
Left pane queries plus:
- 1 for session key
- 1 for theme count (pagination)
- 1 for themes
"""
with self.record_performance():
self.client.get(self.url)
def test_cards(self):
......
......@@ -4,12 +4,6 @@ from .base import ThemeBaseTest
class ThemePositionsTest(ThemeBaseTest):
tab = 'positions'
"""
Theme base queries plus
- 1 for positions
"""
queries = ThemeBaseTest.queries + 1
def test_queries(self):
self.do_query_test()
......
......@@ -4,14 +4,6 @@ from .base import ThemeBaseTest
class ThemeProposalsTest(ThemeBaseTest):
tab = 'proposals'
"""
Theme base queries plus
- 1 for proposals, dossiers and recommendations
- 1 for related dossiers/documents
- 1 for related dossiers/documents/chambers
"""
queries = ThemeBaseTest.queries + 3
def test_queries(self):
self.do_query_test()
......
......@@ -2,11 +2,12 @@ import copy
import logging
import re
from django import test
from django.core.serializers.json import Deserializer
from core.tests import BaseTest as CoreBaseTest
class TestBase(test.TestCase):
class TestBase(CoreBaseTest):
logger = logging.getLogger('representatives')
_exclude = ('id', '_state', 'created', 'updated', 'fingerprint')
......
RepresentativeManagerTest.test_chambers_api:
- db: SELECT ... FROM "representatives_chamber" ORDER BY "representatives_chamber"."id" ASC
RepresentativeManagerTest.test_constituencies_api:
- db: SELECT ... FROM "representatives_constituency" ORDER BY "representatives_constituency"."id" ASC
RepresentativeManagerTest.test_groups_api:
- db: SELECT ... FROM "representatives_group" ORDER BY "representatives_group"."id" ASC
RepresentativeManagerTest.test_mandates_api:
- db: SELECT ... FROM "representatives_mandate" LEFT OUTER JOIN "representatives_group" ON ( "representatives_mandate"."group_id" = "representatives_group"."id" ) LEFT OUTER JOIN "representatives_constituency" ON ( "representatives_mandate"."constituency_id" = "representatives_constituency"."id" ) INNER JOIN "representatives_representative" ON ( "representatives_mandate"."representative_id" = "representatives_representative"."id" ) ORDER BY ...
RepresentativeManagerTest.test_representatives_api:
- db: SELECT ... FROM "representatives_representative" ORDER BY "representatives_representative"."slug" ASC
- db: SELECT ... FROM "representatives_email" WHERE "representatives_email"."representative_id" IN (...) ORDER BY "representatives_email"."id" ASC
- db: SELECT ... FROM "representatives_website" WHERE "representatives_website"."representative_id" IN (...) ORDER BY "representatives_website"."id" ASC
- db: SELECT ... FROM "representatives_address" INNER JOIN "representatives_country" ON ( "representatives_address"."country_id" = "representatives_country"."id" ) WHERE "representatives_address"."representative_id" IN (...) ORDER BY "representatives_address"."id" ASC
- db: SELECT ... FROM "representatives_phone" LEFT OUTER JOIN "representatives_address" ON ( "representatives_phone"."address_id" = "representatives_address"."id" ) LEFT OUTER JOIN "representatives_country" ON ( "representatives_address"."country_id" = "representatives_country"."id" ) WHERE "representatives_phone"."representative_id" IN (...) ORDER BY "representatives_phone"."id" ASC
- db: SELECT ... FROM "representatives_mandate" LEFT OUTER JOIN "representatives_group" ON ( "representatives_mandate"."group_id" = "representatives_group"."id" ) LEFT OUTER JOIN "representatives_constituency" ON ( "representatives_mandate"."constituency_id" = "representatives_constituency"."id" ) WHERE "representatives_mandate"."representative_id" IN (...) ORDER BY "representatives_mandate"."id" ASC
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_test.json']
def functional_test(self, queries, url):
def functional_test(self, url):
client = test.client.Client()
# First query to setup session
client.get(url)
with self.assertNumQueries(queries):
with self.record_performance():
result = client.get(url)
Response.for_test(self).assertNoDiff(result)
def test_constituencies_api(self):
self.functional_test(1, '/api/constituencies/?format=json')
self.functional_test('/api/constituencies/?format=json')
def test_groups_api(self):
self.functional_test(1, '/api/groups/?format=json')
self.functional_test('/api/groups/?format=json')
def test_mandates_api(self):
self.functional_test(1, '/api/mandates/?format=json')
self.functional_test('/api/mandates/?format=json')
def test_chambers_api(self):
self.functional_test(1, '/api/chambers/?format=json')
self.functional_test('/api/chambers/?format=json')
def test_representatives_api(self):
"""
Queries:
- representatives,
- emails,
- websites,
- addresses,
- phones,
- mandates.
"""
self.functional_test(6, '/api/representatives/?format=json')
self.functional_test('/api/representatives/?format=json')
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