Ejemplo n.º 1
0
def _test_view_project_children(view, project):
    request = view.request
    kwargs = view.kwargs
    resource_path = ("%(dir_path)s%(filename)s" % kwargs)
    project_path = ("%s/%s" % (kwargs["project_code"], resource_path))
    if not (kwargs["dir_path"] or kwargs["filename"]):
        obj = project
    elif not kwargs["filename"]:
        obj = ProjectResource(Directory.objects.live().filter(
            pootle_path__regex="^/.*/%s$" % project_path),
                              pootle_path="/projects/%s" % project_path)
    else:
        obj = ProjectResource(Store.objects.live().filter(
            pootle_path__regex="^/.*/%s$" % project_path),
                              pootle_path="/projects/%s" % project_path)

    item_func = (make_xlanguage_item if
                 (kwargs["dir_path"]
                  or kwargs["filename"]) else make_language_item)
    items = [
        item_func(item) for item in obj.get_children_for_user(request.user)
    ]
    stats = obj.data_tool.get_stats(user=request.user)
    stats = StatsDisplay(obj, stats=stats).stats
    for item in items:
        if item["code"] in stats["children"]:
            item["stats"] = stats["children"][item["code"]]
    items.sort(cmp_by_last_activity)
    assert view.object_children == items
Ejemplo n.º 2
0
def _test_browse_view(project, request, response, kwargs):
    cookie_data = json.loads(
        unquote(response.cookies[SIDEBAR_COOKIE_NAME].value))
    assert cookie_data["foo"] == "bar"
    assert "announcements_projects_%s" % project.code in cookie_data
    ctx = response.context
    kwargs["project_code"] = project.code
    resource_path = ("%(dir_path)s%(filename)s" % kwargs)
    project_path = ("%s/%s" % (kwargs["project_code"], resource_path))
    if not (kwargs["dir_path"] or kwargs["filename"]):
        ob = project
    elif not kwargs["filename"]:
        ob = ProjectResource(Directory.objects.live().filter(
            pootle_path__regex="^/.*/%s$" % project_path),
                             pootle_path="/projects/%s" % project_path)
    else:
        ob = ProjectResource(Store.objects.live().filter(
            pootle_path__regex="^/.*/%s$" % project_path),
                             pootle_path="/projects/%s" % project_path)

    item_func = (make_xlanguage_item if
                 (kwargs["dir_path"]
                  or kwargs["filename"]) else make_language_item)
    items = [
        item_func(item) for item in ob.get_children_for_user(request.user)
    ]
    items.sort(lambda x, y: locale.strcoll(x['title'], y['title']))

    table_fields = [
        'name', 'progress', 'total', 'need-translation', 'suggestions',
        'critical', 'last-updated', 'activity'
    ]
    table = {
        'id': 'project',
        'fields': table_fields,
        'headings': get_table_headings(table_fields),
        'items': items
    }

    assertions = dict(
        page="browse",
        project=project,
        browser_extends="projects/base.html",
        pootle_path="/projects/%s" % project_path,
        resource_path=resource_path,
        resource_path_parts=get_path_parts(resource_path),
        url_action_continue=ob.get_translate_url(state='incomplete'),
        url_action_fixcritical=ob.get_critical_url(),
        url_action_review=ob.get_translate_url(state='suggestions'),
        url_action_view_all=ob.get_translate_url(state='all'),
        translation_states=get_translation_states(ob),
        check_categories=get_qualitycheck_schema(ob),
        table=table,
        stats=jsonify(ob.get_stats()))
    sidebar = get_sidebar_announcements_context(request, (project, ))
    for k in ["has_sidebar", "is_sidebar_open", "announcements"]:
        assertions[k] = sidebar[0][k]
    view_context_test(ctx, **assertions)
