本文整理汇总了Python中pytest_pootle.suite.view_context_test函数的典型用法代码示例。如果您正苦于以下问题:Python view_context_test函数的具体用法?Python view_context_test怎么用?Python view_context_test使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了view_context_test函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _test_translate_view
def _test_translate_view(tp, request, response, kwargs, settings):
ctx = response.context
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)
vfolder, pootle_path = extract_vfolder_from_path(request_path)
current_vfolder_pk = vfolder.pk if vfolder else ""
display_priority = not current_vfolder_pk and (
VirtualFolderTreeItem.objects.filter(pootle_path__startswith=pootle_path).exists()
)
assertions = dict(
page="translate",
translation_project=tp,
language=tp.language,
project=tp.project,
is_admin=False,
profile=request.profile,
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",
check_categories=get_qualitycheck_schema(),
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),
POOTLE_MT_BACKENDS=settings.POOTLE_MT_BACKENDS,
AMAGAMA_URL=settings.AMAGAMA_URL,
)
view_context_test(ctx, **assertions)
示例2: _test_translate_view
def _test_translate_view(project, request, response, kwargs, settings):
ctx = response.context
user = request.profile
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)
view_context_test(
ctx,
**dict(
page="translate",
is_admin=False,
language=None,
project=project,
profile=user,
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",
check_categories=get_qualitycheck_schema(),
previous_url=get_previous_url(request),
display_priority=(
VirtualFolderTreeItem.objects.filter(
pootle_path__startswith=pootle_path).exists()),
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))
示例3: _test_export_view
def _test_export_view(tp, request, response, kwargs, settings):
ctx = response.context
filter_name, filter_extra = get_filter_name(request.GET)
form_data = request.GET.copy()
form_data["path"] = request.path.replace("export-view/", "")
search_form = UnitExportForm(
form_data, user=request.user)
assert search_form.is_valid()
total, start, end, units_qs = search_backend.get(Unit)(
request.user, **search_form.cleaned_data).search()
units_qs = units_qs.select_related('store')
assertions = {}
if total > settings.POOTLE_EXPORT_VIEW_LIMIT:
units_qs = units_qs[:settings.POOTLE_EXPORT_VIEW_LIMIT]
assertions.update(
{'unit_total_count': total,
'displayed_unit_count': settings.POOTLE_EXPORT_VIEW_LIMIT})
unit_groups = [
(path, list(units))
for path, units
in groupby(
units_qs,
lambda x: x.store.pootle_path)]
assertions.update(
dict(project=tp.project,
language=tp.language,
source_language=tp.project.source_language,
filter_name=filter_name,
filter_extra=filter_extra,
unit_groups=unit_groups))
view_context_test(ctx, **assertions)
示例4: test_view_projects_translate
def test_view_projects_translate(site_permissions, site_matrix_with_vfolders,
client, nobody, default, settings):
response = client.get(reverse("pootle-projects-translate"))
ctx = response.context
request = response.wsgi_request
assertions = dict(
page="translate",
is_admin=False,
language=None,
project=None,
profile=request.profile,
pootle_path="/projects/",
ctx_path="/projects/",
resource_path="",
resource_path_parts=[],
editor_extends="projects/all/base.html",
check_categories=get_qualitycheck_schema(),
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)
示例5: _test_export_view
def _test_export_view(language, request, response, kwargs):
# TODO: export views should be parsed in a form
ctx = response.context
filter_name, filter_extra = get_filter_name(request.GET)
form_data = request.GET.copy()
form_data["path"] = request.path.replace("export-view/", "")
search_form = UnitExportForm(
form_data, user=request.user)
assert search_form.is_valid()
uid_list, units_qs = get_search_backend()(
request.user, **search_form.cleaned_data).search()
units_qs = units_qs.select_related('store')
unit_groups = [
(path, list(units))
for path, units
in groupby(
units_qs,
lambda x: x.store.pootle_path)]
view_context_test(
ctx,
**dict(
project=None,
language=language,
source_language="en",
filter_name=filter_name,
filter_extra=filter_extra,
unit_groups=unit_groups))
示例6: _test_translate_view
def _test_translate_view(language, request, response, kwargs, settings):
ctx = response.context
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=[],
profile=request.profile,
editor_extends="languages/base.html",
check_categories=get_qualitycheck_schema(),
previous_url=get_previous_url(request),
display_priority=False,
is_admin=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))
示例7: test_view_projects_translate
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
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",
check_categories=get_qualitycheck_schema(),
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)
示例8: _test_export_view
def _test_export_view(tp, request, response, kwargs):
ctx = response.context
filter_name, filter_extra = get_filter_name(request.GET)
form_data = request.GET.copy()
form_data["path"] = request.path.replace("export-view/", "")
search_form = UnitExportForm(
form_data, user=request.user)
assert search_form.is_valid()
total, start, end, units_qs = search_backend.get(Unit)(
request.user, **search_form.cleaned_data).search()
units_qs = units_qs.select_related('store')
unit_groups = [
(path, list(units))
for path, units
in groupby(
units_qs,
lambda x: x.store.pootle_path)]
view_context_test(
ctx,
**dict(
project=tp.project,
language=tp.language,
source_language=tp.project.source_language,
filter_name=filter_name,
filter_extra=filter_extra,
unit_groups=unit_groups))
示例9: test_view_projects_export
def test_view_projects_export(client):
response = client.get(reverse("pootle-projects-export"))
ctx = response.context
request = response.wsgi_request
filter_name, filter_extra = get_filter_name(request.GET)
form_data = request.GET.copy()
form_data["path"] = request.path.replace("export-view/", "")
search_form = UnitExportForm(
form_data, user=request.user)
assert search_form.is_valid()
total, start, end, units_qs = search_backend.get(Unit)(
request.user, **search_form.cleaned_data).search()
units_qs = units_qs.select_related('store')
unit_groups = [
(path, list(units))
for path, units
in groupby(
units_qs,
lambda x: x.store.pootle_path)]
assertions = dict(
project=None,
language=None,
source_language="en",
filter_name=filter_name,
filter_extra=filter_extra,
unit_groups=unit_groups)
view_context_test(ctx, **assertions)
示例10: test_view_projects_browse
def test_view_projects_browse(client, request_users):
user = request_users["user"]
client.login(
username=user.username,
password=request_users["password"])
response = client.get(reverse("pootle-projects-browse"))
assert response.cookies["pootle-language"].value == "projects"
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)
items = [
make_project_list_item(project)
for project in obj.children]
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': 'projects',
'fields': table_fields,
'headings': get_table_headings(table_fields),
'items': items}
if request.user.is_superuser:
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(limit=10)
assertions = dict(
page="browse",
pootle_path="/projects/",
resource_path="",
resource_path_parts=[],
object=obj,
table=table,
browser_extends="projects/all/base.html",
stats=obj.data_tool.get_stats(user=request.user),
checks=get_qualitycheck_list(obj),
top_scorers=top_scorers,
top_scorers_data=get_top_scorers_data(top_scorers, 10),
translation_states=get_translation_states(obj),
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)
view_context_test(ctx, **assertions)
示例11: test_view_projects_browse
def test_view_projects_browse(client, request_users):
user = request_users["user"]
client.login(
username=user.username,
password=request_users["password"])
response = client.get(reverse("pootle-projects-browse"))
assert response.cookies["pootle-language"].value == "projects"
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)
stats = obj.data_tool.get_stats(user=request.user)
if request.user.is_superuser:
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"]
chunk_size = TOP_CONTRIBUTORS_CHUNK_SIZE
score_data = scores.get(ProjectSet)(obj)
def scores_to_json(score):
score["user"] = score["user"].to_dict()
return score
top_scorers = score_data.display(
limit=chunk_size,
formatter=scores_to_json)
top_scorer_data = dict(
items=list(top_scorers),
has_more_items=len(score_data.top_scorers) > chunk_size)
assertions = dict(
page="browse",
pootle_path="/projects/",
resource_path="",
resource_path_parts=[],
object=obj,
browser_extends="projects/all/base.html",
top_scorers=top_scorer_data,
translation_states=get_translation_states(obj),
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,
checks=checks,
stats=stats)
view_context_test(ctx, **assertions)
示例12: _test_translate_view
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)
示例13: _test_translate_view
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)
if request.path.startswith("/++vfolder"):
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, "")]))
else:
vfolder = None
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",
check_categories=get_qualitycheck_schema(),
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)
示例14: _test_browse_view
def _test_browse_view(language, request, response, kwargs):
assert response.cookies["pootle-language"].value == language.code
assert (request.user.is_anonymous
or "announcements/%s" % language.code in request.session)
ctx = response.context
user_tps = language.get_children_for_user(request.user)
stats = language.data_tool.get_stats(user=request.user)
items = [make_project_item(tp) for tp in user_tps]
for item in items:
if item["code"] in stats["children"]:
item["stats"] = stats["children"][item["code"]]
checks = ChecksDisplay(language).checks_by_category
stats = StatsDisplay(language, stats=stats).stats
del stats["children"]
score_data = scores.get(language.__class__)(language)
chunk_size = TOP_CONTRIBUTORS_CHUNK_SIZE
def scores_to_json(score):
score["user"] = score["user"].to_dict()
return score
top_scorers = score_data.display(
limit=chunk_size,
formatter=scores_to_json)
top_scorer_data = dict(
items=list(top_scorers),
has_more_items=len(score_data.top_scorers) > chunk_size)
assertions = dict(
page="browse",
object=language,
language={
'code': language.code,
'name': language.name},
browser_extends="languages/base.html",
pootle_path="/%s/" % language.code,
resource_path="",
resource_path_parts=[],
url_action_continue=language.get_translate_url(state='incomplete'),
url_action_fixcritical=language.get_critical_url(),
url_action_review=language.get_translate_url(state='suggestions'),
url_action_view_all=language.get_translate_url(state='all'),
# check_categories=get_qualitycheck_schema(language),
translation_states=get_translation_states(language),
top_scorers=top_scorer_data,
checks=checks,
stats=stats)
sidebar = get_sidebar_announcements_context(request, (language, ))
for k in ["has_sidebar", "is_sidebar_open", "announcements"]:
assertions[k] = sidebar[k]
view_context_test(ctx, **assertions)
示例15: _test_browse_view
def _test_browse_view(language, request, response, kwargs):
assert (
response.cookies["pootle-language"].value == language.code)
cookie_data = json.loads(
unquote(response.cookies[SIDEBAR_COOKIE_NAME].value))
assert cookie_data["foo"] == "bar"
assert "announcements_%s" % language.code in cookie_data
ctx = response.context
table_fields = [
'name', 'progress', 'total', 'need-translation',
'suggestions', 'critical', 'last-updated', 'activity']
user_tps = language.get_children_for_user(request.user)
items = [make_project_item(tp) for tp in user_tps]
table = {
'id': 'language',
'fields': table_fields,
'headings': get_table_headings(table_fields),
'items': items}
top_scorers = get_user_model().top_scorers(language=language.code, limit=10)
assertions = dict(
page="browse",
object=language,
language={
'code': language.code,
'name': language.name},
browser_extends="languages/base.html",
pootle_path="/%s/" % language.code,
resource_path="",
resource_path_parts=[],
url_action_continue=language.get_translate_url(state='incomplete'),
url_action_fixcritical=language.get_critical_url(),
url_action_review=language.get_translate_url(state='suggestions'),
url_action_view_all=language.get_translate_url(state='all'),
# check_categories=get_qualitycheck_schema(language),
table=table,
translation_states=get_translation_states(language),
top_scorers=top_scorers,
top_scorers_data=get_top_scorers_data(top_scorers, 10),
stats=language.data_tool.get_stats(user=request.user)
)
sidebar = get_sidebar_announcements_context(
request, (language, ))
for k in ["has_sidebar", "is_sidebar_open", "announcements"]:
assertions[k] = sidebar[0][k]
view_context_test(ctx, **assertions)