Ejemplo n.º 1
0
def test_root_pagination(scratch_project, scratch_env):
    base = scratch_project.tree
    with open(os.path.join(base, "models", "page.ini"), "w") as f:
        f.write("[model]\n"
                "label = {{ this.title }}\n\n"
                "[children]\n"
                "model = page\n"
                "[pagination]\n"
                "enabled = yes\n"
                "per_page = 1\n"
                "[fields.title]\n"
                "type = string\n"
                "[fields.body]\n"
                "type = markdown\n")

    for name in "a", "b", "c":
        os.mkdir(os.path.join(base, "content", name))
        with open(os.path.join(base, "content", name, "contents.lr"),
                  "w") as f:
            f.write("_model: page\n"
                    "---\n"
                    "title: Page %s\n"
                    "---\n"
                    "body: Hello World!\n" % name)

    scratch_pad = Database(scratch_env).new_pad()

    root = scratch_pad.root
    assert root.children.count() == 3

    root_1 = scratch_pad.resolve_url_path("/")
    assert root_1.page_num == 1

    root_2 = scratch_pad.resolve_url_path("/page/2/")
    assert root_2.page_num == 2
Ejemplo n.º 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']
Ejemplo n.º 3
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']
Ejemplo n.º 4
0
 def build(self):
     try:
         db = Database(self.env, lang=self.lang)
         builder = Builder(db.new_pad(), self.output_path)
         builder.build_all()
     except Exception:
         traceback.print_exc()
     else:
         self.last_build = time.time()
Ejemplo n.º 5
0
 def build(self):
     try:
         db = Database(self.env, lang=self.lang)
         builder = Builder(db.new_pad(), self.output_path)
         builder.build_all()
     except Exception:
         traceback.print_exc()
     else:
         self.last_build = time.time()
Ejemplo n.º 6
0
 def build(self, update_source_info_first=False):
     try:
         db = Database(self.env)
         builder = Builder(db.new_pad(), self.output_path)
         if update_source_info_first:
             builder.update_all_source_infos()
         builder.build_all()
         builder.prune()
     except Exception:
         traceback.print_exc()
     else:
         self.last_build = time.time()
Ejemplo n.º 7
0
 def build(self, update_source_info_first=False):
     try:
         db = Database(self.env)
         builder = Builder(db.new_pad(), self.output_path,
                           build_flags=self.build_flags)
         if update_source_info_first:
             builder.update_all_source_infos()
         builder.build_all()
         if self.prune:
             builder.prune()
     except Exception:
         traceback.print_exc()
     else:
         self.last_build = time.time()
Ejemplo n.º 8
0
def child_sources_test_project_builder(tmpdir):
    project = Project.from_path(
        os.path.join(os.path.dirname(__file__), "child-sources-test-project"))
    env = Environment(project)
    pad = Database(env).new_pad()

    return Builder(pad, str(tmpdir.mkdir("output")))
Ejemplo n.º 9
0
 def setUp(self):
     self.project = Project.from_path(
         os.path.join(os.path.dirname(__file__), 'demo-project'))
     self.env = Environment(self.project)
     self.pad = Database(self.env).new_pad()
     self.out = tempfile.mkdtemp()
     self.builder = Builder(self.pad, self.out)
Ejemplo n.º 10
0
def get_unicode_builder(tmpdir):
    proj = Project.from_path(
        os.path.join(os.path.dirname(__file__), u"ünicöde-project"))
    env = Environment(proj)
    pad = Database(env).new_pad()

    return pad, Builder(pad, str(tmpdir.mkdir("output")))
Ejemplo n.º 11
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"]
Ejemplo n.º 12
0
def child_sources_test_project_builder(request):
    from lektor.db import Database
    from lektor.environment import Environment
    from lektor.project import Project

    project = Project.from_path(
        os.path.join(os.path.dirname(__file__), 'child-sources-test-project'))
    env = Environment(project)
    pad = Database(env).new_pad()

    return make_builder(request, pad)
Ejemplo n.º 13
0
def child_sources_test_project_builder(tmpdir):
    from lektor.db import Database
    from lektor.environment import Environment
    from lektor.project import Project
    from lektor.builder import Builder

    project = Project.from_path(
        os.path.join(os.path.dirname(__file__), 'child-sources-test-project'))
    env = Environment(project)
    pad = Database(env).new_pad()

    return Builder(pad, str(tmpdir.mkdir("output")))
Ejemplo n.º 14
0
def get_unicode_builder(tmpdir):
    from lektor.project import Project
    from lektor.environment import Environment
    from lektor.db import Database
    from lektor.builder import Builder

    proj = Project.from_path(os.path.join(os.path.dirname(__file__),
                                          u'ünicöde-project'))
    env = Environment(proj)
    pad = Database(env).new_pad()

    return pad, Builder(pad, str(tmpdir.mkdir('output')))
