Changes between Initial Version and Version 1 of TestManagerForTracPluginRPCApi


Ignore:
Timestamp:
Jan 20, 2011, 4:40:42 PM (13 years ago)
Author:
Roberto Longobardi
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TestManagerForTracPluginRPCApi

    v1 v1  
     1= Test Manager for Trac Plugin - The XML-RPC API =
     2
     3[[BR]]
     4The [wiki:TestManagerForTracPlugin TestManager plugin] can be used programmatically to create and manage Test Catalogs, Test Cases and Test Plans, and to set the test execution verdicts of Test Cases in a plan.
     5
     6This page describes the '''XML-RPC API''', but there are alternatives:
     7
     8 * A '''HTTP RESTful''' API, allowing you to remotely control your test artifacts by means of simple HTTP GET requests,
     9 * A '''Python''' API, allowing for a fine-grained control over any artifact, managing their life-cycle, listening to events, reacting to status changes and workflow transitions.
     10
     11The Test Manager RPC API leverages the [wiki:XmlRpcPlugin XmlRpcPlugin], which must be installed in Trac for you to be able to use the following API.
     12
     13[[BR]]
     14== The exported functions ==
     15
     16[[BR]]'''createTestCatalog'''(self, req, parent_catalog_id, title, description)[[BR]]
     17        Creates a new test catalog, in the parent catalog specified,
     18        with the specified title and description.
     19        To create a root catalog, specify '' as the parent catalog.
     20        Returns the generated object ID, or '-1' if an error occurs.
     21
     22[[BR]]'''createTestCase'''(self, req, catalog_id, title, description)[[BR]]
     23        Creates a new test case, in the catalog specified, with the
     24        specified title and description.
     25        Returns the generated object ID, or '-1' if an error occurs.
     26       
     27[[BR]]'''createTestPlan'''(self, req, catalog_id, name)[[BR]]
     28        Creates a new test plan, on the catalog specified, with the
     29        specified name.
     30        Returns the generated object ID, or '-1' if an error occurs.
     31       
     32[[BR]]'''deleteTestObject'''(self, req, objtype, id)[[BR]]
     33        Deletes the test object of the specified type identified
     34        by the given id.
     35        Returns True if successful, False otherwise.
     36       
     37[[BR]]'''modifyTestObject'''(self, req, objtype, id, attributes={})[[BR]]
     38        Modifies the test object of the specified type identified
     39        by the given id.
     40        Returns True if successful, False otherwise.
     41       
     42[[BR]]'''setTestCaseStatus'''(self, req, testcase_id, plan_id, status)[[BR]]
     43        Sets the test case status.
     44        Returns True if successful, False otherwise.
     45       
     46[[BR]]'''getTestCatalog(self, req, catalog_id)[[BR]]
     47        Returns the catalog properties.
     48        The result is in the form, all strings:
     49        (wiki_page_name, title, description)
     50       
     51[[BR]]'''getTestCase'''(self, req, testcase_id, plan_id='')[[BR]]
     52        Returns the test case properties.
     53        If plan_id is provided, also the status of the test case in the
     54        plan will be returned.
     55        Each result is in the form, all strings:
     56                If plan_id is NOT provided:
     57                        (wiki_page_name, title, description)
     58                If plan_id is provided:
     59                        (wiki_page_name, title, description, status)
     60                       
     61[[BR]]'''getTestPlan'''(self, req, catalog_id, plan_id)[[BR]]
     62        Returns the test plan properties.
     63        The result is in the form, all strings:
     64        (wiki_page_name, name)
     65       
     66[[BR]]'''listSubCatalogs'''(self, req, catalog_id)[[BR]]
     67        Returns a iterator over the direct sub-catalogs of the specified
     68        catalog.
     69        Each result is in the form, all strings:
     70        (test_catalog_id, wiki_page_name, title, description)
     71       
     72[[BR]]'''listTestPlans'''(self, req, catalog_id)[[BR]]
     73        Returns a iterator over the test plans associated
     74        to the specified catalog.
     75        Each result is in the form, all strings:
     76        (testplan_id, name)
     77       
     78[[BR]]'''listTestCases'''(self, req, catalog_id, plan_id='')[[BR]]
     79        Returns a iterator over the test cases directly in the
     80        specified catalog (no sub-catalogs).
     81        If plan_id is provided, also the status of the test case in the
     82        plan will be returned.
     83        Each result is in the form, all strings:
     84                If plan_id is NOT provided:
     85                        (testcase_id, wiki_page_name, title, description)
     86                If plan_id is provided:
     87                        (testcase_id, wiki_page_name, status)
     88
     89[[BR]]
     90[[BR]]
     91== Examples ==
     92
     93This section presents a set of usage examples for this RPC API.
     94
     95Just copy this code and paste into a file with "example.py" extension, adapt the initial URL to point to your server, port and project, and run it from a command line with {{{python example.py}}}.
     96
     97{{{
     98import xmlrpclib
     99                 
     100server = xmlrpclib.ServerProxy("http://user@yourserver:port/yourproject/rpc")
     101
     102print ">> Creating test catalog"
     103root_cat = server.testmanager.createTestCatalog('', "Test Root Catalog RPC", "This is a wonderful catalog.")
     104print root_cat
     105
     106print ">> Creating sub-catalog"
     107sub_cat = server.testmanager.createTestCatalog(root_cat, "Test Sub-Catalog RPC", "This is a wonderful sub-catalog.")
     108print sub_cat
     109
     110print ">> Creating two test cases in the root catalog"
     111tc_1 = server.testmanager.createTestCase(root_cat, "Test Case 1", "This is a wonderful test case.")
     112print tc_1
     113tc_2 = server.testmanager.createTestCase(root_cat, "Test Case 2", "This is an even more wonderful test case.")
     114print tc_2
     115
     116print ">> Creating two test cases in the sub-catalog"
     117tc_3 = server.testmanager.createTestCase(sub_cat, "Test Case Sub 3", "This is a wonderful test case.")
     118print tc_3
     119tc_4 = server.testmanager.createTestCase(sub_cat, "Test Case Sub 4", "This is an even more wonderful test case.")
     120print tc_4
     121
     122print ">> Listing sub-catalogs of root test catalog"
     123for tc in server.testmanager.listSubCatalogs(root_cat):
     124    for v in tc:
     125        print v
     126
     127print ">> Listing test cases in root test catalog"
     128for tc in server.testmanager.listTestCases(root_cat):
     129    for v in tc:
     130        print v
     131
     132print ">> Creating a test plan on the root catalog"
     133tplan = server.testmanager.createTestPlan(root_cat, "Test Root Plan RPC", "This is a wonderful test plan.")
     134print tplan
     135
     136print ">> Listing test plans available on specified test catalog"
     137for tp in server.testmanager.listTestPlans('0'):
     138    for v in tp:
     139        print v
     140
     141print ">> Listing test cases for root test plan on root test catalog, with their status"
     142for tc in server.testmanager.listTestCases(root_cat, tplan):
     143    for v in tc:
     144        print v
     145
     146print ">> Getting root test catalog properties"
     147for v in server.testmanager.getTestCatalog(root_cat):
     148    print v
     149
     150print ">> Modifying root test catalog title and description"
     151print server.testmanager.modifyTestObject('testcatalog', root_cat, {'title': "Test Root Catalog Modified", 'description': "This is no more a wonderful catalog."})
     152
     153print ">> Verifying root test catalog properties has been changed"
     154for v in server.testmanager.getTestCatalog(root_cat):
     155    print v
     156
     157print ">> Getting first test case properties"
     158for v in server.testmanager.getTestCase(tc_1):
     159    print v
     160
     161print ">> Getting test plan on root catalog properties"
     162for v in server.testmanager.getTestPlan(tplan, root_cat):
     163    print v
     164
     165#
     166# These simple functions leverage the base functions to demostrate some more articulated usage.
     167#
     168
     169# Recursive function to print a whole sub-catalog and its contained test cases
     170def printSubCatalog(cat_id):
     171    for subc in server.testmanager.listSubCatalogs(cat_id):
     172        subc_id = subc[0]
     173        print subc[2]
     174        printSubCatalog(subc_id)
     175
     176    for tc in server.testmanager.listTestCases(cat_id):
     177        print tc[2]
     178
     179# Recursive function to print a whole sub-catalog and its contained test cases with status
     180def printSubPlan(cat_id, plan_id, indent):
     181    tcat = server.testmanager.getTestCatalog(cat_id)
     182    print str([' ' for i in range(indent)]) + tcat[1]
     183
     184    for subc in server.testmanager.listSubCatalogs(cat_id):
     185        subc_id = subc[0]
     186        printSubPlan(subc_id, plan_id, indent + 1)
     187
     188    for tcip in server.testmanager.listTestCases(cat_id, plan_id):
     189        tc_id = tcip[0]
     190        tc_status = tcip[2]
     191        tc = server.testmanager.getTestCase(tc_id)
     192        tc_title = tc[1]
     193        print str([' ' for i in range(indent)]) + tc_title + ": "+tc_status
     194
     195# Entry point to print a whole test plan and its contained test cases with status
     196def printPlan(cat_id, plan_id):
     197    p = server.testmanager.getTestPlan(plan_id, cat_id)
     198   
     199    print p[1]
     200
     201    printSubPlan(cat_id, plan_id, 0)
     202
     203
     204# Now, let's use the functions defined above
     205
     206print ">> Printing complete test catalog tree"
     207printSubCatalog(root_cat)
     208
     209print ">> Printing complete test plan tree"
     210printPlan(root_cat, tplan)
     211
     212print ">> Setting test case status"
     213print server.testmanager.setTestCaseStatus(tc_2, tplan, 'successful')
     214
     215print ">> Printing test case status just set"
     216for v in server.testmanager.getTestCase(tc_2, tplan):
     217    print v
     218
     219print ">> Changing test case status"
     220print server.testmanager.setTestCaseStatus(tc_2, tplan, 'failed')
     221
     222print ">> Verifying the test case status has been changed"
     223for v in server.testmanager.getTestCase(tc_2, tplan):
     224    print v
     225
     226}}}