Skip to content

Commit

Permalink
Simplify TestPlan.add_text() by removing extra parameter
Browse files Browse the repository at this point in the history
there's no need both the method and the caller to check if the
incoming text is different from the one we already have.
  • Loading branch information
atodorov committed Jun 26, 2018
1 parent 14d58b9 commit 8cc43d6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
13 changes: 6 additions & 7 deletions tcms/testplans/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,16 @@ def text_checksum(self):
except ObjectDoesNotExist:
return None

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

return self.text.create(
author=author,
plan_text=plan_text,
checksum=text_checksum or checksum(plan_text)
checksum=new_checksum
)

def add_case(self, case, sortkey=0):
Expand Down
9 changes: 1 addition & 8 deletions tcms/testplans/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from uuslug import slugify

from tcms.core.models import TCMSLog
from tcms.core.utils.checksum import checksum
from tcms.core.utils import DataTableResult
from tcms.core.utils.raw_sql import RawSQL
from tcms.management.models import EnvGroup
Expand Down Expand Up @@ -469,13 +468,7 @@ def edit(request, plan_id, template_name='plan/edit.html'):
test_plan.save()

if request.user.has_perm('testplans.add_testplantext'):
new_text = form.cleaned_data['text']
text_checksum = checksum(new_text)

if not test_plan.text_exist() or text_checksum != test_plan.text_checksum():
test_plan.add_text(author=request.user,
plan_text=new_text,
text_checksum=text_checksum)
test_plan.add_text(author=request.user, plan_text=form.cleaned_data['text'])

if request.user.has_perm('testplans.change_envplanmap'):
test_plan.clear_env_groups()
Expand Down

0 comments on commit 8cc43d6

Please sign in to comment.