예제 #1
0
파일: test_db.py 프로젝트: sunliwen/lektor
def test_default_order_by(scratch_project, scratch_env):
    from lektor.db import Database

    tree = scratch_project.tree
    with open(os.path.join(tree, 'models', 'mymodel.ini'), 'w') as f:
        f.write(
            '[children]\n'
            'order_by = title\n'
            '[attachments]\n'
            'order_by = attachment_filename\n'
            )
    os.mkdir(os.path.join(tree, 'content', 'myobj'))
    with open(os.path.join(tree, 'content', 'myobj', 'contents.lr'), 'w') as f:
        f.write(
            '_model: mymodel\n'
            '---\n'
            'title: My Test Object\n'
            )

    pad = Database(scratch_env).new_pad()
    myobj = pad.get('/myobj')
    children = myobj.children
    assert list(children.get_order_by()) == ['title']
    assert list(children.order_by('explicit').get_order_by()) == ['explicit']
    assert list(myobj.attachments.get_order_by()) == ['attachment_filename']
예제 #2
0
def test_default_order_by(scratch_project, scratch_env):
    from lektor.db import Database

    tree = scratch_project.tree
    with open(os.path.join(tree, 'models', 'mymodel.ini'), 'w') as f:
        f.write(
            '[children]\n'
            'order_by = title\n'
            '[attachments]\n'
            'order_by = attachment_filename\n'
            )
    os.mkdir(os.path.join(tree, 'content', 'myobj'))
    with open(os.path.join(tree, 'content', 'myobj', 'contents.lr'), 'w') as f:
        f.write(
            '_model: mymodel\n'
            '---\n'
            'title: My Test Object\n'
            )

    pad = Database(scratch_env).new_pad()
    myobj = pad.get('/myobj')
    children = myobj.children
    assert list(children.get_order_by()) == ['title']
    assert list(children.order_by('explicit').get_order_by()) == ['explicit']
    assert list(myobj.attachments.get_order_by()) == ['attachment_filename']
예제 #3
0
def test_default_order_by(scratch_project, scratch_env):
    tree = scratch_project.tree
    with open(os.path.join(tree, "models", "mymodel.ini"), "w") as f:
        f.write("[children]\n"
                "order_by = title\n"
                "[attachments]\n"
                "order_by = attachment_filename\n")
    os.mkdir(os.path.join(tree, "content", "myobj"))
    with open(os.path.join(tree, "content", "myobj", "contents.lr"), "w") as f:
        f.write("_model: mymodel\n" "---\n" "title: My Test Object\n")

    pad = Database(scratch_env).new_pad()
    myobj = pad.get("/myobj")
    children = myobj.children
    assert list(children.get_order_by()) == ["title"]
    assert list(children.order_by("explicit").get_order_by()) == ["explicit"]
    assert list(myobj.attachments.get_order_by()) == ["attachment_filename"]