Beispiel #1
0
def test_view_projects_translate(client, settings, request_users):
    user = request_users["user"]
    client.login(
        username=user.username,
        password=request_users["password"])
    response = client.get(reverse("pootle-projects-translate"))

    if not user.is_superuser:
        assert response.status_code == 403
        return
    ctx = response.context
    request = response.wsgi_request
    user_projects = Project.accessible_by_user(request.user)
    user_projects = (
        Project.objects.for_user(request.user)
                       .filter(code__in=user_projects))
    obj = ProjectSet(user_projects)
    checks = get_qualitychecks()
    schema = {sc["code"]: sc for sc in get_qualitycheck_schema()}
    check_data = obj.data_tool.get_checks()
    _checks = {}
    for check, checkid in checks.items():
        if check not in check_data:
            continue
        _checkid = schema[checkid]["name"]
        _checks[_checkid] = _checks.get(
            _checkid, dict(checks=[], title=schema[checkid]["title"]))
        _checks[_checkid]["checks"].append(
            dict(
                code=check,
                title=check_names[check],
                count=check_data[check]))
    _checks = OrderedDict(
        (k, _checks[k])
        for k in CATEGORY_IDS.keys()
        if _checks.get(k))
    assertions = dict(
        page="translate",
        has_admin_access=user.is_superuser,
        language=None,
        project=None,
        pootle_path="/projects/",
        ctx_path="/projects/",
        resource_path="",
        resource_path_parts=[],
        editor_extends="projects/all/base.html",
        checks=_checks,
        previous_url=get_previous_url(request),
        display_priority=False,
        cantranslate=check_permission("translate", request),
        cansuggest=check_permission("suggest", request),
        canreview=check_permission("review", request),
        search_form=make_search_form(request=request),
        current_vfolder_pk="",
        POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
        AMAGAMA_URL=settings.AMAGAMA_URL)
    view_context_test(ctx, **assertions)
Beispiel #2
0
def _test_translate_view(project, request, response, kwargs, settings):

    if not request.user.is_superuser:
        assert response.status_code == 403
        return

    ctx = response.context
    kwargs["project_code"] = project.code
    ctx_path = (
        "/projects/%(project_code)s/" % kwargs)
    resource_path = (
        "%(dir_path)s%(filename)s" % kwargs)
    pootle_path = "%s%s" % (ctx_path, resource_path)
    display_priority = False

    checks = get_qualitychecks()
    schema = {sc["code"]: sc for sc in get_qualitycheck_schema()}
    check_data = ctx["object"].data_tool.get_checks()
    _checks = {}
    for check, checkid in checks.items():
        if check not in check_data:
            continue
        _checkid = schema[checkid]["name"]
        _checks[_checkid] = _checks.get(
            _checkid, dict(checks=[], title=schema[checkid]["title"]))
        _checks[_checkid]["checks"].append(
            dict(
                code=check,
                title=check_names[check],
                count=check_data[check]))
    _checks = OrderedDict(
        (k, _checks[k])
        for k in CATEGORY_IDS.keys()
        if _checks.get(k))
    view_context_test(
        ctx,
        **dict(
            page="translate",
            has_admin_access=request.user.is_superuser,
            language=None,
            project=project,
            pootle_path=pootle_path,
            ctx_path=ctx_path,
            resource_path=resource_path,
            resource_path_parts=get_path_parts(resource_path),
            editor_extends="projects/base.html",
            checks=_checks,
            previous_url=get_previous_url(request),
            display_priority=display_priority,
            cantranslate=check_permission("translate", request),
            cansuggest=check_permission("suggest", request),
            canreview=check_permission("review", request),
            search_form=make_search_form(request=request),
            current_vfolder_pk="",
            POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
            AMAGAMA_URL=settings.AMAGAMA_URL))
