def add_version(request, values): """ Description: Add version to specified product. Params: $product - Integer/String Integer: product_id of the product in the Database String: Product name $value - String The name of the version string. Returns: Array: Returns the newly added version object, error info if failed. Example: # Add version for specified product: >>> Product.add_version({'value': 'devel', 'product': 272}) {'product': 'QE Test Product', 'id': '1106', 'value': 'devel', 'product_id': 272} # Run it again: >>> Product.add_version({'value': 'devel', 'product': 272}) [['__all__', 'Version with this Product and Value already exists.']] """ from nitrate.apps.management.forms import VersionForm from nitrate.core import forms form = VersionForm(values) if form.is_valid(): version = form.save() return version.serialize() else: return forms.errors_to_list(form)
def create(request, values): """ Description: Creates a new Test Plan 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 plan to be created. +-------------------------+----------------+-----------+------------------------------------+ | Field | Type | Null | Description | +-------------------------+----------------+-----------+------------------------------------+ | product | Integer | Required | ID of product | | name | String | Required | | | type | Integer | Required | ID of plan type | | default_product_version | Integer | Required | | | text | String | Required | Plan documents, HTML acceptable. | | parent | Integer | Optional | Parent plan ID | | is_active | Boolean | Optional | 0: Archived 1: Active (Default 0) | +-------------------------+----------------+-----------+------------------------------------+ Returns: The newly created object hash. Example: # Minimal test case parameters >>> values = { 'product': 61, 'name': 'Testplan foobar', 'type': 1, 'parent_id': 150, 'default_product_version': 93, 'text':'Testing TCMS', } >>> TestPlan.create(values) """ from nitrate.core import forms from nitrate.apps.testplans.forms import XMLRPCNewPlanForm if not values.get('product'): raise ValueError('Value of product is required') form = XMLRPCNewPlanForm(values) form.populate(product_id = values['product']) if form.is_valid(): tp = TestPlan.objects.create( product = form.cleaned_data['product'], name = form.cleaned_data['name'], type = form.cleaned_data['type'], author = request.user, default_product_version = form.cleaned_data['default_product_version'], parent = form.cleaned_data['parent'], is_active = form.cleaned_data['is_active'] ) tp.add_text( author = request.user, plan_text = values['text'], ) return tp.serialize() else: return forms.errors_to_list(form)
def create(request, values): """ *** It always report - ValueError: invalid literal for int() with base 10: '' *** Description: Creates a new Test Case 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 case to be created. +--------------------+----------------+-----------+------------------------------------------------+ | Field | Type | Null | Description | +--------------------+----------------+-----------+------------------------------------------------+ | run | Integer | Required | ID of Test Run | | case | Integer | Required | ID of test case | | build | Integer | Required | ID of a Build in plan's product | | assignee | Integer | Optional | ID of assignee | | case_run_status | Integer | Optional | Defaults to "IDLE" | | case_text_version | Integer | Optional | Default to latest case text version | | notes | String | Optional | | | sortkey | Integer | Optional | a.k.a. Index, Default to 0 | +--------------------+----------------+-----------+------------------------------------------------+ Returns: The newly created object hash. Example: # Minimal test case parameters >>> values = { 'run': 1990, 'case': 12345, 'build': 123, } >>> TestCaseRun.create(values) """ from nitrate.core import forms from nitrate.apps.testcases.models import TestCase from nitrate.apps.testruns.models import TestRun from nitrate.apps.testruns.forms import XMLRPCNewCaseRunForm form = XMLRPCNewCaseRunForm(values) if form.is_valid(): tr = form.cleaned_data['run'] tcr = tr.add_case_run( case = form.cleaned_data['case'], build = form.cleaned_data['build'], assignee = form.cleaned_data['assignee'], case_run_status = form.cleaned_data['case_run_status'], case_text_version = form.cleaned_data['case_text_version'], notes = form.cleaned_data['notes'], sortkey = form.cleaned_data['sortkey'] ) else: return forms.errors_to_list(form) return tcr.serialize()
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 nitrate.core import forms from nitrate.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 nitrate.core import forms from nitrate.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)
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 nitrate.core import forms from nitrate.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)
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, 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 nitrate.core import forms from nitrate.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 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 nitrate.core import forms from nitrate.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()