From dd7bd9965086a8fe833548801747a1bca0be19d3 Mon Sep 17 00:00:00 2001 From: "Mr. Senko" Date: Wed, 24 Jul 2019 12:33:55 +0300 Subject: [PATCH] Clone TC: always create new TC record when cloning. Refs #838 otherwise it doesn't really make any sense, now that we can only clone test cases into the same TP. --- tcms/templates/case/clone.html | 6 -- tcms/testcases/forms.py | 6 -- tcms/testcases/views.py | 101 +++++++++++++-------------------- 3 files changed, 41 insertions(+), 72 deletions(-) diff --git a/tcms/templates/case/clone.html b/tcms/templates/case/clone.html index 43f45fb89a..8a3c3a6c34 100644 --- a/tcms/templates/case/clone.html +++ b/tcms/templates/case/clone.html @@ -35,12 +35,6 @@

{% trans "Clone TestCase(s) into" %} TP-{{ test_plan.pk }}: {{ test_plan.nam
{% trans "Case Properties" %}
    -
  • - {{ clone_form.copy_case }} - - - -
  • {{ clone_form.maintain_case_orignal_author }} diff --git a/tcms/testcases/forms.py b/tcms/testcases/forms.py index 6d3ebfb63c..0d1ff76f6b 100644 --- a/tcms/testcases/forms.py +++ b/tcms/testcases/forms.py @@ -281,12 +281,6 @@ class CloneCaseForm(forms.Form): queryset=TestPlan.objects.all(), widget=forms.CheckboxSelectMultiple() ) - copy_case = forms.BooleanField( - label='Create a copy', - help_text='Create a copy (Unchecking will create a link to selected ' - 'case)', - required=False - ) maintain_case_orignal_author = forms.BooleanField( label='Keep original author', help_text='Keep original author (Unchecking will make me as author ' diff --git a/tcms/testcases/views.py b/tcms/testcases/views.py index 9e2a4e1536..a08396a7fe 100644 --- a/tcms/testcases/views.py +++ b/tcms/testcases/views.py @@ -777,70 +777,52 @@ def clone(request, template_name='case/clone.html'): if clone_form.is_valid(): tcs_src = clone_form.cleaned_data['case'] for tc_src in tcs_src: - if clone_form.cleaned_data['copy_case']: - tc_dest = TestCase.objects.create( - is_automated=tc_src.is_automated, - script=tc_src.script, - arguments=tc_src.arguments, - extra_link=tc_src.extra_link, - summary=tc_src.summary, - requirement=tc_src.requirement, - case_status=TestCaseStatus.get_proposed(), - category=tc_src.category, - priority=tc_src.priority, - notes=tc_src.notes, - text=tc_src.text, - author=clone_form.cleaned_data[ - 'maintain_case_orignal_author'] and - tc_src.author or request.user, - default_tester=clone_form.cleaned_data[ - 'maintain_case_orignal_default_tester'] and - tc_src.author or request.user, - ) - - for test_plan in clone_form.cleaned_data['plan']: - sortkey = test_plan.get_case_sortkey() - test_plan.add_case(tc_dest, sortkey) - - for tag in tc_src.tag.all(): - tc_dest.add_tag(tag=tag) - else: - tc_dest = tc_src - tc_dest.author = request.user - if clone_form.cleaned_data['maintain_case_orignal_author']: - tc_dest.author = tc_src.author - - tc_dest.default_tester = request.user - if clone_form.cleaned_data['maintain_case_orignal_default_tester']: - tc_dest.default_tester = tc_src.default_tester - - tc_dest.save() + tc_dest = TestCase.objects.create( + is_automated=tc_src.is_automated, + script=tc_src.script, + arguments=tc_src.arguments, + extra_link=tc_src.extra_link, + summary=tc_src.summary, + requirement=tc_src.requirement, + case_status=TestCaseStatus.get_proposed(), + category=tc_src.category, + priority=tc_src.priority, + notes=tc_src.notes, + text=tc_src.text, + author=clone_form.cleaned_data[ + 'maintain_case_orignal_author'] and + tc_src.author or request.user, + default_tester=clone_form.cleaned_data[ + 'maintain_case_orignal_default_tester'] and + tc_src.author or request.user, + ) - for test_plan in clone_form.cleaned_data['plan']: - sortkey = test_plan.get_case_sortkey() - test_plan.add_case(tc_dest, sortkey) + # apply tags as well + for tag in tc_src.tag.all(): + tc_dest.add_tag(tag=tag) - # Add the cases to plan for test_plan in clone_form.cleaned_data['plan']: - # Clone the categories to new product - if clone_form.cleaned_data['copy_case']: - try: - tc_category = test_plan.product.category.get( - name=tc_src.category.name - ) - except ObjectDoesNotExist: - tc_category = test_plan.product.category.create( - name=tc_src.category.name, - description=tc_src.category.description, - ) - - tc_dest.category = tc_category - tc_dest.save() - del tc_category + # add new TC to selected TP + sortkey = test_plan.get_case_sortkey() + test_plan.add_case(tc_dest, sortkey) + + # clone TC category b/c we may be cloning a 'linked' + # TC which has a different Product that doesn't have the + # same categories yet + try: + tc_category = test_plan.product.category.get( + name=tc_src.category.name + ) + except ObjectDoesNotExist: + tc_category = test_plan.product.category.create( + name=tc_src.category.name, + description=tc_src.category.description, + ) + tc_dest.category = tc_category + tc_dest.save() # Clone the components to new product - if clone_form.cleaned_data['copy_component'] and \ - clone_form.cleaned_data['copy_case']: + if clone_form.cleaned_data['copy_component']: for component in tc_src.component.all(): try: new_c = test_plan.product.component.get( @@ -885,7 +867,6 @@ def clone(request, template_name='case/clone.html'): # Initial the clone case form clone_form = CloneCaseForm(initial={ 'case': selected_cases, - 'copy_case': False, 'maintain_case_orignal_author': False, 'maintain_case_orignal_default_tester': False, 'copy_component': True,