Skip to content

Commit

Permalink
Remove TestCaseRun. API methods. Fixes #889
Browse files Browse the repository at this point in the history
  • Loading branch information
atodorov committed May 15, 2019
1 parent 5e0db01 commit aa0a340
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 98 deletions.
98 changes: 30 additions & 68 deletions tcms/xmlrpc/api/testexecution.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
)


@rpc_method(name='TestCaseRun.add_comment')
@rpc_method(name='TestExecution.add_comment')
def add_comment(case_run_id, comment, **kwargs):
"""
.. function:: XML-RPC TestCaseRun.add_comment(case_run_id, comment)
.. function:: XML-RPC TestExecution.add_comment(case_run_id, comment)
Add comment to selected test execution.
:param case_run_id: PK of a TestCaseRun object
:param case_run_id: PK of a TestExecution object
:param case_run_id: int
:param comment: The text to add as a comment
:param comment: str
Expand All @@ -59,16 +59,16 @@ def add_comment(case_run_id, comment, **kwargs):
# todo: this is very similar, if not duplicate to TestRun.add_case IMO
# should we schedule it for removal ?!?
@permissions_required('testruns.add_testexecution')
@rpc_method(name='TestCaseRun.create')
@rpc_method(name='TestExecution.create')
def create(values):
"""
.. function:: XML-RPC TestCaseRun.create(values)
.. function:: XML-RPC TestExecution.create(values)
Create new TestCaseRun object and store it in the database.
Create new TestExecution object and store it in the database.
:param values: Field values for :class:`tcms.testruns.models.TestCaseRun`
:param values: Field values for :class:`tcms.testruns.models.TestExecution`
:type values: dict
:return: Serialized :class:`tcms.testruns.models.TestCaseRun` object
:return: Serialized :class:`tcms.testruns.models.TestExecution` object
:raises: PermissionDenied if missing *testruns.add_testexecution* permission
Minimal parameters::
Expand Down Expand Up @@ -106,34 +106,34 @@ def create(values):
return testcase_run.serialize()


@rpc_method(name='TestCaseRun.filter')
@rpc_method(name='TestExecution.filter')
def filter(values): # pylint: disable=redefined-builtin
"""
.. function:: XML-RPC TestCaseRun.filter(values)
.. function:: XML-RPC TestExecution.filter(values)
Perform a search and return the resulting list of test case executions.
:param values: Field lookups for :class:`tcms.testruns.models.TestCaseRun`
:param values: Field lookups for :class:`tcms.testruns.models.TestExecution`
:type values: dict
:return: List of serialized :class:`tcms.testruns.models.TestCaseRun` objects
:return: List of serialized :class:`tcms.testruns.models.TestExecution` objects
:rtype: list(dict)
"""
return TestExecution.to_xmlrpc(values)


@permissions_required('testruns.change_testexecution')
@rpc_method(name='TestCaseRun.update')
@rpc_method(name='TestExecution.update')
def update(case_run_id, values, **kwargs):
"""
.. function:: XML-RPC TestCaseRun.update(case_run_id, values)
.. function:: XML-RPC TestExecution.update(case_run_id, values)
Update the selected TestCaseRun
Update the selected TestExecution
:param case_run_id: PK of TestCaseRun to modify
:param case_run_id: PK of TestExecution to modify
:type case_run_id: int
:param values: Field values for :class:`tcms.testruns.models.TestCaseRun`
:param values: Field values for :class:`tcms.testruns.models.TestExecution`
:type values: dict
:return: Serialized :class:`tcms.testruns.models.TestCaseRun` object
:return: Serialized :class:`tcms.testruns.models.TestExecution` object
:raises: PermissionDenied if missing *testruns.change_testexecution* permission
"""
from tcms.testruns.forms import XMLRPCUpdateExecutionForm
Expand Down Expand Up @@ -164,14 +164,14 @@ def update(case_run_id, values, **kwargs):
return tcr.serialize()