Beispiel #3
0
def _test_translate_view(tp, request, response, kwargs, settings):
    ctx = response.context
    obj = ctx["object"]
    kwargs["project_code"] = tp.project.code
    kwargs["language_code"] = tp.language.code
    resource_path = "%(dir_path)s%(filename)s" % kwargs
    request_path = "%s%s" % (tp.pootle_path, resource_path)

    checks = get_qualitychecks()
    schema = {sc["code"]: sc for sc in get_qualitycheck_schema()}
    check_data = obj.data_tool.get_checks()
    _checks = {}
    for check, checkid in checks.items():
        if check not in check_data:
            continue
        _checkid = schema[checkid]["name"]
        _checks[_checkid] = _checks.get(
            _checkid, dict(checks=[], title=schema[checkid]["title"]))
        _checks[_checkid]["checks"].append(
            dict(
                code=check,
                title=check_names[check],
                count=check_data[check]))
    _checks = OrderedDict(
        (k, _checks[k])
        for k in CATEGORY_IDS.keys()
        if _checks.get(k))
    current_vfolder_pk = ""
    display_priority = False
    if not kwargs["filename"]:
        vf_view = vfolders_data_view.get(obj.__class__)(obj, request.user)
        display_priority = vf_view.has_data
    unit_api_root = "/xhr/units/"
    assertions = dict(
        page="translate",
        translation_project=tp,
        language=tp.language,
        project=tp.project,
        has_admin_access=check_permission('administrate', request),
        ctx_path=tp.pootle_path,
        pootle_path=request_path,
        resource_path=resource_path,
        resource_path_parts=get_path_parts(resource_path),
        editor_extends="translation_projects/base.html",
        checks=_checks,
        previous_url=get_previous_url(request),
        current_vfolder_pk=current_vfolder_pk,
        display_priority=display_priority,
        cantranslate=check_permission("translate", request),
        cansuggest=check_permission("suggest", request),
        canreview=check_permission("review", request),
        search_form=make_search_form(request=request),
        unit_api_root=unit_api_root,
        POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
        AMAGAMA_URL=settings.AMAGAMA_URL)
    view_context_test(ctx, **assertions)
Beispiel #4
0
 def checks(self):
     check_data = self.check_data
     checks = get_qualitychecks()
     schema = {sc["code"]: sc for sc in get_qualitycheck_schema()}
     _checks = {}
     for check, checkid in checks.items():
         if check not in check_data:
             continue
         _checkid = schema[checkid]["name"]
         _checks[_checkid] = _checks.get(_checkid, dict(checks=[], title=schema[checkid]["title"]))
         _checks[_checkid]["checks"].append(dict(code=check, title=check_names[check], count=check_data[check]))
     return OrderedDict((k, _checks[k]) for k in CATEGORY_IDS.keys() if _checks.get(k))
Beispiel #5
0
def _test_translate_view(tp, request, response, kwargs, settings):
    ctx = response.context
    obj = ctx["object"]
    kwargs["project_code"] = tp.project.code
    kwargs["language_code"] = tp.language.code
    resource_path = "%(dir_path)s%(filename)s" % kwargs
    request_path = "%s%s" % (tp.pootle_path, resource_path)

    checks = get_qualitychecks()
    schema = {sc["code"]: sc for sc in get_qualitycheck_schema()}
    check_data = obj.data_tool.get_checks()
    _checks = {}
    for check, checkid in checks.items():
        if check not in check_data:
            continue
        _checkid = schema[checkid]["name"]
        _checks[_checkid] = _checks.get(
            _checkid, dict(checks=[], title=schema[checkid]["title"]))
        _checks[_checkid]["checks"].append(
            dict(code=check, title=check_names[check],
                 count=check_data[check]))
    _checks = OrderedDict(
        (k, _checks[k]) for k in CATEGORY_IDS.keys() if _checks.get(k))
    current_vfolder_pk = ""
    display_priority = False
    if not kwargs["filename"]:
        vf_view = vfolders_data_view.get(obj.__class__)(obj, request.user)
        display_priority = vf_view.has_data
    unit_api_root = "/xhr/units/"
    assertions = dict(page="translate",
                      translation_project=tp,
                      language=tp.language,
                      project=tp.project,
                      has_admin_access=check_permission(
                          'administrate', request),
                      ctx_path=tp.pootle_path,
                      pootle_path=request_path,
                      resource_path=resource_path,
                      resource_path_parts=get_path_parts(resource_path),
                      editor_extends="translation_projects/base.html",
                      checks=_checks,
                      previous_url=get_previous_url(request),
                      current_vfolder_pk=current_vfolder_pk,
                      display_priority=display_priority,
                      cantranslate=check_permission("translate", request),
                      cansuggest=check_permission("suggest", request),
                      canreview=check_permission("review", request),
                      search_form=make_search_form(request=request),
                      unit_api_root=unit_api_root,
                      POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
                      AMAGAMA_URL=settings.AMAGAMA_URL)
    view_context_test(ctx, **assertions)
