Skip to content

Commit

Permalink
Refactor updateAssignee to use JSON-RPC. Refs kiwitcms#1063
Browse files Browse the repository at this point in the history
Remove unused imports

Refactor update of assignee rpc call

Remove override of assignee form field

Remove trimming

Fix tests for changeAssignee

Revert change in test case for updateAssignee with invalid id

Add tests for updateAssignee
  • Loading branch information
rsasov committed Apr 23, 2020
1 parent 050859b commit 15fc82d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 51 deletions.
1 change: 0 additions & 1 deletion tcms/rpc/api/forms/testrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,5 @@ def clean_status(self):


class UpdateExecutionForm(BaseCaseRunForm):
assignee = forms.ModelChoiceField(queryset=User.objects.all(), required=False)
tested_by = forms.ModelChoiceField(queryset=User.objects.all(), required=False)
build = forms.ModelChoiceField(queryset=Build.objects.all(), required=False)
30 changes: 28 additions & 2 deletions tcms/rpc/tests/test_testexecution.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,40 @@ def test_update_with_single_caserun(self):
self.assertEqual(tcr['status'], self.status_positive.name)
self.assertEqual(tcr['sortkey'], 90)

def test_update_with_assignee_id(self):
tcr = self.rpc_client.TestExecution.update(self.case_run_1.pk, {
"assignee": self.user.pk
})
self.assertEqual(tcr['assignee'], self.user.username)

def test_update_with_assignee_email(self):
tcr = self.rpc_client.TestExecution.update(self.case_run_1.pk, {
"assignee": self.user.email
})
self.assertEqual(tcr['assignee'], self.user.username)

def test_update_with_assignee_username(self):
tcr = self.rpc_client.TestExecution.update(self.case_run_1.pk, {
"assignee": self.user.username
})
self.assertEqual(tcr['assignee'], self.user.username)

def test_update_with_non_existing_build(self):
with self.assertRaisesRegex(XmlRPCFault, 'Select a valid choice'):
self.rpc_client.TestExecution.update(self.case_run_1.pk, {"build": 1111111})

def test_update_with_non_existing_assignee(self):
with self.assertRaisesRegex(XmlRPCFault, 'Select a valid choice'):
def test_update_with_non_existing_assignee_id(self):
with self.assertRaisesRegex(XmlRPCFault, 'Unknown user_id'):
self.rpc_client.TestExecution.update(self.case_run_1.pk, {"assignee": 1111111})

def test_update_with_non_existing_assignee_email(self):
with self.assertRaisesRegex(XmlRPCFault, 'Unknown user'):
self.rpc_client.TestExecution.update(self.case_run_1.pk, {"assignee": '[email protected]'})

def test_update_with_non_existing_assignee_username(self):
with self.assertRaisesRegex(XmlRPCFault, 'Unknown user:'):
self.rpc_client.TestExecution.update(self.case_run_1.pk, {"assignee": 'nonExistentUsername'})

def test_update_with_non_existing_status(self):
with self.assertRaisesRegex(XmlRPCFault, 'Select a valid choice'):
self.rpc_client.TestExecution.update(self.case_run_1.pk,
Expand Down
22 changes: 6 additions & 16 deletions tcms/static/js/testrun_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,28 +527,18 @@ function removeRunCC(run_id, user, container) {
}

function changeCaseRunAssignee() {
var runs = serializeCaseRunFromInputList(jQ('#id_table_cases')[0]);
if (!runs.length) {
var executions = serializeCaseRunFromInputList(jQ('#id_table_cases')[0]);
if (!executions.length) {
window.alert(default_messages.alert.no_case_selected);
return false;
}

var p = window.prompt('Please type new email or username for assignee');
if (!p) {
var assignee = window.prompt('Please type new email or username for assignee');
if (!assignee) {
return false;
}

jQ.ajax({
'url': '/runs/update-assignee/',
'type': 'POST',
'data': { ids: runs, assignee: p },
'success': function (data, textStatus, jqXHR) {
window.location.reload();
},
'error': function (jqXHR, textStatus, errorThrown) {
json_failure(jqXHR);
}
});
executions.forEach(execution_id => jsonRPC('TestExecution.update', [execution_id, {'assignee': assignee}], () => { }, sync=true));
window.location.reload();
}

function serializeCaseRunFromInputList(table, name) {
Expand Down
1 change: 0 additions & 1 deletion tcms/testruns/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
url(r'^(?P<pk>\d+)/cc/$', views.ManageTestRunCC.as_view(), name='testruns-cc'),
url(r'^(?P<pk>\d+)/update/$', views.UpdateCaseRunTextView.as_view(),
name='testruns-update_case_run_text'),
url(r'^update-assignee/$', views.UpdateAssigneeView.as_view()),

url(r'^search/$', views.SearchTestRunView.as_view(), name='testruns-search'),
]
32 changes: 1 addition & 31 deletions tcms/testruns/views.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# -*- coding: utf-8 -*-

from http import HTTPStatus

from django.conf import settings
from django.contrib import messages
from django.contrib.auth import get_user_model
from django.contrib.auth.decorators import permission_required
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Count, Q
from django.http import Http404, HttpResponseRedirect, JsonResponse
from django.http import Http404, HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
from django.urls import reverse
from django.utils.decorators import method_decorator
Expand Down Expand Up @@ -584,31 +582,3 @@ def get_caseruns_of_runs(runs, kwargs=None):
if status:
caseruns = caseruns.filter(status__name__iexact=status)
return caseruns


@method_decorator(permission_required('testruns.change_testexecution'), name='dispatch')
class UpdateAssigneeView(View):
"""Updates TestExecution.assignee. Called from the front-end."""

http_method_names = ['post']

def post(self, request):
assignee = request.POST.get('assignee')
try:
user = User.objects.get(username=assignee)
except User.DoesNotExist:
try:
user = User.objects.get(email=assignee)
except User.DoesNotExist:
return JsonResponse({'rc': 1,
'response': _('User %s not found!') % assignee},
status=HTTPStatus.NOT_FOUND)

object_ids = request.POST.getlist('ids[]')

for caserun_pk in object_ids:
execution = get_object_or_404(TestExecution, pk=int(caserun_pk))
execution.assignee = user
execution.save()

return JsonResponse({'rc': 0, 'response': 'ok'})

0 comments on commit 15fc82d

Please sign in to comment.