Skip to content

Commit

Permalink
Update TestRun complation status manually. Fix #367
Browse files Browse the repository at this point in the history
TestRun.update_completion_status() is now called in only 2 places
after a user selected action. We've removed the functionality to
update the status automatically and removed all signals related
to that.

This will also fix #367 because emails are sent after TestRun.save()
which now is less often (e.g. when user edits or changes status).
  • Loading branch information
atodorov committed Jul 22, 2018
1 parent 1120695 commit ce73da4
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 125 deletions.
22 changes: 0 additions & 22 deletions tcms/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
'handle_emails_pre_case_delete',
'handle_emails_post_plan_save',
'handle_emails_post_run_save',
'handle_post_case_run_save',
'handle_post_case_run_delete',
]


Expand Down Expand Up @@ -139,23 +137,3 @@ def handle_emails_post_run_save(sender, *_args, **kwargs):
subject=subject,
recipients=instance.get_notify_addrs(),
context={'test_run': instance})


def handle_post_case_run_save(sender, *_args, **kwargs):
"""
Auto-update TestRun status after TestCaseRun is created!
"""
# TODO: does this work properly
instance = kwargs['instance']
# todo: what about after update ????
if kwargs.get('created'):
instance.run.update_completion_status(is_auto_updated=True)


def handle_post_case_run_delete(sender, **kwargs):
"""
Auto-update TestRun status after TestCaseRun is deleted!
"""
# TODO: does this work properly
instance = kwargs['instance']
instance.run.update_completion_status(is_auto_updated=True)
12 changes: 0 additions & 12 deletions tcms/static/js/testrun_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,18 +306,6 @@ Nitrate.TestRuns.New.on_load = function() {
Nitrate.TestRuns.Edit.on_load = function() {
bind_version_selector_to_product(false);
bind_build_selector_to_product(false);
if (jQ('#id_auto_update_run_status').attr('checked')) {
jQ('#id_finished').attr({'checked': false, 'disabled': true});
}
jQ('#id_auto_update_run_status').bind('click', function(){
if (jQ('#id_auto_update_run_status').attr('checked')) {
jQ('#id_finished').attr({'checked': false, 'disabled': true});
} else {
if (jQ('#id_finished').attr('disabled')) {
jQ('#id_finished').attr('disabled', false);
}
}
});
jQ('#add_id_product_version, #add_id_build').bind('click', function() {
return popupAddAnotherWindow(this, 'product');
});
Expand Down
4 changes: 0 additions & 4 deletions tcms/templates/run/clone.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ <h2>Clone Test Run - {{ test_run.summary }}</h2>
<td><label for="id_default_tester">Default Tester</label></td>
<td>{{ clone_form.default_tester }} <div class="errors">{{ clone_form.default_tester.errors }}</div></td>
</tr>
<tr>
<td><label for="id_auto_update_run_status">Set Status Automatically</label></td>
<td>{{ clone_form.auto_update_run_status }} <span class="system_help">{{ clone_form.auto_update_run_status.help_text }}</span>
</tr>
<tr>
<td><label class="strong" for="id_estimated_time">Estimated Time</label></td>
<td>
Expand Down
7 changes: 0 additions & 7 deletions tcms/templates/run/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,6 @@ <h2>Edit Test Run</h2>
<span class="system_help">Check to finish this test run directly.</span>
</td>
</tr>
<tr>
<td><label>{{ form.auto_update_run_status.label }}</span></td>
<td class="note">
{{ form.auto_update_run_status }}
<span class="system_help">{{form.auto_update_run_status.help_text}}</span>
</td>
</tr>
</table>
<div id="control_box" class="submit-row">
<input type="submit" value="Save" />
Expand Down
14 changes: 0 additions & 14 deletions tcms/templates/run/get.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ <h2 id="display_title">{{ test_run.summary }}</h2>
</div>
<div class="listinfo">
<div class="title grey">Status&nbsp;:</div>
{% if not test_run.auto_update_run_status %}
<div class="name">
{% if test_run.stop_date %}
<span class="pauselink"> Finished </span>
Expand All @@ -171,15 +170,6 @@ <h2 id="display_title">{{ test_run.summary }}</h2>
{% endif %}
{% endif %}
</div>
{% else %}
<div class="name">
{% if test_run.stop_date %}
<span class="pauselink"> Finished </span>
{% else %}
<span class="runninglink">Running</span>
{% endif %}
</div>
{% endif %}
</div>
<div class="listinfo">
<div class="title grey">Finished at&nbsp;:</div>
Expand All @@ -193,10 +183,6 @@ <h2 id="display_title">{{ test_run.summary }}</h2>
{% include 'run/get_cc.html' %}
</div>
</div>
<div class="listinfo">
<div class="title grey">Set Status Automatically&nbsp;:</div>
<div class="name"> {{ test_run.auto_update_run_status }} </div>
</div>
<div class="clear"></div>
</div>

Expand Down
4 changes: 0 additions & 4 deletions tcms/templates/run/new.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ <h2>Create New Test Run</h2>
<td valign="top" valign="top"><label for="id_default_tester">Default Tester</label></td>
<td>{{ form.default_tester }} <div class="errors">{{ form.default_tester.errors }}</div></td>
</tr>
<tr>
<td valign="top" valign="top"><label for="auto_update_run_status">Set Status Automatically</label></td>
<td>{{ form.auto_update_run_status }} <span class="system_help">{{ form.auto_update_run_status.help_text }}</span></td>
</tr>
<tr>
<td valign="top" valign="top"><label class="strong" for="id_estimated_time">Estimated Time</label></td>
<td>
Expand Down
8 changes: 2 additions & 6 deletions tcms/testruns/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ class AppConfig(DjangoAppConfig):
name = 'tcms.testruns'

def ready(self):
from django.db.models.signals import post_save, post_delete, pre_save
from .models import TestRun, TestCaseRun
from django.db.models.signals import post_save, pre_save
from .models import TestRun
from tcms import signals

post_save.connect(signals.handle_emails_post_run_save, sender=TestRun)
post_save.connect(signals.handle_post_case_run_save, sender=TestCaseRun,
dispatch_uid='tcms.testruns.models.TestCaseRun')
post_delete.connect(signals.handle_post_case_run_delete, sender=TestCaseRun,
dispatch_uid='tcms.testruns.models.TestCaseRun')
pre_save.connect(signals.pre_save_clean, sender=TestRun)
6 changes: 0 additions & 6 deletions tcms/testruns/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ class BaseRunForm(forms.Form):
required=False,
initial=True
)
auto_update_run_status = forms.BooleanField(
label='Set Status Automatically', widget=forms.CheckboxInput(),
help_text='Check to update test run status automatically',
required=False,
initial=False
)

def populate(self, product_id):
# We can dynamically set choices for a form field:
Expand Down
21 changes: 21 additions & 0 deletions tcms/testruns/migrations/0016_remove_auto_update_run_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 2.0.7 on 2018-07-19 08:07

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('testruns', '0015_historicaltestrun'),
]

