Пример #1
0
def test_recordinfo_children_sort_limited_alts(project, env):
    # This excercises the bug described in #962, namely that
    # if a page has a child that only has content in a subset of the
    # configured alts, get_record_info throws an exception.
    webadmin = WebAdmin(env, output_path=project.tree)
    data = json.loads(webadmin.test_client().get(
        "/admin/api/recordinfo?path=/projects").data)
    child_data = data["children"]
    assert list(sorted(child_data, key=itemgetter("label"))) == child_data
Пример #2
0
def test_children_sorting_via_api(scratch_project, scratch_env, children_records_data):
    webadmin = WebAdmin(scratch_env, output_path=scratch_project.tree)
    data = json.loads(webadmin.test_client().get('/admin/api/recordinfo?path=/myobj').data)
    children_records_ids_provided_by_api = list(map(itemgetter('id'), data['children']))

    records_ordered_by_title = sorted(children_records_data, key=itemgetter('title'))
    ordered_records = sorted(records_ordered_by_title, key=itemgetter('pub_date'), reverse=True)

    assert list(map(itemgetter('id'), ordered_records)) == children_records_ids_provided_by_api
Пример #3
0
def run_server(bindaddr,
               env,
               output_path,
               prune=True,
               verbosity=0,
               lektor_dev=False,
               ui_lang='en',
               browse=False,
               extra_flags=None):
    """This runs a server but also spawns a background process.  It's
    not safe to call this more than once per python process!
    """
    wz_as_main = os.environ.get('WERKZEUG_RUN_MAIN') == 'true'
    in_main_process = not lektor_dev or wz_as_main
    extra_flags = process_extra_flags(extra_flags)

    if in_main_process:
        background_builder = BackgroundBuilder(env,
                                               output_path=output_path,
                                               prune=prune,
                                               verbosity=verbosity,
                                               extra_flags=extra_flags)
        background_builder.setDaemon(True)
        background_builder.start()
        env.plugin_controller.emit('server-spawn',
                                   bindaddr=bindaddr,
                                   extra_flags=extra_flags)

    app = WebAdmin(env,
                   output_path=output_path,
                   verbosity=verbosity,
                   debug=lektor_dev,
                   ui_lang=ui_lang,
                   extra_flags=extra_flags)

    dt = None
    if lektor_dev and not wz_as_main:
        dt = DevTools(env)
        dt.start()

    if browse:
        browse_to_address(bindaddr)

    try:
        return run_simple(
            bindaddr[0],
            bindaddr[1],
            app,
            use_debugger=True,
            threaded=True,
            use_reloader=lektor_dev,
            request_handler=not lektor_dev and SilentWSGIRequestHandler
            or WSGIRequestHandler)
    finally:
        if dt is not None:
            dt.stop()
        if in_main_process:
            env.plugin_controller.emit('server-stop')
Пример #4
0
 def __init__(self, env, output_path, verbosity=0, debug=False, lang='en'):
     self.env = env
     self.output_path = output_path
     self.verbosity = verbosity
     self.admin = WebAdmin(env,
                           debug=debug,
                           lang=lang,
                           output_path=output_path)
     self.lang = lang