Skip to content

Commit

Permalink
Clone TP: always set TC.author to the new user when copying cases
Browse files Browse the repository at this point in the history
- when linking test cases to a newly created TP their original
  fields are not changed b/c we only add another m2m relationship
- when copying the test cases, that is creating new TC objects,
  with new PKs, then we set their author to the current user
  • Loading branch information
atodorov committed Jul 24, 2019
1 parent dd31b0d commit 8452b57
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 26 deletions.
2 changes: 0 additions & 2 deletions tcms/static/js/testplan_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -650,10 +650,8 @@ Nitrate.TestPlans.Clone.on_load = function() {

jQ('#id_copy_testcases').bind('change', function(e) {
if (this.checked) {
jQ('#id_maintain_case_orignal_author')[0].disabled = false;
jQ('#id_keep_case_default_tester')[0].disabled = false;
} else {
jQ('#id_maintain_case_orignal_author')[0].disabled = true;
jQ('#id_keep_case_default_tester')[0].disabled = true;
}
});
Expand Down
1 change: 0 additions & 1 deletion tcms/templates/plan/clone.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ <h2>{% trans "Clone TestPlan" %} {{ test_plan.name }}</h2>
<legend>{{ clone_form.link_testcases }}{% trans "Copy" %} {{ clone_form.link_testcases.label }}</legend>
<ul id="id_clone_case_zone" style="display:block ;list-style-type:none;">
<li>{{ clone_form.copy_testcases }}{{ clone_form.copy_testcases.label }} ({{ clone_form.copy_testcases.help_text }})</li>
<li>{{ clone_form.maintain_case_orignal_author }}{{ clone_form.maintain_case_orignal_author.label }} ({{ clone_form.maintain_case_orignal_author.help_text }})</li>
<li>{{ clone_form.keep_case_default_tester }}{{ clone_form.keep_case_default_tester.label }} ({{ clone_form.keep_case_default_tester.help_text }})</li>
</ul>
</fieldset>
Expand Down
5 changes: 0 additions & 5 deletions tcms/testplans/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,6 @@ class ClonePlanForm(BasePlanForm):
help_text='Unchecking will create a link to selected plans',
required=False
)
maintain_case_orignal_author = forms.BooleanField(
label='Maintain original authors',
help_text='Unchecking will make me the author of the copied cases',
required=False
)
keep_case_default_tester = forms.BooleanField(
label='Keep Default Tester',
help_text='Unchecking will make me the default tester of copied cases',
Expand Down
5 changes: 1 addition & 4 deletions tcms/testplans/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ def make_cloned_name(self):
def clone(self, new_name=None, product=None, version=None,
new_author=None, set_parent=True,
link_cases=True, copy_cases=None,
new_case_author=None,
new_case_default_tester=None,
default_component_initial_owner=None):
"""Clone this plan
Expand All @@ -168,7 +167,6 @@ def clone(self, new_name=None, product=None, version=None,
:param bool link_cases: Whether to link cases to cloned plan. Default is True.
:param bool copy_cases: Whether to copy cases to cloned plan instead of just linking them.
Default is False.
:param new_case_author: The author of copied cases. Used only if copy cases.
:param new_case_default_tester: The default tester of copied cases. Used only if copy cases.
:param default_component_initial_owner: Used only if copy cases. If copied case does not
have original case' component, create it and use this value as the initial_owner.
Expand Down Expand Up @@ -203,7 +201,6 @@ def clone(self, new_name=None, product=None, version=None,
# duplicating the clone operation here
for tpcase_src in tpcases_src:
tcp = get_object_or_404(TestCasePlan, plan=self, case=tpcase_src)
author = new_case_author or tpcase_src.author
default_tester = new_case_default_tester or tpcase_src.default_tester

tc_category, _ = Category.objects.get_or_create(
Expand All @@ -219,7 +216,7 @@ def clone(self, new_name=None, product=None, version=None,
case_status=TestCaseStatus.get_proposed(),
category=tc_category,
priority=tpcase_src.priority,
author=author,
author=new_author,
default_tester=default_tester,
text=tpcase_src.text)

Expand Down
10 changes: 2 additions & 8 deletions tcms/testplans/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,6 @@ def test_open_clone_page_to_clone_one_plan(self):

def verify_cloned_plan(self, original_plan, cloned_plan,
link_cases=True, copy_cases=None,
maintain_case_orignal_author=None,
keep_case_default_tester=None):
self.assertEqual('Copy of {}'.format(original_plan.name), cloned_plan.name)
self.assertEqual(cloned_plan.text, original_plan.text)
Expand All @@ -466,11 +465,10 @@ def verify_cloned_plan(self, original_plan, cloned_plan,
# Verify if case' author and default tester are set properly
for original_case, copied_case in zip(original_plan.case.all(),
cloned_plan.case.all()):
if maintain_case_orignal_author:
if not copy_cases:
self.assertEqual(original_case.author, copied_case.author)
else:
me = self.plan_tester
self.assertEqual(me, copied_case.author)
self.assertEqual(self.plan_tester, copied_case.author)

if keep_case_default_tester:
self.assertEqual(original_case.default_tester, copied_case.default_tester)
Expand All @@ -496,7 +494,6 @@ def test_clone_a_plan_with_default_options(self):
'product_version': self.version.pk,
'set_parent': 'on',
'link_testcases': 'on',
'maintain_case_orignal_author': 'on',
'keep_case_default_tester': 'on',
'submit': 'Clone',
}
Expand All @@ -522,7 +519,6 @@ def test_clone_a_plan_by_copying_cases(self):
'product_version': self.version.pk,
'set_parent': 'on',
'link_testcases': 'on',
'maintain_case_orignal_author': 'on',
'keep_case_default_tester': 'on',
'submit': 'Clone',

Expand All @@ -535,7 +531,6 @@ def test_clone_a_plan_by_copying_cases(self):
cloned_plan = TestPlan.objects.get(name=self.totally_new_plan.make_cloned_name())
self.verify_cloned_plan(self.totally_new_plan, cloned_plan,
copy_cases=True,
maintain_case_orignal_author=True,
keep_case_default_tester=True)

def test_clone_a_plan_by_setting_me_to_copied_cases_author_default_tester(self):
Expand All @@ -549,7 +544,6 @@ def test_clone_a_plan_by_setting_me_to_copied_cases_author_default_tester(self):
'submit': 'Clone',

'copy_testcases': 'on',
# Do not pass maintain_case_orignal_author and keep_case_default_tester
}
self.client.login( # nosec:B106:hardcoded_password_funcarg
username=self.plan_tester.username,
Expand Down
6 changes: 0 additions & 6 deletions tcms/testplans/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,6 @@ def clone(request):

clone_params['new_author'] = request.user

assign_me_as_copied_case_author = \
clone_options['copy_testcases'] and \
not clone_options['maintain_case_orignal_author']
if assign_me_as_copied_case_author:
clone_params['new_case_author'] = request.user

# pylint: disable=invalid-name
assign_me_as_copied_case_default_tester = \
clone_options['copy_testcases'] and \
Expand Down

0 comments on commit 8452b57

Please sign in to comment.