Skip to content

Commit

Permalink
Remove TestPlanText model, use TestPlan.text instead
Browse files Browse the repository at this point in the history
Now that we have proper history tracking we don't need a separate
model to hold versions of the text. Instead this can be a field
inside TestPlan model.

- remove unused showMoreSummary() and showShortSummary()
  JavaScript functions
- remove now unnecessary clone_form.copy_texts ption
- simplify plan/get_docs.html template and merge with plan/get.html
- remove TestPlan.latest_text() and TestPlan.add_text() methods,
  refs #198
  • Loading branch information
atodorov committed Jul 9, 2018
1 parent 8010716 commit f9fd339
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 166 deletions.
20 changes: 0 additions & 20 deletions tcms/static/js/testplan_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1070,26 +1070,6 @@ Nitrate.TestPlans.Clone.on_load = function() {
});
};

function showMoreSummary() {
jQ('#display_summary').show();
if (jQ('#display_summary_short').length) {
jQ('#id_link_show_more').hide();
jQ('#id_link_show_short').show();
jQ('#display_summary_short').hide();
}
}

function showShortSummary() {
jQ('#id_link_show_more').show();
jQ('#display_summary').hide();
if (jQ('#display_summary_short').length) {
jQ('#id_link_show_short').hide();
jQ('#display_summary_short').show();
}

window.scrollTo(0, 0);
}

