def test_query_count(client):
policy = mommy.make(Policy, omb_policy_id='M-O-A-R')
root = random_doc(20, save=True, policy=policy, text='placeholder')
# select 3 nodes to have external links
for node in random.sample(list(root.walk()), 3):
node.externallinks.create(start=0, end=1, href='http://example.com/')
# select 3 nodes to have inline requirements
for node in random.sample(list(root.walk()), 3):
node.inlinerequirements.create(
start=1, end=2, requirement=mommy.make(Requirement))
# select 3 nodes to add footnote citations
citing_nodes = random.sample(list(root.walk()), 3)
footnotes = [citing.add_child('footnote') for citing in citing_nodes]
root.nested_set_renumber(bulk_create=False)
for node in root.walk():
node.model.save()
for citing, footnote in zip(citing_nodes, footnotes):
citing.footnotecitations.create(
start=2, end=3, footnote_node=footnote.model)
# pytest will alter the connection, so we only want to load it within this
# test
from django.db import connection
with CaptureQueriesContext(connection) as capture:
client.get("/M-O-A-R")
# Query 01: Lookup the policy
# 02: Lookup the root docnode
# 03: fetch footnote citations _and_ referenced node for the root
# 04: fetch external links for the root
# 05: fetch inline requirements _and_ referenced req for root
# 06: fetch cite elements for the root
# 06: fetch nodes for table of contents
# 08: fetch child nodes
# 09: fetch footnote citations _and_ referenced node for child nodes
# 10: fetch external links for child nodes
# 11: fetch inline requirements _and_ referenced req for child nodes
# 12: fetch cite elements for child nodes
assert len(capture) == 12
评论列表
文章目录