@rpc_method(name='TestCaseRun.add_link')
@rpc_method(name='TestExecution.add_link')
def add_link(case_run_id, name, url):
"""
.. function:: XML-RPC TestCaseRun.add_link(case_run_id, name, url)
.. function:: XML-RPC TestExecution.add_link(case_run_id, name, url)
Add new URL link to a TestCaseRun
Add new URL link to a TestExecution
:param case_run_id: PK of a TestCaseRun object
:param case_run_id: PK of a TestExecution object
:type case_run_id: int
:param name: Name/description of the link
:type name: str
Expand All @@ -192,14 +192,14 @@ def add_link(case_run_id, name, url):
return result['data']['pk']


@rpc_method(name='TestCaseRun.remove_link')
@rpc_method(name='TestExecution.remove_link')
def remove_link(case_run_id, link_id):
"""
.. function:: XML-RPC TestCaseRun.remove_link(case_run_id, link_id)
.. function:: XML-RPC TestExecution.remove_link(case_run_id, link_id)
Remove URL link from TestCaseRun
Remove URL link from TestExecution
:param case_run_id: PK of TestCaseRun to modify
:param case_run_id: PK of TestExecution to modify
:type case_run_id: int
:param link_id: PK of link to remove
:type link_id: int
Expand All @@ -208,56 +208,18 @@ def remove_link(case_run_id, link_id):
LinkReference.objects.filter(pk=link_id, test_case_run=case_run_id).delete()


@rpc_method(name='TestCaseRun.get_links')
@rpc_method(name='TestExecution.get_links')
def get_links(case_run_id):
"""
.. function:: XML-RPC TestCaseRun.get_links(case_run_id)
.. function:: XML-RPC TestExecution.get_links(case_run_id)
Get URL links for the specified TestCaseRun
Get URL links for the specified TestExecution
:param case_run_id: PK of TestCaseRun object
:param case_run_id: PK of TestExecution object
:type case_run_id: int
:return: Serialized list of :class:`tcms.core.contrib.linkreference.models.LinkReference`
objects
"""
links = LinkReference.objects.filter(test_case_run=case_run_id)
serialier = XMLRPCSerializer(links)
return serialier.serialize_queryset()


# workaround for keeping backward-compatibility with users of the API calling TestCaseRun.*
@rpc_method(name='TestExecution.add_comment')
def test_execution_add_comment(case_run_id, comment, **kwargs):
return add_comment(case_run_id, comment, **kwargs)


@permissions_required('testruns.add_testexecution')
@rpc_method(name='TestExecution.create')
def test_execution_create(values):
return create(values)


@rpc_method(name='TestExecution.filter')
def test_execution_filter(values):
return filter(values)


@rpc_method(name='TestExecution.get_links')
def test_execution_get_links(case_run_id):
return get_links(case_run_id)


@rpc_method(name='TestExecution.remove_link')
def test_execution_remove_link(case_run_id, link_id):
return remove_link(case_run_id, link_id)


@permissions_required('testruns.change_testexecution')
@rpc_method(name='TestExecution.update')
def test_execution_update(case_run_id, values, **kwargs):
return update(case_run_id, values, **kwargs)


@rpc_method(name='TestExecution.add_link')
def test_execution_add_link(case_run_id, name, url):
return add_link(case_run_id, name, url)
14 changes: 4 additions & 10 deletions tcms/xmlrpc/api/testexecutionstatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,16 @@
from tcms.testruns.models import TestExecutionStatus


@rpc_method(name='TestCaseRunStatus.filter')
@rpc_method(name='TestExecutionStatus.filter')
def filter(query): # pylint: disable=redefined-builtin
"""
.. function:: XML-RPC TestCaseRunStatus.filter(query)
.. function:: XML-RPC TestExecutionStatus.filter(query)
Search and return the list of test case run statuses.
:param query: Field lookups for :class:`tcms.testruns.models.TestCaseRunStatus`
:param query: Field lookups for :class:`tcms.testruns.models.TestExecutionStatus`
:type query: dict
:return: Serialized list of :class:`tcms.testruns.models.TestCaseRunStatus` objects
:return: Serialized list of :class:`tcms.testruns.models.TestExecutionStatus` objects
:rtype: list(dict)
"""
return TestExecutionStatus.to_xmlrpc(query)