Ejemplo n.º 3
0
def _test_browse_view(project, request, response, kwargs):
    cookie_data = json.loads(unquote(response.cookies[SIDEBAR_COOKIE_NAME].value))
    assert cookie_data["foo"] == "bar"
    assert "announcements_projects_%s" % project.code in cookie_data
    ctx = response.context
    kwargs["project_code"] = project.code
    resource_path = "%(dir_path)s%(filename)s" % kwargs
    project_path = "%s/%s" % (kwargs["project_code"], resource_path)
    if not (kwargs["dir_path"] or kwargs["filename"]):
        ob = project
    elif not kwargs["filename"]:
        ob = ProjectResource(
            Directory.objects.live().filter(pootle_path__regex="^/.*/%s$" % project_path),
            pootle_path="/projects/%s" % project_path,
        )
    else:
        ob = ProjectResource(
            Store.objects.live().filter(pootle_path__regex="^/.*/%s$" % project_path),
            pootle_path="/projects/%s" % project_path,
        )

    item_func = make_xlanguage_item if (kwargs["dir_path"] or kwargs["filename"]) else make_language_item
    items = [item_func(item) for item in ob.get_children_for_user(request.profile)]
    items.sort(lambda x, y: locale.strcoll(x["title"], y["title"]))

    table_fields = [
        "name",
        "progress",
        "total",
        "need-translation",
        "suggestions",
        "critical",
        "last-updated",
        "activity",
    ]
    table = {"id": "project", "fields": table_fields, "headings": get_table_headings(table_fields), "items": items}

    assertions = dict(
        page="browse",
        project=project,
        resource_obj=ob,
        browser_extends="projects/base.html",
        pootle_path="/projects/%s" % project_path,
        resource_path=resource_path,
        resource_path_parts=get_path_parts(resource_path),
        url_action_continue=ob.get_translate_url(state="incomplete"),
        url_action_fixcritical=ob.get_critical_url(),
        url_action_review=ob.get_translate_url(state="suggestions"),
        url_action_view_all=ob.get_translate_url(state="all"),
        translation_states=get_translation_states(ob),
        check_categories=get_qualitycheck_schema(ob),
        table=table,
        stats=jsonify(ob.get_stats()),
    )
    sidebar = get_sidebar_announcements_context(request, (project,))
    for k in ["has_sidebar", "is_sidebar_open", "announcements"]:
        assertions[k] = sidebar[0][k]
    view_context_test(ctx, **assertions)
Ejemplo n.º 4
0
def _test_view_project_children(view, project):
    request = view.request
    kwargs = view.kwargs
    resource_path = (
        "%(dir_path)s%(filename)s" % kwargs)
    project_path = (
        "%s/%s"
        % (kwargs["project_code"], resource_path))
    if not (kwargs["dir_path"] or kwargs["filename"]):
        obj = project
    elif not kwargs["filename"]:
        obj = ProjectResource(
            Directory.objects.live().filter(
                pootle_path__regex="^/.*/%s$" % project_path),
            pootle_path="/projects/%s" % project_path)
    else:
        obj = ProjectResource(
            Store.objects.live().filter(
                pootle_path__regex="^/.*/%s$" % project_path),
            pootle_path="/projects/%s" % project_path)

    item_func = (
        make_xlanguage_item
        if (kwargs["dir_path"]
            or kwargs["filename"])
        else make_language_item)
    items = [
        item_func(item)
        for item
        in obj.get_children_for_user(request.user)
    ]
    items.sort(lambda x, y: locale.strcoll(x['title'], y['title']))
    stats = obj.data_tool.get_stats(user=request.user)
    stats = StatsDisplay(obj, stats=stats).stats
    for item in items:
        if item["code"] in stats["children"]:
            item["stats"] = stats["children"][item["code"]]
    assert view.object_children == items
Ejemplo n.º 5
0
def _test_browse_view(project, request, response, kwargs):
    cookie_data = json.loads(
        unquote(response.cookies[SIDEBAR_COOKIE_NAME].value))
    assert cookie_data["foo"] == "bar"
    assert "announcements_projects_%s" % project.code in cookie_data
    ctx = response.context
    kwargs["project_code"] = project.code
    resource_path = (
        "%(dir_path)s%(filename)s" % kwargs)
    project_path = (
        "%s/%s"
        % (kwargs["project_code"], resource_path))
    if not (kwargs["dir_path"] or kwargs["filename"]):
        obj = project
    elif not kwargs["filename"]:
        obj = ProjectResource(
            Directory.objects.live().filter(
                pootle_path__regex="^/.*/%s$" % project_path),
            pootle_path="/projects/%s" % project_path)
    else:
        obj = ProjectResource(
            Store.objects.live().filter(
                pootle_path__regex="^/.*/%s$" % project_path),
            pootle_path="/projects/%s" % project_path)

    item_func = (
        make_xlanguage_item
        if (kwargs["dir_path"]
            or kwargs["filename"])
        else make_language_item)
    items = [
        item_func(item)
        for item
        in obj.get_children_for_user(request.user)
    ]
    items.sort(lambda x, y: locale.strcoll(x['title'], y['title']))

    table_fields = ['name', 'progress', 'total', 'need-translation',
                    'suggestions', 'critical', 'last-updated', 'activity']
    table = {
        'id': 'project',
        'fields': table_fields,
        'headings': get_table_headings(table_fields),
        'items': items}

    if request.user.is_superuser or kwargs.get("language_code"):
        url_action_continue = obj.get_translate_url(state='incomplete')
        url_action_fixcritical = obj.get_critical_url()
        url_action_review = obj.get_translate_url(state='suggestions')
        url_action_view_all = obj.get_translate_url(state='all')
    else:
        (url_action_continue,
         url_action_fixcritical,
         url_action_review,
         url_action_view_all) = [None] * 4

    User = get_user_model()
    top_scorers = User.top_scorers(project=project.code, limit=10)
    assertions = dict(
        page="browse",
        project=project,
        browser_extends="projects/base.html",
        pootle_path="/projects/%s" % project_path,
        resource_path=resource_path,
        resource_path_parts=get_path_parts(resource_path),
        url_action_continue=url_action_continue,
        url_action_fixcritical=url_action_fixcritical,
        url_action_review=url_action_review,
        url_action_view_all=url_action_view_all,
        translation_states=get_translation_states(obj),
        checks=get_qualitycheck_list(obj),
        table=table,
        top_scorers=top_scorers,
        top_scorers_data=get_top_scorers_data(top_scorers, 10),
        stats=obj.data_tool.get_stats(user=request.user),
    )
    sidebar = get_sidebar_announcements_context(
        request, (project, ))
    for k in ["has_sidebar", "is_sidebar_open", "announcements"]:
        assertions[k] = sidebar[0][k]
    view_context_test(ctx, **assertions)
