def filter_versions(request, query): """ Description: Performs a search and returns the resulting list of versions. Params: $query - Hash: keys must match valid search fields. +------------------------------------------------------------------+ | Component Search Parameters | +------------------------------------------------------------------+ | Key | Valid Values | | id | Integer: ID of product | | value | String | | product | ForeignKey: Product | +------------------------------------------------------------------+ Returns: Array: Matching versions are retuned in a list of hashes. Example: # Get all of versions named like '2.4.0-SNAPSHOT' >>> Product.filter_versions({'value__icontains': '2.4.0-SNAPSHOT'}) # Get all of filter_versions named in product 'Red Hat Enterprise Linux 5' >>> Product.filter_versions({'product__name': 'Red Hat Enterprise Linux 5'}) """ from tcms.apps.management.models import Version return Version.to_xmlrpc(query)
def get_versions(request, product): """ Description: Get the list of versions associated with this product. Params: $product - Integer/String Integer: product_id of the product in the Database String: Product name Returns: Array: Returns an array of Version objects. Example: # Get with product id >>> Product.get_runs(61) # Get with product name >>> Product.get_runs('Red Hat Enterprise Linux 5') """ from tcms.apps.management.models import Version p = pre_check_product(values = product) query = {'product': p} return Version.to_xmlrpc(query)
def get_versions(request, product): """ Description: Get the list of versions associated with this product. Params: $product - Integer/String Integer: product_id of the product in the Database String: Product name Returns: Array: Returns an array of Version objects. Example: # Get with product id >>> Product.get_runs(61) # Get with product name >>> Product.get_runs('Red Hat Enterprise Linux 5') """ from tcms.apps.management.models import Version p = pre_check_product(values=product) query = {'product': p} return Version.to_xmlrpc(query)
def clone(request, template_name='plan/clone.html'): """Clone testplan""" SUB_MODULE_NAME = 'plans' if not request.REQUEST.get('plan'): return HttpResponse(Prompt.render( request=request, info_type=Prompt.Info, info='At least one plan is required by clone function.', next='javascript:window.history.go(-1)', )) tps = TestPlan.objects.filter(pk__in=request.REQUEST.getlist('plan')) if not tps: return HttpResponse(Prompt.render( request=request, info_type=Prompt.Info, info='The plan you specific does not exist in database', next='javascript:window.history.go(-1)', )) # Clone the plan if the form is submitted if request.method == "POST": clone_form = ClonePlanForm(request.REQUEST) clone_form.populate(product_id=request.REQUEST.get('product_id')) if clone_form.is_valid(): # Create new test plan. for tp in tps: tp_dest = TestPlan.objects.create( product=clone_form.cleaned_data['product'], author=clone_form.cleaned_data['keep_orignal_author'] and tp.author or request.user, type=tp.type, default_product_version=clone_form.cleaned_data['default_product_version'], name = len(tps) == 1 and clone_form.cleaned_data['name'] or tp.name, create_date=tp.create_date, is_active=tp.is_active, extra_link=tp.extra_link, parent=clone_form.cleaned_data['set_parent'] and tp or None, ) # Copy the plan documents if clone_form.cleaned_data['copy_texts']: tptxts_src = tp.text.all() for tptxt_src in tptxts_src: tp_dest.add_text( plan_text_version=tptxt_src.plan_text_version, author=tptxt_src.author, create_date=tptxt_src.create_date, plan_text=tptxt_src.plan_text, ) else: tp_dest.add_text(author=request.user, plan_text='',) # Copy the plan tags for tp_tag_src in tp.tag.all(): tp_dest.add_tag(tag=tp_tag_src) # Copy the plan attachments if clone_form.cleaned_data['copy_attachements']: for tp_attach_src in tp.attachment.all(): tp_dest.add_attachment(attachment=tp_attach_src) # Copy the environment group if clone_form.cleaned_data['copy_environment_group']: for env_group in tp.env_group.all(): tp_dest.add_env_group(env_group=env_group) # Link the cases of the plan if clone_form.cleaned_data['link_testcases']: tpcases_src = tp.case.all() if clone_form.cleaned_data['copy_testcases']: for tpcase_src in tpcases_src: tcp = get_object_or_404(TestCasePlan, plan=tp, case=tpcase_src) if clone_form.cleaned_data['maintain_case_orignal_author']: author = tpcase_src.author else: author = request.user if clone_form.cleaned_data['keep_case_default_tester']: if hasattr(tpcase_src, 'default_tester'): default_tester = getattr(tpcase_src, 'default_tester') else: default_tester = None else: default_tester = request.user tc_category, b_created = TestCaseCategory.objects.get_or_create( name = tpcase_src.category.name, product = clone_form.cleaned_data['product'] ) tpcase_dest = TestCase.objects.create( create_date=tpcase_src.create_date, is_automated=tpcase_src.is_automated, script=tpcase_src.script, arguments=tpcase_src.arguments, summary=tpcase_src.summary, requirement=tpcase_src.requirement, alias=tpcase_src.alias, estimated_time=tpcase_src.estimated_time, case_status=TestCaseStatus.get_PROPOSED(), category=tc_category, priority=tpcase_src.priority, author=author, default_tester=default_tester, ) # Add case to plan. tp_dest.add_case(tpcase_dest, tcp.sortkey) for tc_tag_src in tpcase_src.tag.all(): tpcase_dest.add_tag(tag=tc_tag_src) for component in tpcase_src.component.filter(product__id=tp.product_id): try: new_c = tp_dest.product.component.get( name=component.name ) except ObjectDoesNotExist, error: new_c = tp_dest.product.component.create( name=component.name, initial_owner=request.user, description=component.description, ) tpcase_dest.add_component(new_c) text = tpcase_src.latest_text() if text: tpcase_dest.add_text( author=text.author, action=text.action, effect=text.effect, setup=text.setup, breakdown=text.breakdown, create_date=text.create_date, ) else: for tpcase_src in tpcases_src: tcp = get_object_or_404(TestCasePlan, plan=tp, case=tpcase_src) tp_dest.add_case(tpcase_src, tcp.sortkey) if len(tps) == 1: return HttpResponseRedirect( reverse('tcms.apps.testplans.views.get', args = [tp_dest.plan_id, ]) ) else: args = { 'action': 'search', 'product': clone_form.cleaned_data['product'].id, 'default_product_version': Version.string_to_id( product_id=clone_form.cleaned_data['product'].id, value=clone_form.cleaned_data['default_product_version'] ) } url_args = urllib.urlencode(args) return HttpResponseRedirect( reverse('tcms.apps.testplans.views.all') + '?' + url_args )