# workaround for keeping backward-compatibility with users of the API calling TestCaseRunStatus.*
@rpc_method(name='TestExecutionStatus.filter')
def test_execution_filter(query):
return filter(query)
40 changes: 20 additions & 20 deletions tcms/xmlrpc/tests/test_testexecution.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_create_with_no_required_fields(self):
]
for value in values:
with self.assertRaisesRegex(XmlRPCFault, 'This field is required'):
self.rpc_client.exec.TestCaseRun.create(value)
self.rpc_client.exec.TestExecution.create(value)

def test_create_with_required_fields(self):
tcr = self.rpc_client.exec.TestExecution.create({
Expand All @@ -78,7 +78,7 @@ def test_create_with_required_fields(self):
self.assertEqual(tcr['run_id'], self.test_run.pk)

def test_create_with_all_fields(self):
tcr = self.rpc_client.exec.TestCaseRun.create({
tcr = self.rpc_client.exec.TestExecution.create({
"run": self.test_run.pk,
"build": self.build.pk,
"case": self.case.pk,
Expand Down Expand Up @@ -116,7 +116,7 @@ def test_create_with_non_exist_fields(self):
]
for value in values:
with self.assertRaisesRegex(XmlRPCFault, 'Select a valid choice'):
self.rpc_client.exec.TestCaseRun.create(value)
self.rpc_client.exec.TestExecution.create(value)

def test_create_with_no_perm(self):
values = {
Expand All @@ -129,14 +129,14 @@ def test_create_with_no_perm(self):
}
self.rpc_client.exec.Auth.logout()
with self.assertRaisesRegex(ProtocolError, '403 Forbidden'):
self.rpc_client.exec.TestCaseRun.create(values)
self.rpc_client.exec.TestExecution.create(values)


class TestCaseRunAddComment(XmlrpcAPIBaseTest):
class TestExecutionAddComment(XmlrpcAPIBaseTest):
"""Test TestExecution.add_comment"""

def _fixture_setup(self):
super(TestCaseRunAddComment, self)._fixture_setup()
super(TestExecutionAddComment, self)._fixture_setup()

self.case_run_1 = TestExecutionFactory()
self.case_run_2 = TestExecutionFactory()
Expand All @@ -147,7 +147,7 @@ def test_add_comment_with_int(self):


@override_settings(LANGUAGE_CODE='en-us')
class TestCaseRunAddLink(XmlrpcAPIBaseTest):
class TestExecutionAddLink(XmlrpcAPIBaseTest):
"""Test TestExecution.add_link"""

def _fixture_setup(self):
Expand All @@ -157,7 +157,7 @@ def _fixture_setup(self):

def test_attach_log_with_non_existing_id(self):
with self.assertRaisesRegex(XmlRPCFault, 'constraint fail|violates foreign key'):
self.rpc_client.exec.TestCaseRun.add_link(-5, 'A test log', 'http://example.com')
self.rpc_client.exec.TestExecution.add_link(-5, 'A test log', 'http://example.com')

def test_attach_log_with_invalid_url(self):
with self.assertRaisesRegex(XmlRPCFault, 'Enter a valid URL'):
Expand All @@ -169,7 +169,7 @@ def test_attach_log(self):
self.assertGreater(log_id, 0)


class TestCaseRunRemoveLink(XmlrpcAPIBaseTest):
class TestExecutionRemoveLink(XmlrpcAPIBaseTest):

def _fixture_setup(self):
super()._fixture_setup()
Expand All @@ -188,13 +188,13 @@ def setUp(self):
self.link = self.case_run.links()[0]

def test_doesnt_raise_with_non_existing_id(self):
self.rpc_client.exec.TestCaseRun.remove_link(-9, self.link.pk)
self.rpc_client.exec.TestExecution.remove_link(-9, self.link.pk)
links = self.case_run.links()
self.assertEqual(1, links.count())
self.assertEqual(self.link.pk, links[0].pk)

def test_detach_log_with_non_exist_log(self):
self.rpc_client.exec.TestCaseRun.remove_link(self.case_run.pk, 999999999)
self.rpc_client.exec.TestExecution.remove_link(self.case_run.pk, 999999999)
links = self.case_run.links()
self.assertEqual(1, links.count())
self.assertEqual(self.link.pk, links[0].pk)
Expand All @@ -204,7 +204,7 @@ def test_detach_log(self):
self.assertEqual([], list(self.case_run.links()))


class TestCaseRunFilter(XmlrpcAPIBaseTest):
class TestExecutionFilter(XmlrpcAPIBaseTest):

def _fixture_setup(self):
super()._fixture_setup()
Expand All @@ -216,7 +216,7 @@ def _fixture_setup(self):
status=self.status_idle)

def test_with_non_exist_id(self):
found = self.rpc_client.exec.TestCaseRun.filter({'pk': -1})
found = self.rpc_client.exec.TestExecution.filter({'pk': -1})
self.assertEqual(0, len(found))

def test_filter_by_id(self):
Expand All @@ -231,21 +231,21 @@ def test_filter_by_id(self):
self.assertEqual(tcr['status_id'], self.status_idle.pk)


class TestCaseRunGetLinks(XmlrpcAPIBaseTest):
class TestExecutionGetLinks(XmlrpcAPIBaseTest):

def _fixture_setup(self):
super()._fixture_setup()

self.case_run_1 = TestExecutionFactory()
self.case_run_2 = TestExecutionFactory()

self.rpc_client.exec.TestCaseRun.add_link(
self.rpc_client.exec.TestExecution.add_link(
self.case_run_1.pk,
"Test logs",
"http://www.google.com")

def test_get_links_with_non_exist_id(self):
result = self.rpc_client.exec.TestCaseRun.get_links(-9)
result = self.rpc_client.exec.TestExecution.get_links(-9)
self.assertEqual([], result)

def test_get_empty_logs(self):
Expand All @@ -264,7 +264,7 @@ def test_get_links(self):


@override_settings(LANGUAGE_CODE='en-us')
class TestCaseRunUpdate(XmlrpcAPIBaseTest):
class TestExecutionUpdate(XmlrpcAPIBaseTest):

def _fixture_setup(self):
super()._fixture_setup()
Expand All @@ -276,7 +276,7 @@ def _fixture_setup(self):
self.status_running = TestExecutionStatus.objects.get(name='RUNNING')

def test_update_with_single_caserun(self):
tcr = self.rpc_client.exec.TestCaseRun.update(self.case_run_1.pk, {
tcr = self.rpc_client.exec.TestExecution.update(self.case_run_1.pk, {
"build": self.build.pk,
"assignee": self.user.pk,
"status": self.status_running.pk,
Expand All @@ -289,11 +289,11 @@ def test_update_with_single_caserun(self):

def test_update_with_non_existing_build(self):
with self.assertRaisesRegex(XmlRPCFault, 'Select a valid choice'):
self.rpc_client.exec.TestCaseRun.update(self.case_run_1.pk, {"build": 1111111})
self.rpc_client.exec.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'):
self.rpc_client.exec.TestCaseRun.update(self.case_run_1.pk, {"assignee": 1111111})
self.rpc_client.exec.TestExecution.update(self.case_run_1.pk, {"assignee": 1111111})

def test_update_with_non_existing_status(self):
with self.assertRaisesRegex(XmlRPCFault, 'Select a valid choice'):
Expand Down

0 comments on commit aa0a340

Please sign in to comment.