Ejemplo n.º 15
0
def test_root_pagination(scratch_project, scratch_env):
    base = scratch_project.tree
    with open(os.path.join(base, 'models', 'page.ini'), 'w') as f:
        f.write(
            '[model]\n'
            'label = {{ this.title }}\n\n'
            '[children]\n'
            'model = page\n'
            '[pagination]\n'
            'enabled = yes\n'
            'per_page = 1\n'
            '[fields.title]\n'
            'type = string\n'
            '[fields.body]\n'
            'type = markdown\n'
        )

    for name in 'a', 'b', 'c':
        os.mkdir(os.path.join(base, 'content', name))
        with open(os.path.join(base, 'content', name, 'contents.lr'), 'w') as f:
            f.write(
                '_model: page\n'
                '---\n'
                'title: Page %s\n'
                '---\n'
                'body: Hello World!\n' % name
            )

    from lektor.db import Database
    scratch_pad = Database(scratch_env).new_pad()

    root = scratch_pad.root
    assert root.children.count() == 3

    root_1 = scratch_pad.resolve_url_path('/')
    assert root_1.page_num == 1

    root_2 = scratch_pad.resolve_url_path('/page/2/')
    assert root_2.page_num == 2
Ejemplo n.º 16
0
def test_root_pagination(scratch_project, scratch_env):
    base = scratch_project.tree
    with open(os.path.join(base, 'models', 'page.ini'), 'w') as f:
        f.write(
            '[model]\n'
            'label = {{ this.title }}\n\n'
            '[children]\n'
            'model = page\n'
            '[pagination]\n'
            'enabled = yes\n'
            'per_page = 1\n'
            '[fields.title]\n'
            'type = string\n'
            '[fields.body]\n'
            'type = markdown\n'
        )

    for name in 'a', 'b', 'c':
        os.mkdir(os.path.join(base, 'content', name))
        with open(os.path.join(base, 'content', name, 'contents.lr'), 'w') as f:
            f.write(
                '_model: page\n'
                '---\n'
                'title: Page %s\n'
                '---\n'
                'body: Hello World!\n' % name
            )

    from lektor.db import Database
    scratch_pad = Database(scratch_env).new_pad()

    root = scratch_pad.root
    assert root.children.count() == 3

    root_1 = scratch_pad.resolve_url_path('/')
    assert root_1.page_num == 1

    root_2 = scratch_pad.resolve_url_path('/page/2/')
    assert root_2.page_num == 2
Ejemplo n.º 17
0
def demo_output(site_path, my_plugin_id, my_plugin_cls, tmp_path_factory):
    """ Build the demo site.

    Return path to output directory.

    """
    project = Project.from_path(str(site_path))
    env = Environment(project, load_plugins=False)

    # Load our plugin
    env.plugin_controller.instanciate_plugin(my_plugin_id, my_plugin_cls)
    env.plugin_controller.emit('setup-env')

    pad = Database(env).new_pad()
    output_path = tmp_path_factory.mktemp('demo-site')
    builder = Builder(pad, str(output_path))
    with CliReporter(env):
        failures = builder.build_all()
        assert failures == 0
    return output_path
Ejemplo n.º 18
0
 def new_pad(self):
     """Convenience function to create a database and pad."""
     from lektor.db import Database
     return Database(self).new_pad()
Ejemplo n.º 19
0
def pntest_pad(request, pntest_env):
    return Database(pntest_env).new_pad()
Ejemplo n.º 20
0
 def get_pad(self):
     db = Database(self.env)
     pad = db.new_pad()
     return pad
Ejemplo n.º 21
0
    def new_pad(self):
        """Convenience function to create a database and pad."""
        from lektor.db import Database  # pylint: disable=import-outside-toplevel

        return Database(self).new_pad()
Ejemplo n.º 22
0
 def get_pad(self):
     return Database(self.env, lang=self.lang).new_pad()
Ejemplo n.º 23
0
 def get_pad(self):
     db = Database(self.env, lang=self.lang)
     pad = db.new_pad()
     return pad
Ejemplo n.º 24
0
def pntest_pad(request, pntest_env):
    from lektor.db import Database

    return Database(pntest_env).new_pad()
Ejemplo n.º 25
0
 def get_pad(self):
     return Database(self.env).new_pad()
Ejemplo n.º 26
0
def pad(env):
    from lektor.db import Database
    return Database(env).new_pad()
Ejemplo n.º 27
0
Archivo: cli.py Proyecto: jab/lektor
 def new_pad(self):
     from lektor.db import Database
     env = self.get_env()
     return Database(env).new_pad()
Ejemplo n.º 28
0
def test_Database_iter_items_invalid_path(env):
    # Check that there is no problem with uncaught
    # OSError(errno=EINVAL) when a path contains non-filename-safe
    # characters in Database.iter_items.
    db = Database(env)
    assert len(list(db.iter_items("/<foo>"))) == 0
Ejemplo n.º 29
0
def scratch_pad(scratch_env):
    return Database(scratch_env).new_pad()
Ejemplo n.º 30
0
 def get_pad(self):
     db = Database(self.env, lang=self.lang)
     pad = db.new_pad()
     return pad
Ejemplo n.º 31
0
def scratch_pad(scratch_env):
    from lektor.db import Database
    return Database(scratch_env).new_pad()
Ejemplo n.º 32
0
def theme_pad(theme_env):

    return Database(theme_env).new_pad()
Ejemplo n.º 33
0
def theme_pad(theme_env):
    from lektor.db import Database

    return Database(theme_env).new_pad()
Ejemplo n.º 34
0
def pad(env):
    return Database(env).new_pad()