Beispiel #6
0
def _test_translate_view(project, request, response, kwargs, settings):

    if not request.user.is_superuser:
        assert response.status_code == 403
        return

    ctx = response.context
    kwargs["project_code"] = project.code
    ctx_path = ("/projects/%(project_code)s/" % kwargs)
    resource_path = ("%(dir_path)s%(filename)s" % kwargs)
    pootle_path = "%s%s" % (ctx_path, resource_path)
    display_priority = False

    checks = get_qualitychecks()
    schema = {sc["code"]: sc for sc in get_qualitycheck_schema()}
    check_data = ctx["object"].data_tool.get_checks()
    _checks = {}
    for check, checkid in checks.items():
        if check not in check_data:
            continue
        _checkid = schema[checkid]["name"]
        _checks[_checkid] = _checks.get(
            _checkid, dict(checks=[], title=schema[checkid]["title"]))
        _checks[_checkid]["checks"].append(
            dict(code=check, title=check_names[check],
                 count=check_data[check]))
    _checks = OrderedDict(
        (k, _checks[k]) for k in CATEGORY_IDS.keys() if _checks.get(k))
    view_context_test(
        ctx,
        **dict(page="translate",
               has_admin_access=request.user.is_superuser,
               language=None,
               project=project,
               pootle_path=pootle_path,
               ctx_path=ctx_path,
               resource_path=resource_path,
               resource_path_parts=get_path_parts(resource_path),
               editor_extends="projects/base.html",
               checks=_checks,
               previous_url=get_previous_url(request),
               display_priority=display_priority,
               cantranslate=check_permission("translate", request),
               cansuggest=check_permission("suggest", request),
               canreview=check_permission("review", request),
               search_form=make_search_form(request=request),
               current_vfolder_pk="",
               POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
               AMAGAMA_URL=settings.AMAGAMA_URL))
Beispiel #7
0
def test_view_projects_translate(client, settings, request_users):
    user = request_users["user"]
    client.login(username=user.username, password=request_users["password"])
    response = client.get(reverse("pootle-projects-translate"))

    if not user.is_superuser:
        assert response.status_code == 403
        return
    ctx = response.context
    request = response.wsgi_request
    user_projects = Project.accessible_by_user(request.user)
    user_projects = (Project.objects.for_user(
        request.user).filter(code__in=user_projects))
    obj = ProjectSet(user_projects)
    checks = get_qualitychecks()
    schema = {sc["code"]: sc for sc in get_qualitycheck_schema()}
    check_data = obj.data_tool.get_checks()
    _checks = {}
    for check, checkid in checks.items():
        if check not in check_data:
            continue
        _checkid = schema[checkid]["name"]
        _checks[_checkid] = _checks.get(
            _checkid, dict(checks=[], title=schema[checkid]["title"]))
        _checks[_checkid]["checks"].append(
            dict(code=check, title=check_names[check],
                 count=check_data[check]))
    _checks = OrderedDict(
        (k, _checks[k]) for k in CATEGORY_IDS.keys() if _checks.get(k))
    assertions = dict(page="translate",
                      has_admin_access=user.is_superuser,
                      language=None,
                      project=None,
                      pootle_path="/projects/",
                      ctx_path="/projects/",
                      resource_path="",
                      resource_path_parts=[],
                      editor_extends="projects/all/base.html",
                      checks=_checks,
                      previous_url=get_previous_url(request),
                      display_priority=False,
                      cantranslate=check_permission("translate", request),
                      cansuggest=check_permission("suggest", request),
                      canreview=check_permission("review", request),
                      search_form=make_search_form(request=request),
                      current_vfolder_pk="",
                      POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
                      AMAGAMA_URL=settings.AMAGAMA_URL)
    view_context_test(ctx, **assertions)
Beispiel #8
0
 def checks(self):
     check_data = self.check_data
     checks = get_qualitychecks()
     schema = {sc["code"]: sc for sc in get_qualitycheck_schema()}
     _checks = {}
     for check, checkid in checks.items():
         if check not in check_data:
             continue
         _checkid = schema[checkid]["name"]
         _checks[_checkid] = _checks.get(
             _checkid, dict(checks=[], title=schema[checkid]["title"]))
         _checks[_checkid]["checks"].append(
             dict(code=check,
                  title=check_names[check],
                  count=check_data[check]))
     return OrderedDict(
         (k, _checks[k]) for k in CATEGORY_IDS.keys() if _checks.get(k))
