views_test.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:omb-eregs 作者: 18F 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号