Ejemplo n.º 6
0
def _test_browse_view(project, request, response, kwargs):
    cookie_data = json.loads(
        unquote(response.cookies[SIDEBAR_COOKIE_NAME].value))
    assert cookie_data["foo"] == "bar"
    assert "announcements_projects_%s" % project.code in cookie_data
    ctx = response.context
    kwargs["project_code"] = project.code
    resource_path = ("%(dir_path)s%(filename)s" % kwargs)
    project_path = ("%s/%s" % (kwargs["project_code"], resource_path))
    if not (kwargs["dir_path"] or kwargs["filename"]):
        obj = project
    elif not kwargs["filename"]:
        obj = ProjectResource(Directory.objects.live().filter(
            pootle_path__regex="^/.*/%s$" % project_path),
                              pootle_path="/projects/%s" % project_path)
    else:
        obj = ProjectResource(Store.objects.live().filter(
            pootle_path__regex="^/.*/%s$" % project_path),
                              pootle_path="/projects/%s" % project_path)

    item_func = (make_xlanguage_item if
                 (kwargs["dir_path"]
                  or kwargs["filename"]) else make_language_item)
    items = [
        item_func(item) for item in obj.get_children_for_user(request.user)
    ]
    items.sort(lambda x, y: locale.strcoll(x['title'], y['title']))
    stats = obj.data_tool.get_stats(user=request.user)
    for item in items:
        if item["code"] in stats["children"]:
            item["stats"] = stats["children"][item["code"]]
    table_fields = [
        'name', 'progress', 'total', 'need-translation', 'suggestions',
        'critical', 'last-updated', 'activity'
    ]
    table = {
        'id': 'project',
        'fields': table_fields,
        'headings': get_table_headings(table_fields),
        'items': items
    }

    if request.user.is_superuser or kwargs.get("language_code"):
        url_action_continue = obj.get_translate_url(state='incomplete')
        url_action_fixcritical = obj.get_critical_url()
        url_action_review = obj.get_translate_url(state='suggestions')
        url_action_view_all = obj.get_translate_url(state='all')
    else:
        (url_action_continue, url_action_fixcritical, url_action_review,
         url_action_view_all) = [None] * 4
    checks = ChecksDisplay(obj).checks_by_category
    stats = StatsDisplay(obj, stats=stats).stats
    del stats["children"]
    User = get_user_model()
    top_scorers = User.top_scorers(project=project.code, limit=10)
    assertions = dict(page="browse",
                      project=project,
                      browser_extends="projects/base.html",
                      pootle_path="/projects/%s" % project_path,
                      resource_path=resource_path,
                      resource_path_parts=get_path_parts(resource_path),
                      url_action_continue=url_action_continue,
                      url_action_fixcritical=url_action_fixcritical,
                      url_action_review=url_action_review,
                      url_action_view_all=url_action_view_all,
                      translation_states=get_translation_states(obj),
                      table=table,
                      top_scorers=top_scorers,
                      top_scorers_data=get_top_scorers_data(top_scorers, 10),
                      checks=checks,
                      stats=stats)
    sidebar = get_sidebar_announcements_context(request, (project, ))
    for k in ["has_sidebar", "is_sidebar_open", "announcements"]:
        assertions[k] = sidebar[0][k]
    view_context_test(ctx, **assertions)