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)
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)
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)
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))
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)
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))
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)
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))
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)
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))
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))
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 item in d.values()], key=lambda x: x['code'], reverse=True) assert result == get_qualitycheck_schema()
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))
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') 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.')