def env_value(request, action, run_ids, env_value_ids): """ Description: add/remove env values to the given runs, function is same as link_env_value/unlink_env_value Params: $action - String: 'add' or 'remove'. $run_ids - Integer/Array/String: An integer representing the ID in the database, an array of run_ids, or a string of comma separated run_ids. $env_value_ids - Integer/Array/String: An integer representing the ID in the database, an array of env_value_ids, or a string of comma separated env_value_ids. Returns: Array: empty on success or an array of hashes with failure codes if a failure occured. Example: # Add env value 13 to run id 8748 >>> TestRun.env_value('add', 8748, 13) """ from tcms.apps.management.models import TCMSEnvValue trs = TestRun.objects.filter(pk__in = pre_process_ids(value = run_ids)) evs = TCMSEnvValue.objects.filter( pk__in = pre_process_ids(value = env_value_ids) ) for tr in trs: for ev in evs: try: func = getattr(tr, action + '_env_value') func(env_value = ev) except: pass return
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) for tc in tcs: for opk in bug_ids: try: tc.remove_bug(bug_id = opk) except ObjectDoesNotExist, error: pass
def remove_component(request, case_ids, component_ids): """ Description: Removes selected component from the selected test case. 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. $component_ids - Integer: - The component ID to be removed. Returns: Array: Empty on success. Example: # Remove component id 54321 from case 1234 >>> TestCase.remove_component(1234, 54321) # Remove component ids list [1234, 5678] from cases list [56789, 12345] >>> TestCase.remove_component([56789, 12345], [1234, 5678]) # Remove component ids list '1234, 5678' from cases list '56789, 12345' with String >>> TestCase.remove_component('56789, 12345', '1234, 5678') """ from tcms.apps.management.models import Component tcs = TestCase.objects.filter( case_id__in = pre_process_ids(value = case_ids) ) tccs = Component.objects.filter( id__in = pre_process_ids(value = component_ids) ) for tc in tcs: for tcc in tccs: try: tc.remove_component(component = tcc) except: pass return
def add_cases(request, run_ids, case_ids): """ Description: Add one or more cases to the selected test runs. Params: $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. $run_ids - Integer/Array/String: An integer representing the ID in the database an array of IDs, or a comma separated list of 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: for tc in tcs: tr.add_case_run(case = tc) return
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: tc.add_tag(tag = t) return
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)) time = timedelta(0) for tc in tcs: 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 )
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 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()
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.apps.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)
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 len(tcs) < len(case_ids): raise ObjectDoesNotExist( "TestCase",compare_list(case_ids, tcs.values_list('pk', flat=True)) ) # Check the non-exist plan ids. if len(tps) < len(plan_ids): raise ObjectDoesNotExist( "TestPlan",compare_list(plan_ids, tps.values_list('pk', flat=True)) ) # Link the plans to cases for tc in tcs: for tp in tps: tc.add_to_plan(tp) return
def remove_cases(request, run_ids, case_ids): """ Description: Remove one or more cases from 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 Exception: When any exception is thrown on the server side, it will be returned as JSON, which contains two items: - status: 1. - message: str, any message specific to the error on the server Example: # Remove case 54321 from run 1234 >>> TestRun.remove_cases(1234, 54321) # Remove case ids list [1234, 5678] from run list [56789, 12345] >>> TestRun.remove_cases([56789, 12345], [1234, 5678]) # Remove case ids list '1234, 5678' from run list '56789, 12345' with String >>> TestRun.remove_cases('56789, 12345', '1234, 5678') """ try: trs = TestRun.objects.filter(run_id__in=pre_process_ids(run_ids)) for tr in trs: crs = TestCaseRun.objects.filter(run=tr, case__in=pre_process_ids(case_ids)) crs.delete() except Exception, err: message = '%s: %s' % (err.__class__.__name__, err.message) return { 'status': 1, 'message': message }
def add_to_run(request, case_ids, run_ids): """ Description: Add one or more cases to the selected test runs. 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. $run_ids - Integer/Array/String: An integer representing the ID in the database an array of IDs, or a comma separated list of IDs. Returns: Array: empty on success or an array of hashes with failure codes if a failure occured. Example: # Add case 1234 to run id 54321 >>> TestCase.add_to_run(1234, 54321) # Add case ids list [56789, 12345] to run list [1234, 5678] >>> TestCase.add_to_run([56789, 12345], [1234, 5678]) # Add case ids list 56789 and 12345 to run list 1234 and 5678 with String >>> TestCase.add_to_run('56789, 12345', '1234, 5678') """ from tcms.apps.testruns.models import TestRun case_ids = pre_process_ids(case_ids) run_ids = pre_process_ids(run_ids) trs = TestRun.objects.filter(run_id__in = run_ids) if not trs: raise ValueError, 'Invalid run_ids' tcs = TestCase.objects.filter(case_id__in = case_ids) if not tcs: raise ValueError, 'Invalid case_ids' for tr in trs: for tc in tcs: tr.add_case_run(case = tc) return
def add_component(request, case_ids, component_ids): """ Description: Adds one or more components 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. $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 case 1234 >>> TestCase.add_component(1234, 54321) # Add component ids list [1234, 5678] to cases list [56789, 12345] >>> TestCase.add_component([56789, 12345], [1234, 5678]) # Add component ids list '1234, 5678' to cases list '56789, 12345' with String >>> TestCase.add_component('56789, 12345', '1234, 5678') """ from tcms.apps.management.models import Component tcs = TestCase.objects.filter( case_id__in = pre_process_ids(value = case_ids) ) cs = Component.objects.filter( id__in = pre_process_ids(value = component_ids) ) try: for tc in tcs: for c in cs: tc.add_component(component = c) except: pass return
def notification_get_cc_list(request, case_ids): ''' Description: Return whole CC list of each TestCase Params: $case_ids - Integer/Array: one or more TestCase IDs Returns: An dictionary object with case_id as key and a list of CC as the value Each case_id will be converted to a str object in the result. ''' result = {} try: tc_ids = pre_process_ids(case_ids) for tc in TestCase.objects.filter(pk__in=tc_ids): cc_list = tc.emailing.get_cc_list() result[str(tc.pk)] = cc_list except (TypeError, ValueError, Exception), err: return { 'status': 1, 'message': '%s: %s' % (err.__class__.__name__, str(err))}
def remove_tag(request, plan_ids, tags): """ Description: Remove a tag from a plan. Params: $plan_ids - Integer/Array/String: An integer or alias representing the ID in the database, an array of plan_ids, or a string of comma separated plan_ids. $tag - String - A single tag to be removed. Returns: Array: Empty on success. Example: # Remove tag 'foo' from plan 1234 >>> TestPlan.remove_tag(1234, 'foo') # Remove tag 'foo' and 'bar' from plan list [56789, 12345] >>> TestPlan.remove_tag([56789, 12345], ['foo', 'bar']) # Remove tag 'foo' and 'bar' from plan list '56789, 12345' with String >>> TestPlan.remove_tag('56789, 12345', 'foo, bar') """ from tcms.apps.management.models import TestTag tps = TestPlan.objects.filter( plan_id__in = pre_process_ids(value = plan_ids) ) tgs = TestTag.objects.filter( name__in = TestTag.string_to_list(tags) ) for tp in tps: for tg in tgs: try: tp.remove_tag(tag = tg) except ObjectDoesNotExist: pass except: raise return
def remove_tag(request, case_ids, tags): """ Description: Remove a tag from a case. Params: $case_ids - Integer/Array/String: An integer or alias representing the ID in the database, an array of case_ids, or a string of comma separated case_ids. $tags - String/Array - A single or multiple tag to be removed. Returns: Array: Empty on success. Example: # Remove tag 'foo' from case 1234 >>> TestCase.remove_tag(1234, 'foo') # Remove tag 'foo' and bar from cases list [56789, 12345] >>> TestCase.remove_tag([56789, 12345], ['foo', 'bar']) # Remove tag 'foo' and 'bar' from cases list '56789, 12345' with String >>> TestCase.remove_tag('56789, 12345', 'foo, bar') """ tcs = TestCase.objects.filter( case_id__in = pre_process_ids(value = case_ids) ) tgs = TestTag.objects.filter( name__in = TestTag.string_to_list(tags) ) for tc in tcs: for tg in tgs: try: tc.remove_tag(tg) except ObjectDoesNotExist: pass except: raise return
def get_bugs(request, case_ids): """ Description: Get the list of bugs that are associated with this test case. Params: $case_ids - Integer/String: An integer representing the ID in the database Returns: Array: An array of bug object hashes. Example: # Get bugs belong to ID 12345 >>> TestCase.get_bugs(12345) # Get bug belong to case ids list [12456, 23456] >>> TestCase.get_bugs([12456, 23456]) # Get bug belong to case ids list 12456 and 23456 with string >>> TestCase.get_bugs('12456, 23456') """ from tcms.apps.testcases.models import TestCaseBug tcs = TestCase.objects.filter( case_id__in = pre_process_ids(value = case_ids) ) query = {'case__case_id__in': tcs.values_list('case_id', flat=True)} return TestCaseBug.to_xmlrpc(query)
def create(request, values): """ Description: Creates a new Test Run object and stores it in the database. Params: $values - Hash: A reference to a hash with keys and values matching the fields of the test run to be created. +-------------------+----------------+-----------+------------------------------------+ | Field | Type | Null | Description | +-------------------+----------------+-----------+------------------------------------+ | plan | Integer | Required | ID of test plan | | build | Integer/String | Required | ID of Build | | errata_id | Integer | Optional | ID of Errata | | manager | Integer | Required | ID of run manager | | summary | String | Required | | | product | Integer | Required | ID of product | | product_version | Integer | Required | ID of product version | | default_tester | Integer | Optional | ID of run default tester | | plan_text_version | Integer | Optional | | | estimated_time | TimeDelta | Optional | HH:MM:MM | | notes | String | Optional | | | status | Integer | Optional | 0:RUNNING 1:STOPPED (default 0) | | case | Array/String | Optional | list of case ids to add to the run | | tag | Array/String | Optional | list of tag to add to the run | +-------------------+----------------+-----------+------------------------------------+ Returns: The newly created object hash. Example: >>> values = {'build': 384, 'manager': 137, 'plan': 137, 'errata_id': 124, 'product': 61, 'product_version': 93, 'summary': 'Testing XML-RPC for TCMS', } >>> TestRun.create(values) """ from datetime import datetime from tcms.core import forms from tcms.apps.testruns.forms import XMLRPCNewRunForm if not values.get('product'): raise ValueError('Value of product is required') if values.get('case'): values['case'] = pre_process_ids(value = values['case']) form = XMLRPCNewRunForm(values) form.populate(product_id = values['product']) if form.is_valid(): tr = TestRun.objects.create( product_version = form.cleaned_data['product_version'], plan_text_version = form.cleaned_data['plan_text_version'], stop_date = form.cleaned_data['status'] and datetime.now() or None, summary = form.cleaned_data['summary'], notes = form.cleaned_data['notes'], estimated_time = form.cleaned_data['estimated_time'], plan = form.cleaned_data['plan'], build = form.cleaned_data['build'], errata_id = form.cleaned_data['errata_id'], manager = form.cleaned_data['manager'], default_tester = form.cleaned_data['default_tester'], ) if form.cleaned_data['case']: for c in form.cleaned_data['case']: tr.add_case_run(case = c) del c if form.cleaned_data['tag']: tags = form.cleaned_data['tag'] if isinstance(tags, str): tags = [c.strip() for c in tags.split(',') if c] for tag in tags: t, c = TestTag.objects.get_or_create(name = tag) tr.add_tag(tag = t) del tag, t, c else: return forms.errors_to_list(form) return tr.serialize()
def update(request, run_ids, values): """ Description: Updates the fields of the selected test run. Params: $run_ids - Integer/Array/String: An integer or alias representing the ID in the database, an array of run_ids, or a string of comma separated run_ids. $values - Hash of keys matching TestRun fields and the new values to set each field to. See params of TestRun.create for description +-------------------+----------------+--------------------------+ | Field | Type | Description | +-------------------+----------------+--------------------------+ | plan | Integer | TestPlan.plan_id | | product | Integer | Product.id | | build | Integer | Build.id | | errata_id | Integer | Errata.id | | manager | Integer | Auth.User.id | | default_tester | Intege | Auth.User.id | | summary | String | | | estimated_time | TimeDelta | MM/DD/YYYY | | product_version | Integer | | | plan_text_version | Integer | | | notes | String | | | status | Integer | 0:RUNNING 1:FINISHED | +-------------------+----------------+ -------------------------+ Returns: Hash: The updated test run object. Example: # Update status to finished for run 1193 and 1194 >>> TestRun.update([1193, 1194], {'status': 1}) """ from datetime import datetime from tcms.core import forms from tcms.apps.testruns.forms import XMLRPCUpdateRunForm if (values.get('product_version') and not values.get('product')): raise ValueError('Field "product" is required by product_version') form = XMLRPCUpdateRunForm(values) if values.get('product_version'): form.populate(product_id = values['product']) if form.is_valid(): trs = TestRun.objects.filter(pk__in = pre_process_ids(value = run_ids)) if form.cleaned_data['plan']: trs.update(plan = form.cleaned_data['plan']) if form.cleaned_data['build']: trs.update(build = form.cleaned_data['build']) if form.cleaned_data['errata_id']: trs.update(errata_id = form.cleaned_data['errata_id']) if form.cleaned_data['manager']: trs.update(manager = form.cleaned_data['manager']) if values.has_key('default_tester'): if values.get('default_tester') and form.cleaned_data['default_tester']: trs.update(default_tester = form.cleaned_data['default_tester']) else: trs.update(default_tester = None) if form.cleaned_data['summary']: trs.update(summary = form.cleaned_data['summary']) if form.cleaned_data['estimated_time']: trs.update(estimated_time = form.cleaned_data['estimated_time']) if form.cleaned_data['product_version']: trs.update(product_version = form.cleaned_data['product_version']) if values.has_key('notes'): if values['notes'] in (None, ''): trs.update(notes = values['notes']) if form.cleaned_data['notes']: trs.update(notes = form.cleaned_data['notes']) if form.cleaned_data['plan_text_version']: trs.update(plan_text_version = form.cleaned_data['plan_text_version']) if isinstance(form.cleaned_data['status'], int): if form.cleaned_data['status']: trs.update(stop_date = datetime.now()) else: trs.update(stop_date = None) else: return forms.errors_to_list(form) query = {'pk__in': trs.values_list('pk', flat=True)} return TestRun.to_xmlrpc(query)
def update(request, case_run_ids, values): """ Description: Updates the fields of the selected case-runs. Params: $caserun_ids - Integer/String/Array Integer: A single TestCaseRun ID. String: A comma separates string of TestCaseRun IDs for batch processing. Array: An array of TestCaseRun IDs for batch mode processing $values - Hash of keys matching TestCaseRun fields and the new values to set each field to. +--------------------+----------------+ | Field | Type | +--------------------+----------------+ | build | Integer | | assignee | Integer | | case_run_status | Integer | | notes | String | | sortkey | Integer | +--------------------+----------------+ Returns: Hash/Array: In the case of a single object, it is returned. If a list was passed, it returns an array of object hashes. If the update on any particular object failed, the hash will contain a ERROR key and the message as to why it failed. Example: # Update alias to 'tcms' for case 12345 and 23456 >>> TestCaseRun.update([12345, 23456], {'assignee': 2206}) """ from datetime import datetime from nitrate.core import forms from nitrate.apps.testruns.forms import XMLRPCUpdateCaseRunForm tcrs = TestCaseRun.objects.filter( pk__in = pre_process_ids(case_run_ids) ) form = XMLRPCUpdateCaseRunForm(values) if form.is_valid(): if form.cleaned_data['build']: tcrs.update(build = form.cleaned_data['build']) if form.cleaned_data['assignee']: tcrs.update(assignee = form.cleaned_data['assignee']) if form.cleaned_data['case_run_status']: tcrs.update(case_run_status = form.cleaned_data['case_run_status']) tcrs.update(tested_by = request.user) tcrs.update(close_date = datetime.now()) if values.has_key('notes'): if values['notes'] in (None, ''): tcrs.update(notes = values['notes']) if form.cleaned_data['notes']: tcrs.update(notes = form.cleaned_data['notes']) if form.cleaned_data['sortkey']: tcrs.update(sortkey = form.cleaned_data['sortkey']) else: return forms.errors_to_list(form) query = {'pk__in': tcrs.values_list('pk', flat = True)} return TestCaseRun.to_xmlrpc(query)
def update(request, plan_ids, values): """ Description: Updates the fields of the selected test plan. Params: $plan_ids - Integer: A single TestPlan ID. $values - Hash of keys matching TestPlan fields and the new values to set each field to. +------------------------+----------------+------------------------------------+ | Field | Type | Description | +-------------------------+----------------+------------------------------------+ | product | Integer | ID of product | | name | String | | | type | Integer | ID of plan type | | default_product_version | Integer | | | parent | Integer | Parent plan ID | | is_active | Boolean | True/False | | env_group | Integer | | +-------------------------+----------------+------------------------------------+ Returns: Hash: The updated test plan object. Example: # Update product to 61 for plan 207 and 208 >>> TestPlan.update([207, 208], {'product': 61}) """ from tcms.core import forms from tcms.apps.testplans.forms import XMLRPCEditPlanForm if values.get('is_active') in (False, True): if values.get('is_active') == False: values['is_active'] = 0 else: values['is_active'] = 1 form = XMLRPCEditPlanForm(values) if values.get('default_product_version') and not values.get('product'): raise ValueError('Product value is required by default product version') if values.get('default_product_version') and values.get('product'): form.populate(product_id = values['product']) tps = TestPlan.objects.filter(pk__in = pre_process_ids(value = plan_ids)) if form.is_valid(): if form.cleaned_data['name']: tps.update(name = form.cleaned_data['name']) if form.cleaned_data['type']: tps.update(type = form.cleaned_data['type']) if form.cleaned_data['product']: tps.update(product = form.cleaned_data['product']) if form.cleaned_data['default_product_version']: tps.update(default_product_version = form.cleaned_data['default_product_version']) if form.cleaned_data['parent']: tps.update(parent = form.cleaned_data['parent']) if isinstance(form.cleaned_data['is_active'], int): tps.update(is_active = form.cleaned_data['is_active']) if form.cleaned_data['env_group']: for tp in tps: tp.clear_env_groups() tp.add_env_group(form.cleaned_data['env_group']) else: return forms.errors_to_list(form) query = {'pk__in': tps.values_list('pk', flat = True)} return TestPlan.to_xmlrpc(query)
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), err: return { 'status': 1, 'message': '%s: %s' % (err.__class__.__name__, str(err)) } try: tc_ids = pre_process_ids(case_ids) for tc in TestCase.objects.filter(pk__in=tc_ids): # 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), err: return { 'status': 1, 'message': '%s: %s' % (err.__class__.__name__, str(err))} return { 'status': 0, 'message': 'Succeed' } @log_call
def create(request, values): """ Description: Creates a new Test Case object and stores it in the database. Params: $values - Array/Hash: A reference to a hash or array of hashes with keys and values matching the fields of the test case to be created. +----------------------------+----------------+-----------+-----------------------------+ | Field | Type | Null | Description | +----------------------------+----------------+-----------+-----------------------------+ | product | Integer | Required | ID of Product | | category | Integer | Required | ID of Category | | priority | Integer | Required | ID of Priority | | summary | String | Required | | | case_status | Integer | Optional | ID of case status | | plan | Array/Str/Int | Optional | ID or List of plan_ids | | component | Integer/String | Optional | ID of Priority | | default_tester | String | Optional | Login of tester | | estimated_time | String | Optional | HH:MM:SS Format | | is_automated | Integer | Optional | 0: Manual, 1: Auto, 2: Both | | is_automated_proposed | Boolean | Optional | Default 0 | | script | String | Optional | | | arguments | String | Optional | | | requirement | String | Optional | | | alias | String | Optional | Must be unique | | action | String | Optional | | | effect | String | Optional | Expected Result | | setup | String | Optional | | | breakdown | String | Optional | | | tag | Array/String | Optional | String Comma separated | | bug | Array/String | Optional | String Comma separated | | extra_link | String | Optional | reference link | +----------------------------+----------------+-----------+-----------------------------+ Returns: Array/Hash: The newly created object hash if a single case was created, or an array of objects if more than one was created. If any single case threw an error during creation, a hash with an ERROR key will be set in its place. Example: # Minimal test case parameters >>> values = { 'category': 135, 'product': 61, 'summary': 'Testing XML-RPC', 'priority': 1, } >>> TestCase.create(values) """ from tcms.core import forms from tcms.apps.testcases.forms import XMLRPCNewCaseForm if not (values.get('category') or values.get('summary')): raise ValueError() values['component'] = pre_process_ids(values.get('component', [])) values['plan'] = pre_process_ids(values.get('plan', [])) values['bug'] = pre_process_ids(values.get('bug', [])) form = XMLRPCNewCaseForm(values) form.populate(values.get('product')) if form.is_valid(): # Create the case tc = TestCase.create(author = request.user, values = form.cleaned_data) # Add case text to the case tc.add_text( action = form.cleaned_data['action'] or '', effect = form.cleaned_data['effect'] or '', setup = form.cleaned_data['setup'] or '', breakdown = form.cleaned_data['breakdown'] or '', ) # Add the case to specific plans for p in form.cleaned_data['plan']: tc.add_to_plan(plan = p) del p # Add components to the case for c in form.cleaned_data['component']: tc.add_component(component = c) del c # Add tag to the case for tag in TestTag.string_to_list(values.get('tag', [])): t, c = TestTag.objects.get_or_create(name = tag) tc.add_tag(tag = t) else: # Print the errors if the form is not passed validation. return forms.errors_to_list(form) return get(request, tc.case_id)
def update(request, case_ids, values): """ Description: Updates the fields of the selected case or cases. Params: $case_ids - Integer/String/Array Integer: A single TestCase ID. String: A comma separates string of TestCase IDs for batch processing. Array: An array of case IDs for batch mode processing $values - Hash of keys matching TestCase fields and the new values to set each field to. Returns: Array: an array of case hashes. If the update on any particular case failed, the has will contain a ERROR key and the message as to why it failed. +-----------------------+----------------+-----------------------------------------+ | Field | Type | Null | +-----------------------+----------------+-----------------------------------------+ | case_status | Integer | Optional | | product | Integer | Optional(Required if changes category) | | category | Integer | Optional | | priority | Integer | Optional | | default_tester | String/Integer | Optional(str - user_name, int - user_id)| | estimated_time | String | Optional | | is_automated | Integer | Optional(0 - Manual, 1 - Auto, 2 - Both)| | is_automated_proposed | Boolean | Optional | | script | String | Optional | | arguments | String | Optional | | summary | String | Optional | | requirement | String | Optional | | alias | String | Optional | | notes | String | Optional | | extra_link | String | Optional(reference link) +-----------------------+----------------+-----------------------------------------+ Example: # Update alias to 'tcms' for case 12345 and 23456 >>> TestCase.update([12345, 23456], {'alias': 'tcms'}) """ from tcms.core import forms from tcms.apps.testcases.forms import XMLRPCUpdateCaseForm form = XMLRPCUpdateCaseForm(values) if values.get('category') and not values.get('product'): raise ValueError('Product ID is required for category') if values.get('product'): form.populate(product_id = values['product']) if form.is_valid(): tcs = TestCase.update( case_ids = pre_process_ids(value = case_ids), values = form.cleaned_data, ) else: return forms.errors_to_list(form) query = {'pk__in': tcs.values_list('pk', flat = True)} return TestCase.to_xmlrpc(query)