コード例 #1
0
    def test_basic_old_and_new(self):

        self.sitetree.cache.init()

        # Assert no dynamic attached.
        tree_alias, sitetree_items = self.sitetree.get_sitetree('main')
        self.assertEqual(len(sitetree_items), 1)

        # Assert cache hit.
        tree_alias, sitetree_items = self.sitetree.get_sitetree('main')
        self.assertEqual(len(sitetree_items), 1)

        # Empty cache before dynamic items added.
        self.sitetree.cache.empty()

        self.assertEqual(len(get_dynamic_trees().keys()), 0)

        self.basic_test()  # old-style

        self.assertEqual(len(get_dynamic_trees().keys()), 3)

        self.basic_test(new_style=True)
        self.basic_test(new_style=True, reset_cache=True)

        self.assertEqual(len(get_dynamic_trees().keys()), 3)
コード例 #2
0
def test_dynamic_basic(template_render_tag, template_context, template_strip_tags):

    from sitetree.toolbox import compose_dynamic_tree, register_dynamic_trees, tree, item, get_dynamic_trees
    from sitetree.sitetreeapp import _IDX_ORPHAN_TREES

    trees = [
        compose_dynamic_tree([tree('dynamic1', items=[
            item('dynamic1_1', '/dynamic1_1_url', url_as_pattern=False, sort_order=2),
            item('dynamic1_2', '/dynamic1_2_url', url_as_pattern=False, sort_order=1),
        ])]),
        compose_dynamic_tree([tree('dynamic2', items=[
            item('dynamic2_1', '/dynamic2_1_url', url_as_pattern=False),
            item('dynamic2_2', '/dynamic2_2_url', url_as_pattern=False),
        ])]),
    ]

    register_dynamic_trees(*trees, reset_cache=True)  # new less-brackets style
    result = template_strip_tags(template_render_tag('sitetree', 'sitetree_tree from "dynamic1"', template_context()))

    assert 'dynamic1_1|dynamic1_2' in result
    assert 'dynamic2_1' not in result

    register_dynamic_trees(trees)

    result = template_strip_tags(template_render_tag('sitetree', 'sitetree_tree from "dynamic1"', template_context()))
    assert 'dynamic1_1|dynamic1_2' in result
    assert 'dynamic2_1' not in result

    trees = get_dynamic_trees()
    assert len(trees[_IDX_ORPHAN_TREES]) == 2

    from sitetree.sitetreeapp import _DYNAMIC_TREES
    _DYNAMIC_TREES.clear()
コード例 #3
0
def test_dynamic_basic(render_template_tag, mock_template_context):

    from sitetree.toolbox import compose_dynamic_tree, register_dynamic_trees, tree, item, get_dynamic_trees
    from sitetree.sitetreeapp import _IDX_ORPHAN_TREES

    trees = [
        compose_dynamic_tree([tree('dynamic1', items=[
            item('dynamic1_1', '/dynamic1_1_url', url_as_pattern=False, sort_order=2),
            item('dynamic1_2', '/dynamic1_2_url', url_as_pattern=False, sort_order=1),
        ])]),
        compose_dynamic_tree([tree('dynamic2', items=[
            item('dynamic2_1', '/dynamic2_1_url', url_as_pattern=False),
            item('dynamic2_2', '/dynamic2_2_url', url_as_pattern=False),
        ])]),
    ]

    register_dynamic_trees(*trees, reset_cache=True)  # new less-brackets style
    result = strip_tags(render_template_tag('sitetree', 'sitetree_tree from "dynamic1"', mock_template_context()))

    assert 'dynamic1_1|dynamic1_2' in result
    assert 'dynamic2_1' not in result

    register_dynamic_trees(trees)

    result = strip_tags(render_template_tag('sitetree', 'sitetree_tree from "dynamic1"', mock_template_context()))
    assert 'dynamic1_1|dynamic1_2' in result
    assert 'dynamic2_1' not in result

    trees = get_dynamic_trees()
    assert len(trees[_IDX_ORPHAN_TREES]) == 2

    from sitetree.sitetreeapp import _DYNAMIC_TREES
    _DYNAMIC_TREES.clear()