/*
* Unlink selected cases from current TestPlan.
*
Expand Down
2 changes: 1 addition & 1 deletion tcms/templates/case/printable.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ <h3>Contents</h3>
<div>
<h2 id="plan_document">Test Plan Document</h2>
<div class="thick-line"></div>
{{ test_plan.latest_text.plan_text|safe }}
{{ test_plan.text|safe }}
</div>
</div>
{% endif %}
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 @@ -79,7 +79,6 @@ <h2>Clone Test Plan</h2>
<ul class="ul-no-format">
<li>{{ clone_form.set_parent }}{{ clone_form.set_parent.label }} ({{ clone_form.set_parent.help_text }})</li>
<li>{{ clone_form.keep_orignal_author }}{{ clone_form.keep_orignal_author.label }} ({{ clone_form.keep_orignal_author.help_text }})</li>
<li>{{ clone_form.copy_texts }}{{ clone_form.copy_texts.label }} ({{ clone_form.copy_texts.help_text }})</li>
<li>{{ clone_form.copy_environment_group }}{{ clone_form.copy_environment_group.label }} ({{ clone_form.copy_environment_group.help_text }})</li>
<li>
<fieldset class="choose">
Expand Down
5 changes: 1 addition & 4 deletions tcms/templates/plan/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
<style>
#tab_testcases{ padding-left:5px;}
#tab_testruns {padding-left:5px;}
.display_summary textarea{
background:red;
}
</style>
{% endblock %}

Expand Down Expand Up @@ -112,7 +109,7 @@
<tr>
<td><label class="lab strong">Plan Document</label></td>
<td>
<div id="display_summary" class="mec">
<div>
{{ form.text }}
</div>
<div >{{ form.text.errors }}</div>
Expand Down
13 changes: 10 additions & 3 deletions tcms/templates/plan/get.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
<input type="hidden" name="content_type" value="testplans.testplan" />
<input type="hidden" name="object_pk" value="{{ test_plan.pk }}" />
<input type="hidden" name="name" value="{{ test_plan.name }}" />
{# <input type="hidden" name="description" value="{{ test_plan.latest_text.plan_text }}" /> #}
{% endblock %}

{% block contents %}
Expand Down Expand Up @@ -107,7 +106,7 @@ <h2 id="display_title" class="{% ifequal test_plan.is_active 0 %}line-through{%
<span class="blue strong"><a href="{% url "plans-all" %}?action=search&name__icontains=&author__email__startswith=&owner__username__startswith=&type=&tag__name__in=&case__default_tester__username__startswith=&product=&product_version=&env_group={{ env_group.id }}&create_date__gte=&create_date__lte=" title="Search plans of use {{ env_group.name }} ">{{ env_group.name }}</a></span>
{% endfor %}
</div>
<div id="display_summary" >
<div>
{% for env_property in env_properties %}
{{ env_property.property.name }},
{% endfor %}
Expand Down Expand Up @@ -173,7 +172,15 @@ <h2 id="display_title" class="{% ifequal test_plan.is_active 0 %}line-through{%
</li>
</ul>
<div id="document" class="tab_list" style="display:none">
{% include "plan/get_docs.html" %}
<div class="listinfo_doc_content">
<div id="display_summary" class="listinfo_doc">
{% if test_plan.text %}
{{ test_plan.text|safe }}
{% else %}
<span style="color: #666">The document for this plan hasn't been written yet.</span>
{% endif %}
</div>
</div>
</div>
<div id="attachment" class="tab_list" style="display:none">
{% include "plan/get_attachments.html" %}
Expand Down
23 changes: 0 additions & 23 deletions tcms/templates/plan/get_docs.html

This file was deleted.

2 changes: 1 addition & 1 deletion tcms/templates/plan/preview.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<div class="listinfo">
<div class="title">Document</div>
<div class="contenttext">
{{ test_plan.latest_text.plan_text|safe }}
{{ test_plan.text|safe }}
</div>
</div>
<div class="clear"></div>
Expand Down
4 changes: 0 additions & 4 deletions tcms/testplans/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,6 @@ class ClonePlanForm(BasePlanForm):
help_text='Unchecking will make me the author of the copied plan',
required=False,
)
copy_texts = forms.BooleanField(
label='Copy Plan Document',
required=False,
)
copy_environment_group = forms.BooleanField(
label='Copy environment group',
help_text='Check it on to copy environment group of the plan.',
Expand Down
64 changes: 64 additions & 0 deletions tcms/testplans/migrations/0017_move_text_into_testplan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Generated by Django 2.0.7 on 2018-07-07 21:07

from django.db import migrations, models


def forward_copy_data(apps, schema_editor):
TestPlan = apps.get_model('testplans', 'TestPlan')
TestPlanText = apps.get_model('testplans', 'TestPlanText')

for test_plan in TestPlan.objects.all():
latest_text = TestPlanText.objects.filter(plan=test_plan.pk).order_by('-pk').first()
if latest_text:
test_plan.plan_text = latest_text.plan_text
test_plan.save()


class Migration(migrations.Migration):

dependencies = [
('testplans', '0016_historicaltestplan'),
]

operations = [
# add new field to hold TP text but use a temporary name
# b/c `text` is also the name of the pre-existing reverse relationship
migrations.AddField(
model_name='historicaltestplan',
name='plan_text',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='testplan',
name='plan_text',
field=models.TextField(blank=True),
),

# copy the data from the related model
migrations.RunPython(forward_copy_data),

# remove the related model
migrations.RemoveField(
model_name='testplantext',
name='author',
),
migrations.RemoveField(
model_name='testplantext',
name='plan',
),
migrations.DeleteModel(
name='TestPlanText',
),

# rename the new field to what is inside the model source
migrations.RenameField(
model_name='historicaltestplan',
old_name='plan_text',
new_name='text',
),
migrations.RenameField(
model_name='testplan',
old_name='plan_text',
new_name='text',
),
]
48 changes: 3 additions & 45 deletions tcms/testplans/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from tcms.core.history import KiwiHistoricalRecords
from tcms.core.models import TCMSActionModel
from tcms.core.utils.checksum import checksum
from tcms.management.models import Version
from tcms.testcases.models import TestCase
from tcms.testcases.models import Category
Expand All @@ -37,6 +36,7 @@ class TestPlan(TCMSActionModel):

plan_id = models.AutoField(primary_key=True)
name = models.CharField(max_length=255, db_index=True)
text = models.TextField(blank=True)
create_date = models.DateTimeField(db_column='creation_date', auto_now_add=True)
is_active = models.BooleanField(db_column='isactive', default=True, db_index=True)
extra_link = models.CharField(max_length=1024, default=None, blank=True, null=True)
Expand Down Expand Up @@ -95,25 +95,6 @@ def list(cls, query=None):
def confirmed_case(self):
return self.case.filter(case_status__name='CONFIRMED')

def latest_text(self):
try:
return self.text.select_related('author').order_by('-pk')[0]
except IndexError:
return None
except ObjectDoesNotExist:
return None

def add_text(self, author, plan_text):
latest_text = self.latest_text()
old_checksum = None
if latest_text is not None:
old_checksum = checksum(latest_text.plan_text)

if old_checksum == checksum(plan_text):
return self.latest_text()

return self.text.create(author=author, plan_text=plan_text)

def add_case(self, case, sortkey=0):

tcp, is_created = TestCasePlan.objects.get_or_create(
Expand Down Expand Up @@ -174,7 +155,6 @@ def make_cloned_name(self):

def clone(self, new_name=None, product=None, version=None,
new_original_author=None, set_parent=True,
copy_texts=True, default_text_author=None,
copy_environment_group=True,
link_cases=True, copy_cases=None,
new_case_author=None,
Expand All @@ -191,9 +171,6 @@ def clone(self, new_name=None, product=None, version=None,
author is used.
:param bool set_parent: Whether to set original plan as parent of cloned plan.
Set by default.
:param bool copy_texts: Whether to copy the four text. Copy by default.
:param default_text_author: When not copy the four text, new text will be created.
This is the default author of new created text.
:param bool copy_environment_group: Whether to copy environment groups. Copy by default.
: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.
Expand All @@ -205,9 +182,6 @@ def clone(self, new_name=None, product=None, version=None,
:rtype: cloned plan
"""

if not copy_texts and not default_text_author:
raise ValueError('Missing default text author when not copy texts.')

if not copy_cases and not default_component_initial_owner:
raise ValueError('Missing default component initial owner when not copy cases.')

Expand All @@ -220,13 +194,8 @@ def clone(self, new_name=None, product=None, version=None,
create_date=self.create_date,
is_active=self.is_active,
extra_link=self.extra_link,
parent=self if set_parent else None)

# Copy the plan documents
if copy_texts:
latest_text = self.latest_text()
if latest_text is not None:
tp_dest.add_text(latest_text.author, latest_text.plan_text)
parent=self if set_parent else None,
text=self.text)

# Copy the plan tags
for tp_tag_src in self.tag.all():
Expand Down Expand Up @@ -299,17 +268,6 @@ def clone(self, new_name=None, product=None, version=None,
return tp_dest


class TestPlanText(TCMSActionModel):
plan = models.ForeignKey(TestPlan, related_name='text', on_delete=models.CASCADE)
author = models.ForeignKey(settings.AUTH_USER_MODEL, db_column='who', on_delete=models.CASCADE)
create_date = models.DateTimeField(auto_now_add=True,
db_column='creation_ts')
plan_text = models.TextField(blank=True)

class Meta:
ordering = ['plan', '-pk']


class TestPlanTag(models.Model):
tag = models.ForeignKey('management.Tag', on_delete=models.CASCADE)
plan = models.ForeignKey(TestPlan, on_delete=models.CASCADE)
Expand Down
17 changes: 2 additions & 15 deletions tcms/testplans/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from tcms.tests.factories import ProductFactory
from tcms.tests.factories import TestCaseFactory, TestCaseTextFactory
from tcms.tests.factories import TestPlanFactory
from tcms.tests.factories import TestPlanTextFactory
from tcms.tests.factories import PlanTypeFactory
from tcms.tests.factories import TagFactory
from tcms.tests.factories import EnvGroupFactory
Expand Down Expand Up @@ -137,8 +136,6 @@ def setUpTestData(cls):
case = TestCaseFactory(plan=[cls.test_plan])
TestCaseTextFactory(case=case)

TestPlanTextFactory(plan=cls.test_plan)

cls.plan_id = cls.test_plan.pk
cls.child_plan = TestPlanFactory(parent=cls.test_plan)

Expand Down Expand Up @@ -193,7 +190,7 @@ def test_plan_printable(self):
self.assertEqual(response.status_code, HTTPStatus.OK)

self.assertContains(response, self.test_plan.name)
self.assertContains(response, self.test_plan.latest_text().plan_text)
self.assertContains(response, self.test_plan.text)

confirmed = TestCaseStatus.objects.get(name='CONFIRMED')
for case in self.test_plan.case.filter(case_status=confirmed):
Expand Down Expand Up @@ -616,19 +613,13 @@ def verify_cloned_plan(self, original_plan, cloned_plan,
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)
self.assertEqual(Product.objects.get(pk=self.product.pk), cloned_plan.product)
self.assertEqual(Version.objects.get(pk=self.version.pk), cloned_plan.product_version)

# Verify option set_parent
self.assertEqual(TestPlan.objects.get(pk=original_plan.pk), cloned_plan.parent)

# Verify option copy_texts
self.assertEqual(cloned_plan.text.count(), original_plan.text.count())
for copied_text, original_text in zip(cloned_plan.text.all(),
original_plan.text.all()):
self.assertEqual(copied_text.author, original_text.author)
self.assertEqual(copied_text.plan_text, original_text.plan_text)

# Verify option copy_environment_groups
for env_group in original_plan.env_group.all():
added = EnvPlanMap.objects.filter(plan=cloned_plan, group=env_group).exists()
Expand Down Expand Up @@ -671,7 +662,6 @@ def test_clone_a_plan_with_default_options(self):
'product': self.product.pk,
'product_version': self.version.pk,
'set_parent': 'on',
'copy_texts': 'on',
'copy_environment_groups': 'on',
'link_testcases': 'on',
'maintain_case_orignal_author': 'on',
Expand Down Expand Up @@ -699,7 +689,6 @@ def test_clone_a_plan_by_copying_cases(self):
'product': self.product.pk,
'product_version': self.version.pk,
'set_parent': 'on',
'copy_texts': 'on',
'copy_environment_groups': 'on',
'link_testcases': 'on',
'maintain_case_orignal_author': 'on',
Expand All @@ -725,7 +714,6 @@ def test_clone_a_plan_by_setting_me_to_copied_cases_author_default_tester(self):
'product': self.product.pk,
'product_version': self.version.pk,
'set_parent': 'on',
'copy_texts': 'on',
'copy_environment_groups': 'on',
'link_testcases': 'on',
'submit': 'Clone',
Expand All @@ -746,7 +734,6 @@ def test_clone_multiple_plans_with_default_options(self):
'product': self.product.pk,
'product_version': self.version.pk,
'set_parent': 'on',
'copy_texts': 'on',
'copy_environment_groups': 'on',
'link_testcases': 'on',
'maintain_case_orignal_author': 'on',
Expand Down
Loading

0 comments on commit f9fd339

Please sign in to comment.