kiwitcms / Kiwi

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

Run time status value. #275

Closed puncoder closed 6 years ago

puncoder commented 6 years ago

Well, this is not a problem, but more of like a question. I am very new to this, and i dont know how can i fetch a run time status value in my code ( so i can add a function if the case is passed, or failed , or error).

I am able to get case_id, case_status, author etc from tcms/testcases/models.py file. But I am not able to get run time status changed values. Please help me.

atodorov commented 6 years ago

What is "run time status changed values" ? Please use the proper terminology otherwise I can't figure out what you want to do.

Do you mean to get the execution status of a TestRun ? E.g. Running or Finished ?

puncoder commented 6 years ago

Sorry my bad. When I run a test case, there are 8 different status it can achieve "RUNNING", "PASSED", "WAIVED" ,"FAILED" etc. Is there a way i can get the running status of the test case inside the code ( any specific file and function inside it ) . I tried to fetch from tcms/testcases/models.py >> self.case_status , but it gives "CONFIRMED" .

atodorov commented 6 years ago

When a TestCase is being executed the results are recorded into a TestCaseRun object. See http://kiwitcms.readthedocs.io/en/latest/guide/introduction.html#data-organization-within-kiwi-tcms

If this answers your question please close this issue.

puncoder commented 6 years ago

Thank you for your quick help. Can I ask one more question in this thread? Is there a way i can change the running status of a testcase from outside? for example, I am running a test case using Jenkins, and as soon it shows passed, i should turn my status of kiwi test case as "Passed". Sincere apology for asking too much. But since I am assigned to this task and there is no much help on google for it.

atodorov commented 6 years ago

You need to use the tcms-api method TestCaseRunStatus.update() and pass case_run_status_id=XX as an update value in the dictionary. NOTE that XX is the numerical ID of the status in the database.

If you're not using Python as a programming language check the TestCaseRun.update XML-RPC call. Again same field for status ID.

All of these are in the docs, aren't they ?

puncoder commented 6 years ago

Thank you for the Help. I was actually afraid of using API because it will need to create XML-RPC, rather I thought to change inside code while running as localhost to change the status values, so i never went for API. Guess I need to rethink of it. Thank you for your time.

okainov commented 6 years ago

Not sure what you mean by "create XML-RPC", you can just use following bit of code as a baseline and it should work flawlessly:

kiwi_api.py:

from xmlrpc.client import ServerProxy, SafeTransport, Transport

#piece of code about CookieTransport from https://stackoverflow.com/questions/25876503/how-to-retain-cookies-for-xmlrpc-client-in-python-3/47291771#47291771

def connect_to_local():
    server = ServerProxy("http://127.0.0.1:8000/xml-rpc/", transport=CookiesTransport())
    session_id = server.Auth.login('api_login', 'api_password')
    return server

def connect_to_prod():
    server = ServerProxy("https://<prod_address>:8081/xml-rpc/",
    transport=CookiesSafeTransport(context=ssl._create_unverified_context()))
    session_id = server.Auth.login('api_login', 'api_password')
    return server

if __name__=='__main__':    
    server = kiwi.connect_to_local()
    print(server.TestCase.get(1))
    server.TestCase.update(1, {'summary': 'New name for test case'})
    #and so on...
puncoder commented 6 years ago

Hi , Thanks both of you. I was actually doing it all in wrong way. I started to read API in more deep and I got the solution that how i can fetch the status and even change it. Thanks a lot for time.