operations = [
migrations.RemoveField(
model_name='historicaltestrun',
name='auto_update_run_status',
),
migrations.RemoveField(
model_name='testrun',
name='auto_update_run_status',
),
]
19 changes: 5 additions & 14 deletions tcms/testruns/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class TestRun(TCMSActionModel):
related_name='run')

cc = models.ManyToManyField('auth.User', through='testruns.TestRunCC')
auto_update_run_status = models.BooleanField(default=False)

class Meta:
unique_together = ('run_id', 'product_version')
Expand Down Expand Up @@ -238,19 +237,11 @@ def _get_total_case_run_num(self):

total_num_caseruns = property(_get_total_case_run_num)

def update_completion_status(self, is_auto_updated, is_finish=None):
if is_auto_updated and self.auto_update_run_status:
if self.completed_case_run_percent == 100.0:
self.stop_date = datetime.datetime.now()
else:
self.stop_date = None
self.save()
if not is_auto_updated and not self.auto_update_run_status:
if is_finish:
self.stop_date = datetime.datetime.now()
else:
self.stop_date = None
self.save()
def update_completion_status(self, is_finished):
if is_finished:
self.stop_date = datetime.datetime.now()
else:
self.stop_date = None

def env_values_str(self):
"""
Expand Down
40 changes: 5 additions & 35 deletions tcms/testruns/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ def new(request, template_name='run/new.html'):
manager=form.cleaned_data['manager'],
default_tester=default_tester,
estimated_time=form.cleaned_data['estimated_time'],
auto_update_run_status=form.cleaned_data['auto_update_run_status']
)

keep_status = form.cleaned_data['keep_status']
Expand Down Expand Up @@ -616,22 +615,6 @@ def edit(request, run_id, template_name='run/edit.html'):

# FIXME: Error handler
if form.is_valid():
# detect if auto_update_run_status field is changed by user when
# edit testrun.
auto_update_changed = False
if test_run.auto_update_run_status \
!= form.cleaned_data['auto_update_run_status']:
auto_update_changed = True

# detect if finished field is changed by user when edit testrun.
finish_field_changed = False
if test_run.stop_date and not form.cleaned_data['finished']:
finish_field_changed = True
is_finish = False
elif not test_run.stop_date and form.cleaned_data['finished']:
finish_field_changed = True
is_finish = True

test_run.summary = form.cleaned_data['summary']
# Permission hack
if test_run.manager == request.user or test_run.plan.author == request.user:
Expand All @@ -641,17 +624,9 @@ def edit(request, run_id, template_name='run/edit.html'):
test_run.product_version = form.cleaned_data['product_version']
test_run.notes = form.cleaned_data['notes']
test_run.estimated_time = form.cleaned_data['estimated_time']
test_run.auto_update_run_status = form.cleaned_data[
'auto_update_run_status']
test_run.update_completion_status(form.cleaned_data['finished'])
test_run.save()
if auto_update_changed:
test_run.update_completion_status(is_auto_updated=True)
if finish_field_changed:
test_run.update_completion_status(is_auto_updated=False,
is_finish=is_finish)
return HttpResponseRedirect(
reverse('testruns-get', args=[run_id, ])
)
return HttpResponseRedirect(reverse('testruns-get', args=[run_id, ]))
else:
# Generate a blank form
form = EditRunForm(initial={
Expand All @@ -665,7 +640,6 @@ def edit(request, run_id, template_name='run/edit.html'):
'notes': test_run.notes,
'finished': test_run.stop_date,
'estimated_time': test_run.estimated_time,
'auto_update_run_status': test_run.auto_update_run_status,
})
form.populate(product_id=test_run.build.product_id)

Expand Down Expand Up @@ -922,14 +896,10 @@ def change_status(request, run_id):
"""Change test run finished or running"""
test_run = get_object_or_404(TestRun, run_id=run_id)

if request.GET.get('finished') == '1':
test_run.update_completion_status(is_auto_updated=False, is_finish=True)
else:
test_run.update_completion_status(is_auto_updated=False, is_finish=False)
test_run.update_completion_status(request.GET.get('finished') == '1')
test_run.save()

return HttpResponseRedirect(
reverse('testruns-get', args=[run_id, ])
)
return HttpResponseRedirect(reverse('testruns-get', args=[run_id, ]))


@require_POST
Expand Down
1 change: 0 additions & 1 deletion tcms/xmlrpc/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ class TestRunXMLRPCSerializer(QuerySetBasedXMLRPCSerializer):
"""Serializer for TestRun"""

values_fields_mapping = {
'auto_update_run_status': ('auto_update_run_status', do_nothing),
'environment_id': ('environment_id', do_nothing),
'estimated_time': ('estimated_time', timedelta_to_str),
'notes': ('notes', do_nothing),
Expand Down

0 comments on commit ce73da4

Please sign in to comment.