本文整理汇总了Python中tcms.xmlrpc.utils.pre_process_ids函数的典型用法代码示例。如果您正苦于以下问题:Python pre_process_ids函数的具体用法?Python pre_process_ids怎么用?Python pre_process_ids使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pre_process_ids函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: detach_issue
def detach_issue(request, case_run_ids, issue_keys):
"""Remove one or more issues to the selected test case-runs.
:param case_run_ids: give one or more case run IDs. It could be an integer,
a string containing comma separated IDs, or a list of int each of them
is a case run ID.
:type run_ids: int, str or list
:param issue_keys: give one or more case run IDs. It could be an integer,
a string containing comma separated IDs, or a list of int each of them
is a case run ID.
:type issue_keys: int, str or list
:return: a list which is empty on success or a list of mappings with
failure codes if a failure occured.
:rtype: list
Example::
# Remove issue 1000 from case run 1
>>> TestCaseRun.detach_issue(1, 1000)
# Remove issues [1000, 2000] from case runs list [1, 2]
>>> TestCaseRun.detach_issue([1, 2], [1000, 2000])
# Remove issues '1000, 2000' from case runs list '1, 2' with String
>>> TestCaseRun.detach_issue('1, 2', '1000, 2000')
"""
tcrs = TestCaseRun.objects.filter(pk__in=pre_process_ids(case_run_ids))
issue_keys = pre_process_ids(issue_keys)
for tcr in tcrs.iterator():
for issue_key in issue_keys:
tcr.remove_issue(issue_key=issue_key, case_run=tcr)
示例2: add_cases
def add_cases(request, run_ids, case_ids):
"""
Description: Add one or more cases to the selected test runs.
Params: $run_ids - Integer/Array/String: An integer representing the ID in the database
an array of IDs, or a comma separated list of IDs.
$case_ids - Integer/Array/String: An integer or alias representing the ID in the database,
an arry of case_ids or aliases, or a string of comma separated case_ids.
Returns: Array: empty on success or an array of hashes with failure
codes if a failure occured.
Example:
# Add case id 54321 to run 1234
>>> TestRun.add_cases(1234, 54321)
# Add case ids list [1234, 5678] to run list [56789, 12345]
>>> TestRun.add_cases([56789, 12345], [1234, 5678])
# Add case ids list '1234, 5678' to run list '56789, 12345' with String
>>> TestRun.add_cases('56789, 12345', '1234, 5678')
"""
trs = TestRun.objects.filter(run_id__in=pre_process_ids(run_ids))
tcs = TestCase.objects.filter(case_id__in=pre_process_ids(case_ids))
for tr in trs.iterator():
for tc in tcs.iterator():
tr.add_case_run(case=tc)
return
示例3: detach_bug
def detach_bug(request, case_ids, bug_ids):
"""
Description: Remove one or more bugs to the selected test cases.
Params: $case_ids - Integer/Array/String: An integer representing the ID in the database,
an array of case_ids, or a string of comma separated case_ids
$bug_ids - Integer/Array/String: An integer representing the ID in the database,
an array of bug_ids, or a string of comma separated primary key of bug_ids.
Returns: Array: empty on success or an array of hashes with failure
codes if a failure occured.
Example:
# Remove bug id 54321 from case 1234
>>> TestCase.detach_bug(1234, 54321)
# Remove bug ids list [1234, 5678] from cases list [56789, 12345]
>>> TestCase.detach_bug([56789, 12345], [1234, 5678])
# Remove bug ids list '1234, 5678' from cases list '56789, 12345' with String
>>> TestCase.detach_bug('56789, 12345', '1234, 5678')
"""
case_ids = pre_process_ids(case_ids)
bug_ids = pre_process_ids(bug_ids)
tcs = TestCase.objects.filter(case_id__in=case_ids).iterator()
for tc in tcs:
for opk in bug_ids:
try:
tc.remove_bug(bug_id=opk)
except ObjectDoesNotExist:
pass
return
示例4: add_component
def add_component(request, plan_ids, component_ids):
"""
Description: Adds one or more components to the selected test plan.
Params: $plan_ids - Integer/Array/String: An integer representing the ID of the plan in the database.
$component_ids - Integer/Array/String - The component ID, an array of Component IDs
or a comma separated list of component IDs.
Returns: Array: empty on success or an array of hashes with failure
codes if a failure occured.
Example:
# Add component id 54321 to plan 1234
>>> TestPlan.add_component(1234, 54321)
# Add component ids list [1234, 5678] to plan list [56789, 12345]
>>> TestPlan.add_component([56789, 12345], [1234, 5678])
# Add component ids list '1234, 5678' to plan list '56789, 12345' with String
>>> TestPlan.add_component('56789, 12345', '1234, 5678')
"""
# FIXME: optimize this method to reduce possible huge number of SQLs
tps = TestPlan.objects.filter(
plan_id__in=pre_process_ids(value=plan_ids)
)
cs = Component.objects.filter(
id__in=pre_process_ids(value=component_ids)
)
for tp in tps.iterator():
for c in cs.iterator():
tp.add_component(c)
return
示例5: link_plan
def link_plan(request, case_ids, plan_ids):
""""
Description: Link test cases to the given plan.
Params: $case_ids - Integer/Array/String: An integer representing the ID in the database,
an array of case_ids, or a string of comma separated case_ids.
$plan_ids - Integer/Array/String: An integer representing the ID in the database,
an array of plan_ids, or a string of comma separated plan_ids.
Returns: Array: empty on success or an array of hashes with failure
codes if a failure occurs
Example:
# Add case 1234 to plan id 54321
>>> TestCase.link_plan(1234, 54321)
# Add case ids list [56789, 12345] to plan list [1234, 5678]
>>> TestCase.link_plan([56789, 12345], [1234, 5678])
# Add case ids list 56789 and 12345 to plan list 1234 and 5678 with String
>>> TestCase.link_plan('56789, 12345', '1234, 5678')
"""
from tcms.apps.testplans.models import TestPlan
case_ids = pre_process_ids(value=case_ids)
plan_ids = pre_process_ids(value=plan_ids)
tcs = TestCase.objects.filter(pk__in=case_ids)
tps = TestPlan.objects.filter(pk__in=plan_ids)
# Check the non-exist case ids.
if tcs.count() < len(case_ids):
raise ObjectDoesNotExist(
"TestCase", compare_list(case_ids,
tcs.values_list('pk',
flat=True).iterator())
)
# Check the non-exist plan ids.
if tps.count() < len(plan_ids):
raise ObjectDoesNotExist(
"TestPlan", compare_list(plan_ids,
tps.values_list('pk',
flat=True).iterator())
)
# Link the plans to cases
for tc in tcs.iterator():
for tp in tps.iterator():
tc.add_to_plan(tp)
return
示例6: test_pre_process_ids_with_others
def test_pre_process_ids_with_others(self):
try:
U.pre_process_ids((1,))
except TypeError as e:
self.assertEqual(str(e), 'Unrecognizable type of ids')
else:
self.fail("Missing validations.")
try:
U.pre_process_ids(dict(a=1))
except TypeError as e:
self.assertEqual(str(e), 'Unrecognizable type of ids')
else:
self.fail("Missing validations.")
示例7: calculate_average_estimated_time
def calculate_average_estimated_time(request, case_ids):
"""
Description: Returns an average estimated time for cases.
Params: $case_ids - Integer/String: An integer representing the ID in the database.
Returns: String: Time in "HH:MM:SS" format.
Example:
>>> TestCase.calculate_average_time([609, 610, 611])
"""
from datetime import timedelta
from tcms.core.utils.xmlrpc import SECONDS_PER_DAY
tcs = TestCase.objects.filter(
pk__in=pre_process_ids(case_ids)).only('estimated_time')
time = timedelta(0)
case_count = 0
for tc in tcs.iterator():
case_count += 1
time += tc.estimated_time
seconds = time.seconds + (time.days * SECONDS_PER_DAY)
# iterator will not populate cache so here will access db again
# seconds = seconds / len(tcs)
seconds = seconds / case_count
return '%02i:%02i:%02i' % (
seconds / 3600, # Hours
seconds / 60, # Minutes
seconds % 60 # Seconds
)
示例8: notification_remove_cc
def notification_remove_cc(request, case_ids, cc_list):
'''
Description: Remove email addresses from the notification CC list of specific TestCases
Params: $case_ids - Integer/Array: one or more TestCase IDs
$cc_list - Array: contians the email addresses that will
be removed from each TestCase indicated by case_ids.
Returns: JSON. When succeed, status is 0, and message maybe empty or
anything else that depends on the implementation. If something
wrong, status will be 1 and message will be a short description
to the error.
'''
try:
validate_cc_list(cc_list)
except (TypeError, ValidationError):
raise
try:
tc_ids = pre_process_ids(case_ids)
for tc in TestCase.objects.filter(pk__in=tc_ids).iterator():
tc.emailing.cc_list.filter(email__in=cc_list).delete()
except (TypeError, ValueError, Exception):
raise
示例9: get_bugs
def get_bugs(request, run_ids):
"""
*** FIXME: BUGGY IN SERIALISER - List can not be serialize. ***
Description: Get the list of bugs attached to this run.
Params: $run_ids - Integer/Array/String: An integer representing the ID in the database
an array of integers or a comma separated list of integers.
Returns: Array: An array of bug object hashes.
Example:
# Get bugs belong to ID 12345
>>> TestRun.get_bugs(12345)
# Get bug belong to run ids list [12456, 23456]
>>> TestRun.get_bugs([12456, 23456])
# Get bug belong to run ids list 12456 and 23456 with string
>>> TestRun.get_bugs('12456, 23456')
"""
from tcms.testcases.models import TestCaseBug
trs = TestRun.objects.filter(
run_id__in=pre_process_ids(value=run_ids)
)
tcrs = TestCaseRun.objects.filter(
run__run_id__in=trs.values_list('run_id', flat=True)
)
query = {'case_run__case_run_id__in': tcrs.values_list('case_run_id',
flat=True)}
return TestCaseBug.to_xmlrpc(query)
示例10: calculate_total_estimated_time
def calculate_total_estimated_time(request, case_ids):
"""
Description: Returns an total estimated time for cases.
Params: $case_ids - Integer/String: An integer representing the ID in the database.
Returns: String: Time in "HH:MM:SS" format.
Example:
>>> TestCase.calculate_total_time([609, 610, 611])
"""
from datetime import timedelta
from tcms.core.utils.xmlrpc import SECONDS_PER_DAY
tcs = TestCase.objects.filter(
pk__in=pre_process_ids(case_ids)).only('estimated_time')
time = timedelta(0)
for tc in tcs.iterator():
time += tc.estimated_time
seconds = time.seconds + (time.days * SECONDS_PER_DAY)
return '%02i:%02i:%02i' % (
seconds / 3600, # Hours
seconds / 60, # Minutes
seconds % 60 # Seconds
)
示例11: add_comment
def add_comment(request, case_ids, comment):
"""
Description: Adds comments to selected test cases.
Params: $case_ids - Integer/Array/String: An integer representing the ID in the database,
an array of case_ids, or a string of comma separated case_ids.
$comment - String - The comment
Returns: Array: empty on success or an array of hashes with failure
codes if a failure occured.
Example:
# Add comment 'foobar' to case 1234
>>> TestCase.add_comment(1234, 'foobar')
# Add 'foobar' to cases list [56789, 12345]
>>> TestCase.add_comment([56789, 12345], 'foobar')
# Add 'foobar' to cases list '56789, 12345' with String
>>> TestCase.add_comment('56789, 12345', 'foobar')
"""
from tcms.xmlrpc.utils import Comment
object_pks = pre_process_ids(value=case_ids)
c = Comment(
request=request,
content_type='testcases.testcase',
object_pks=object_pks,
comment=comment
)
return c.add()
示例12: add_tag
def add_tag(request, case_ids, tags):
"""
Description: Add one or more tags to the selected test cases.
Params: $case_ids - Integer/Array/String: An integer representing the ID in the database,
an array of case_ids, or a string of comma separated case_ids.
$tags - String/Array - A single tag, an array of tags,
or a comma separated list of tags.
Returns: Array: empty on success or an array of hashes with failure
codes if a failure occured.
Example:
# Add tag 'foobar' to case 1234
>>> TestCase.add_tag(1234, 'foobar')
# Add tag list ['foo', 'bar'] to cases list [12345, 67890]
>>> TestCase.add_tag([12345, 67890], ['foo', 'bar'])
# Add tag list ['foo', 'bar'] to cases list [12345, 67890] with String
>>> TestCase.add_tag('12345, 67890', 'foo, bar')
"""
tcs = TestCase.objects.filter(
case_id__in=pre_process_ids(value=case_ids))
tags = TestTag.string_to_list(tags)
for tag in tags:
t, c = TestTag.objects.get_or_create(name=tag)
for tc in tcs.iterator():
tc.add_tag(tag=t)
return
示例13: calculate_total_estimated_time
def calculate_total_estimated_time(request, case_ids):
"""
Description: Returns an total estimated time for cases.
Params: $case_ids - Integer/String: An integer representing the ID in the database.
Returns: String: Time in "HH:MM:SS" format.
Example:
>>> TestCase.calculate_total_time([609, 610, 611])
"""
from django.db.models import Sum
tcs = TestCase.objects.filter(
pk__in=pre_process_ids(case_ids)).only('estimated_time')
if not tcs.exists():
raise ValueError('Please input valid case Id')
# aggregate Sum return integer directly rather than timedelta
seconds = tcs.aggregate(Sum('estimated_time')).get('estimated_time__sum')
m, s = divmod(seconds, 60)
h, m = divmod(m, 60)
# TODO: return h:m:s or d:h:m
return '%02i:%02i:%02i' % (h, m, s)
示例14: notification_remove_cc
def notification_remove_cc(request, case_ids, cc_list):
'''
Description: Remove email addresses from the notification CC list of specific TestCases
Params: $case_ids - Integer/Array: one or more TestCase IDs
$cc_list - Array: contians the email addresses that will
be removed from each TestCase indicated by case_ids.
Returns: JSON. When succeed, status is 0, and message maybe empty or
anything else that depends on the implementation. If something
wrong, status will be 1 and message will be a short description
to the error.
'''
try:
validate_cc_list(cc_list)
except (TypeError, ValidationError):
raise
try:
tc_ids = pre_process_ids(case_ids)
cursor = connection.writer_cursor
ids_values = ",".join(itertools.repeat('%s', len(tc_ids)))
email_values = ",".join(itertools.repeat('%s', len(cc_list)))
sql = TC_REMOVE_CC % (ids_values, email_values)
tc_ids.extend(cc_list)
cursor.execute(sql, tc_ids)
transaction.commit_unless_managed()
except (TypeError, ValueError, Exception):
raise
示例15: notification_add_cc
def notification_add_cc(request, case_ids, cc_list):
'''
Description: Add email addresses to the notification CC list of specific TestCases
Params: $case_ids - Integer/Array: one or more TestCase IDs
$cc_list - Array: one or more Email addresses, which will be
added to each TestCase indicated by the case_ids.
Returns: JSON. When succeed, status is 0, and message maybe empty or
anything else that depends on the implementation. If something
wrong, status will be 1 and message will be a short description
to the error.
'''
try:
validate_cc_list(cc_list)
except (TypeError, ValidationError):
raise
try:
tc_ids = pre_process_ids(case_ids)
for tc in TestCase.objects.filter(pk__in=tc_ids).iterator():
# First, find those that do not exist yet.
existing_cc = tc.emailing.get_cc_list()
adding_cc = list(set(cc_list) - set(existing_cc))
tc.emailing.add_cc(adding_cc)
except (TypeError, ValueError, Exception):
raise