Beispiel #9
0
def _test_translate_view(language, request, response, kwargs, settings):
    ctx = response.context
    checks = get_qualitychecks()
    schema = {sc["code"]: sc for sc in get_qualitycheck_schema()}
    check_data = language.data_tool.get_checks()
    _checks = {}
    for check, checkid in checks.items():
        if check not in check_data:
            continue
        _checkid = schema[checkid]["name"]
        _checks[_checkid] = _checks.get(
            _checkid, dict(checks=[], title=schema[checkid]["title"]))
        _checks[_checkid]["checks"].append(
            dict(
                code=check,
                title=check_names[check],
                count=check_data[check]))
    _checks = OrderedDict(
        (k, _checks[k])
        for k in CATEGORY_IDS.keys()
        if _checks.get(k))
    view_context_test(
        ctx,
        **dict(
            project=None,
            language=language,
            page="translate",
            ctx_path=language.directory.pootle_path,
            pootle_path=language.directory.pootle_path,
            resource_path="",
            resource_path_parts=[],
            editor_extends="languages/base.html",
            checks=_checks,
            previous_url=get_previous_url(request),
            display_priority=False,
            has_admin_access=check_permission('administrate', request),
            cantranslate=check_permission("translate", request),
            cansuggest=check_permission("suggest", request),
            canreview=check_permission("review", request),
            search_form=make_search_form(request=request),
            current_vfolder_pk="",
            POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
            AMAGAMA_URL=settings.AMAGAMA_URL))
Beispiel #10
0
 def to_python(self, value):
     if value is not None:
         return CATEGORY_IDS.get(value)
Beispiel #11
0
def _test_vf_translate_view(tp, request, response, kwargs, settings):
    from .tp import view_context_test

    ctx = response.context
    obj = ctx["object"]
    kwargs["project_code"] = tp.project.code
    kwargs["language_code"] = tp.language.code
    resource_path = "%(dir_path)s%(filename)s" % kwargs
    request_path = "%s%s" % (tp.pootle_path, resource_path)

    checks = get_qualitychecks()
    schema = {sc["code"]: sc for sc in get_qualitycheck_schema()}
    vfolder_pk = response.context["current_vfolder_pk"]
    check_data = DirectoryVFDataTool(obj).get_checks(
        user=request.user).get(vfolder_pk, {})
    _checks = {}
    for check, checkid in checks.items():
        if check not in check_data:
            continue
        _checkid = schema[checkid]["name"]
        _checks[_checkid] = _checks.get(
            _checkid, dict(checks=[], title=schema[checkid]["title"]))
        _checks[_checkid]["checks"].append(
            dict(
                code=check,
                title=check_names[check],
                count=check_data[check]))
    _checks = OrderedDict(
        (k, _checks[k])
        for k in CATEGORY_IDS.keys()
        if _checks.get(k))
    vfolder = VirtualFolder.objects.get(
        name=request.resolver_match.kwargs["vfolder_name"])
    current_vfolder_pk = vfolder.pk
    display_priority = False
    unit_api_root = reverse(
        "vfolder-pootle-xhr-units",
        kwargs=dict(vfolder_name=vfolder.name))
    resource_path = (
        "/".join(
            ["++vfolder",
             vfolder.name,
             ctx['object'].pootle_path.replace(tp.pootle_path, "")]))
    assertions = dict(
        page="translate",
        translation_project=tp,
        language=tp.language,
        project=tp.project,
        has_admin_access=check_permission('administrate', request),
        ctx_path=tp.pootle_path,
        pootle_path=request_path,
        resource_path=resource_path,
        resource_path_parts=get_path_parts(resource_path),
        editor_extends="translation_projects/base.html",
        checks=_checks,
        previous_url=get_previous_url(request),
        current_vfolder_pk=current_vfolder_pk,
        display_priority=display_priority,
        cantranslate=check_permission("translate", request),
        cansuggest=check_permission("suggest", request),
        canreview=check_permission("review", request),
        search_form=make_search_form(request=request),
        unit_api_root=unit_api_root,
        POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
        AMAGAMA_URL=settings.AMAGAMA_URL)
    view_context_test(ctx, **assertions)
Beispiel #12
0
 def to_python(self, value):
     if value is not None:
         return CATEGORY_IDS.get(value)