Skip to content

Commit

Permalink
Clone TC: always create new TC record when cloning. Refs #838
Browse files Browse the repository at this point in the history
otherwise it doesn't really make any sense, now that we can only
clone test cases into the same TP.
  • Loading branch information
atodorov committed Jul 24, 2019
1 parent 30886e6 commit dd7bd99
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 72 deletions.
6 changes: 0 additions & 6 deletions tcms/templates/case/clone.html
Expand Up @@ -35,12 +35,6 @@ <h2>{% trans "Clone TestCase(s) into" %} TP-{{ test_plan.pk }}: {{ test_plan.nam
<fieldset class="choose">
<legend class="">{% trans "Case Properties" %}</legend>
<ul class="ul-no-format">
<li>
{{ clone_form.copy_case }}
<span>
<label for="id_copy_case">{{ clone_form.copy_case.help_text }}</label>
</span>
</li>
<li>
{{ clone_form.maintain_case_orignal_author }}
<span>
Expand Down
6 changes: 0 additions & 6 deletions tcms/testcases/forms.py
Expand Up @@ -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 '
Expand Down
101 changes: 41 additions & 60 deletions tcms/testcases/views.py
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit dd7bd99

Please sign in to comment.