kiwitcms / Kiwi

open source test management system with over 2 million downloads!
https://kiwitcms.org
GNU General Public License v2.0
986 stars 295 forks source link

Automated tests for missing coverage in tcms.rpc.api.testexecutionstatus #1626

Closed kiwitcms-bot closed 4 years ago

kiwitcms-bot commented 4 years ago

Kiwi TCMS needs additional automated test(s) as mentioned in subject.

Definition of Done:

Hints:

This issue is part of Kiwi TCMS open source bounty program. For more information see the link(s) in bounty-program milestone

awalvie commented 4 years ago

Hey! I'd like to work on this issue if that's alright.

atodorov commented 4 years ago

@awalvie are you an MLH fellow ?

awalvie commented 4 years ago

Yes! I am a MLH Fellow.

atodorov commented 4 years ago

IMPORTANT: This issue/bounty has been assigned to an MLH fellow who is currently working on it, see here. Pull requests towards the same issue from other contributors will not be considered at this time. Please pick something else to work on!

awalvie commented 4 years ago

I can't seem to figure out what the query that is supposed to be passed to the filter function looks like. For now I'm making the query like so

execution_statuses = self.rpc_client.TestExecutionStatus.filter({'id': (self.execution_status_1.id, self.execution_status_2.id)})

Where both execution_status_1 and execution_status_2 are objects made using TestExecutionStatus(), but I'm getting the following error.

======================================================================
ERROR: test_filter_statuses (tcms.rpc.tests.test_testexecutionstatus.TestFilter)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/awalvie/projects/mlh/Kiwi/tcms/rpc/tests/test_testexecutionstatus.py", line 15, in test_filter_statuses
    execution_statuses = self.rpc_client.TestExecutionStatus.filter({'id': (self.execution_status_1.id, self.execution_status_2.id)})
  File "/usr/lib/python3.8/xmlrpc/client.py", line 1109, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib/python3.8/xmlrpc/client.py", line 1450, in __request
    response = self.__transport.request(
  File "/usr/lib/python3.8/xmlrpc/client.py", line 1153, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/usr/lib/python3.8/xmlrpc/client.py", line 1169, in single_request
    return self.parse_response(resp)
  File "/home/awalvie/.virtualenvs/kiwi/lib/python3.8/site-packages/tcms_api/xmlrpc.py", line 37, in parse_response
    return super().parse_response(response)
  File "/usr/lib/python3.8/xmlrpc/client.py", line 1341, in parse_response
    return u.close()
  File "/usr/lib/python3.8/xmlrpc/client.py", line 655, in close
    raise Fault(**self._stack[0])
xmlrpc.client.Fault: <Fault -32602: "Invalid parameters: Field 'id' expected a number but got [None, None].">
awalvie commented 4 years ago

for reference, this is what the full test looks like

# -*- coding: utf-8 -*-
# pylint: disable=attribute-defined-outside-init, invalid-name, objects-update-used
from tcms.testruns.models import TestExecutionStatus
from tcms.rpc.tests.utils import APITestCase

class TestFilter(APITestCase):

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

        self.execution_status_1 = TestExecutionStatus()
        self.execution_status_2 = TestExecutionStatus()

    def test_filter_statuses(self):
        execution_statuses = self.rpc_client.TestExecutionStatus.filter({'id': (self.execution_status_1.id, self.execution_status_2.id)})
        execution_status = execution_statuses[0]
        self.assertEqual(self.execution_status_1['name'], execution_status['name'])
asankov commented 4 years ago

@awalvie Any valid Django query can be passed to the filter method. See the docs - https://docs.djangoproject.com/en/3.1/topics/db/queries/

Also, Github issues are not a good medium to discuss code. Next time open a Draft PR.

atodorov commented 4 years ago

@awalvie also see https://kiwitcms.readthedocs.io/en/latest/modules/tcms.rpc.api.html#module-tcms.rpc.api and https://kiwitcms.readthedocs.io/en/latest/db.html and the individual models to figure out what fields are available

In your case the 'id' field accepts a numeric value not a tuple. If you want to filter by 2 values you need to use the in field lookup, see https://docs.djangoproject.com/en/3.0/ref/models/querysets/#field-lookups

awalvie commented 4 years ago

Got it, I'll open up a draft PR