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(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 #3
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 #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_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 #7
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 #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_get_qualitycheck_list(tp0):
    result = []
    checks = get_qualitychecks()
    for check, cat in checks.items():
        result.append({
            'code': check,
            'is_critical': cat == Category.CRITICAL,
            'title': u"%s" % check_names.get(check, check),
            'url': tp0.get_translate_url(check=check)
        })

    def alphabetical_critical_first(item):
        sort_prefix = 0 if item['is_critical'] else 1
        return "%d%s" % (sort_prefix, item['title'].lower())

    result = sorted(result, key=alphabetical_critical_first)

    assert result == get_qualitycheck_list(tp0)
Beispiel #10
0
def test_get_qualitycheck_list(tp0):
    result = []
    checks = get_qualitychecks()
    for check, cat in checks.items():
        result.append({
            'code': check,
            'is_critical': cat == Category.CRITICAL,
            'title': u"%s" % check_names.get(check, check),
            'url': tp0.get_translate_url(check=check)
        })

    def alphabetical_critical_first(item):
        sort_prefix = 0 if item['is_critical'] else 1
        return "%d%s" % (sort_prefix, item['title'].lower())

    result = sorted(result, key=alphabetical_critical_first)

    assert result == get_qualitycheck_list(tp0)
Beispiel #11
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 #12
0
def test_get_qualitycheck_schema():
    d = {}
    checks = get_qualitychecks()
    for check, cat in checks.items():
        if cat not in d:
            d[cat] = {
                "code": cat,
                "name": get_category_code(cat),
                "title": get_category_name(cat),
                "checks": [],
            }
        d[cat]["checks"].append(
            {"code": check, "title": u"%s" % check_names.get(check, check)}
        )
        d[cat]["checks"] = sorted(d[cat]["checks"], key=lambda x: x["code"])

    result = sorted(
        [item for item in d.values()], key=lambda x: x["code"], reverse=True
    )

    assert result == get_qualitycheck_schema()
Beispiel #13
0
def test_get_qualitycheck_schema():
    d = {}
    checks = get_qualitychecks()
    for check, cat in checks.items():
        if cat not in d:
            d[cat] = {
                'code': cat,
                'name': get_category_code(cat),
                'title': get_category_name(cat),
                'checks': []
            }
        d[cat]['checks'].append({
            'code': check,
            'title': u"%s" % check_names.get(check, check),
        })
        d[cat]['checks'] = sorted(d[cat]['checks'], key=lambda x: x['code'])

    result = sorted([item for item in d.values()],
                    key=lambda x: x['code'],
                    reverse=True)

    assert result == get_qualitycheck_schema()
Beispiel #14
0
def test_get_qualitycheck_schema():
    d = {}
    checks = get_qualitychecks()
    for check, cat in checks.items():
        if cat not in d:
            d[cat] = {
                'code': cat,
                'name': get_category_code(cat),
                'title': get_category_name(cat),
                'checks': []
            }
        d[cat]['checks'].append({
            'code': check,
            'title': u"%s" % check_names.get(check, check),
            'url': ''
        })

    result = sorted([item for code, item in d.items()],
                    key=lambda x: x['code'],
                    reverse=True)

    assert result == get_qualitycheck_schema()
Beispiel #15
0
                unit = Unit.objects.get(id=unit_id)
                source = unit.source
                target = unit.target
            except Unit.DoesNotExist, e:
                raise CommandError(e.message)
        else:
            source = options.get('source', '').decode('utf-8')
            target = options.get('target', '').decode('utf-8')

        if settings.POOTLE_QUALITY_CHECKER:
            checkers = [import_func(settings.POOTLE_QUALITY_CHECKER)()]
        else:
            checkers = [checker() for checker in projectcheckers.values()]

        if not checks:
            checks = get_qualitychecks().keys()

        error_checks = []
        for checker in checkers:
            for check in checks:
                filtermessage = ''
                if check in error_checks:
                    continue
                try:
                    if hasattr(checker, check):
                        test = getattr(checker, check)
                        try:
                            filterresult = test(source, target)
                        except AttributeError:
                            continue
                except FilterFailure, e:
Beispiel #16
0
class Command(NoArgsCommand):
    help = "Tests quality checks against string pairs."

    shared_option_list = (
        make_option('--check',
                    action='append',
                    dest='checks',
                    help='Check name to check for'),
        make_option('--source', dest='source', help='Source string'),
        make_option('--unit', dest='unit', help='Unit id'),
        make_option('--target', dest='target', help='Translation string'),
    )
    option_list = NoArgsCommand.option_list + shared_option_list

    def handle_noargs(self, **options):
        # adjust debug level to the verbosity option
        verbosity = int(options.get('verbosity', 1))
        debug_levels = {
            0: logging.ERROR,
            1: logging.WARNING,
            2: logging.INFO,
            3: logging.DEBUG
        }
        debug_level = debug_levels.get(verbosity, logging.DEBUG)
        logging.getLogger().setLevel(debug_level)
        self.name = self.__class__.__module__.split('.')[-1]

        source = options.get('source', '')
        target = options.get('target', '')
        unit_id = options.get('unit', '')
        checks = options.get('checks', [])

        if (source and target) == bool(unit_id):
            raise CommandError("Either --unit or a pair of --source "
                               "and --target must be provided.")

        if unit_id:
            try:
                unit = Unit.objects.get(id=unit_id)
                source = unit.source
                target = unit.target
            except Unit.DoesNotExist, e:
                raise CommandError(e.message)

        checker = ENChecker()

        if not checks:
            checks = get_qualitychecks().keys()

        error_checks = []
        for check in checks:
            filtermessage = ''
            try:
                test = getattr(checker, check)
                filterresult = test(source, target)
            except FilterFailure, e:
                filterresult = False
                filtermessage = unicode(e)

            message = "%s - %s" % (filterresult, check)
            if filtermessage:
                message += ": %s" % filtermessage
            logging.info(message)

            if not filterresult:
                error_checks.append(check)
Beispiel #17
0
                unit = Unit.objects.get(id=unit_id)
                source = unit.source
                target = unit.target
            except Unit.DoesNotExist, e:
                raise CommandError(e.message)
        else:
            source = options.get('source', '').decode('utf-8')
            target = options.get('target', '').decode('utf-8')

        if settings.POOTLE_QUALITY_CHECKER:
            checkers = [import_func(settings.POOTLE_QUALITY_CHECKER)()]
        else:
            checkers = [checker() for checker in projectcheckers.values()]

        if not checks:
            checks = get_qualitychecks().keys()

        error_checks = []
        for checker in checkers:
            for check in checks:
                filtermessage = ''
                if check in error_checks:
                    continue
                try:
                    if hasattr(checker, check):
                        test = getattr(checker, check)
                        try:
                            filterresult = test(source, target)
                        except AttributeError:
                            continue
                except FilterFailure, e:
Beispiel #18
0
    def handle(self, **options):
        # adjust debug level to the verbosity option
        debug_levels = {
            0: logging.ERROR,
            1: logging.WARNING,
            2: logging.INFO,
            3: logging.DEBUG
        }
        debug_level = debug_levels.get(options['verbosity'], logging.DEBUG)
        logging.getLogger().setLevel(debug_level)
        self.name = self.__class__.__module__.split('.')[-1]

        if ((options['unit'] is not None and
             (options['source'] or options['target']))
                or (options['unit'] is None and not options['source']
                    and not options['target'])):
            raise CommandError("Either --unit or a pair of --source "
                               "and --target must be provided.")
        if bool(options['source']) != bool(options['target']):
            raise CommandError("Use a pair of --source and --target.")

        checks = options.get('checks', [])

        if options['unit'] is not None:
            try:
                unit = Unit.objects.get(id=options['unit'])
                source = unit.source
                target = unit.target
            except Unit.DoesNotExist as e:
                raise CommandError(e)
        else:
            source = options['source'].decode('utf-8')
            target = options['target'].decode('utf-8')

        if settings.POOTLE_QUALITY_CHECKER:
            checkers = [import_func(settings.POOTLE_QUALITY_CHECKER)()]
        else:
            checkers = [checker() for checker in projectcheckers.values()]

        if not checks:
            checks = get_qualitychecks().keys()

        error_checks = []
        for checker in checkers:
            for check in checks:
                filtermessage = ''
                filterresult = True
                if check in error_checks:
                    continue
                try:
                    if hasattr(checker, check):
                        test = getattr(checker, check)
                        try:
                            filterresult = test(source, target)
                        except AttributeError:
                            continue
                except FilterFailure as e:
                    filterresult = False
                    filtermessage = unicode(e)

                message = "%s - %s" % (filterresult, check)
                if filtermessage:
                    message += ": %s" % filtermessage
                logging.info(message)

                if not filterresult:
                    error_checks.append(check)

        if error_checks:
            self.stdout.write('Failing checks: %s' % ', '.join(error_checks))
        else:
            self.stdout.write('No errors found.')
Beispiel #19
0
    def handle(self, **options):
        # adjust debug level to the verbosity option
        debug_levels = {
            0: logging.ERROR,
            1: logging.WARNING,
            2: logging.INFO,
            3: logging.DEBUG
        }
        debug_level = debug_levels.get(options['verbosity'], logging.DEBUG)
        logging.getLogger().setLevel(debug_level)
        self.name = self.__class__.__module__.split('.')[-1]

        if ((options['unit'] is not None
             and (options['source'] or options['target']))
            or (options['unit'] is None
                and not options['source']
                and not options['target'])):
            raise CommandError("Either --unit or a pair of --source "
                               "and --target must be provided.")
        if bool(options['source']) != bool(options['target']):
            raise CommandError("Use a pair of --source and --target.")

        checks = options.get('checks', [])

        if options['unit'] is not None:
            try:
                unit = Unit.objects.get(id=options['unit'])
                source = unit.source
                target = unit.target
            except Unit.DoesNotExist as e:
                raise CommandError(e)
        else:
            source = options['source'].decode('utf-8')
            target = options['target'].decode('utf-8')

        if settings.POOTLE_QUALITY_CHECKER:
            checkers = [import_func(settings.POOTLE_QUALITY_CHECKER)()]
        else:
            checkers = [checker() for checker in projectcheckers.values()]

        if not checks:
            checks = get_qualitychecks().keys()

        error_checks = []
        for checker in checkers:
            for check in checks:
                filtermessage = ''
                filterresult = True
                if check in error_checks:
                    continue
                try:
                    if hasattr(checker, check):
                        test = getattr(checker, check)
                        try:
                            filterresult = test(source, target)
                        except AttributeError:
                            continue
                except FilterFailure as e:
                    filterresult = False
                    filtermessage = unicode(e)

                message = "%s - %s" % (filterresult, check)
                if filtermessage:
                    message += ": %s" % filtermessage
                logging.info(message)

                if not filterresult:
                    error_checks.append(check)

        if error_checks:
            self.stdout.write('Failing checks: %s' % ', '.join(error_checks))
        else:
            self.stdout.write('No errors found.')
Beispiel #20
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)