@@ -126,16 +126,19 @@ def getProjectTestPlans(self, testprojectid):
126
126
'testprojectid' :str (testprojectid )}
127
127
return self .server .tl .getProjectTestPlans (argsAPI )
128
128
129
- def getTestCase (self , testcaseid = None , testcaseexternalid = None ):
129
+ def getTestCase (self , testcaseid = None , testcaseexternalid = None , version = None ):
130
130
""" getTestCase :
131
- Gets test case specification using external or internal id
131
+ Gets test case specification using external or internal id and its verion
132
+ (if version is not specified, the higher version is used)
132
133
"""
133
134
134
135
argsAPI = {'devKey' : self .devKey }
135
136
if testcaseexternalid is not None :
136
137
argsAPI .update ({'testcaseexternalid' : str (testcaseexternalid )})
137
138
elif testcaseid is not None :
138
139
argsAPI .update ({'testcaseid' : str (testcaseid )})
140
+ if version is not None :
141
+ argsAPI .update ({'version' : str (version )})
139
142
140
143
return self .server .tl .getTestCase (argsAPI )
141
144
@@ -558,15 +561,45 @@ def getProjectIDByName(self, projectName):
558
561
return result
559
562
560
563
def __str__ (self ):
561
- message = """
562
- TestLinkAPIClient - version %s
563
- @author: Olivier Renault (admin@sqaopen.net)
564
- @author: kereval.com
565
- @author: Patrick Dassier
566
-
567
- """
564
+ message = "TestLinkAPIClient - version %s"
568
565
return message % self .__VERSION__
569
566
567
+ class TestCase (object ):
568
+ """Test case object"""
569
+
570
+ def __init__ (self ):
571
+ self .id = ''
572
+ self .extid = ''
573
+ self .version = ''
574
+ self .is_open = False
575
+ self .is_active = False
576
+ self .name = ''
577
+ self .summary = ''
578
+ self .preconditions = ''
579
+ # Must be 'auto' or 'manual'
580
+ self .execution_type = ''
581
+ self .testsuite = TestSuite ()
582
+
583
+ class TestSuite (object ):
584
+ """TestSuite object"""
585
+ def __init__ (self ):
586
+ self .id = ''
587
+ self .details = ''
588
+ self .name = ''
589
+ self .node_order = ''
590
+ self .node_type_id = ''
591
+ self .parent = None
592
+ self .is_root = False
593
+ self .project = None
594
+
595
+ class TestProject (object ):
596
+ """TestProject object"""
597
+ def __init__ (self ):
598
+ self .id = ''
599
+ self .is_active = False
600
+ self .is_public = False
601
+ self .name = ''
602
+
570
603
class TestLink (TestLinkAPIClient ):
571
604
"""
572
605
TestLink API library
@@ -580,6 +613,96 @@ def __init__(self, server_url, key):
580
613
"""
581
614
super (TestLink , self ).__init__ (server_url , key )
582
615
616
+ def getTestProjectByID (self , testprojectid ):
617
+ """
618
+ Return a project according to its id
619
+ A TestLinkErrors is raised if id is not found
620
+ """
621
+ # First get all projects
622
+ projects = self .getProjects ()
623
+
624
+ for p in projects :
625
+ if p ['id' ] == testprojectid :
626
+ prj = TestProject ()
627
+ prj .id = p ['id' ]
628
+ prj .is_active = p ['active' ] == '1'
629
+ prj .is_public = p ['is_public' ] == '1'
630
+ prj .name = p ['name' ]
631
+ return prj
632
+ # No project found, raise an error
633
+ raise TestLinkErrors ("(getProjectByID) - Project with id %s is not found" % testprojectid )
634
+
635
+
636
+ def getTestSuiteByID (self , testsuiteid ):
637
+ """docstring for getTestSuiteByID"""
638
+ result = super (TestLink , self ).getTestSuiteByID (testsuiteid )
639
+
640
+ # Check error
641
+ if type (result ) == list and 'message' in result [0 ]:
642
+ raise TestLinkErrors (result [0 ]['message' ])
643
+
644
+ ts = TestSuite ()
645
+ ts .id = result ['id' ]
646
+ ts .details = result ['details' ]
647
+ ts .name = result ['name' ]
648
+ ts .node_order = result ['node_order' ]
649
+ ts .node_type_id = result ['node_type_id' ]
650
+
651
+ # Is parent_id an id of a test suite ?
652
+ try :
653
+ ts_parent = self .getTestSuiteByID (result ['parent_id' ])
654
+ except TestLinkErrors :
655
+ # Parent is not a test suite, so it is a project
656
+ ts .project = self .getTestProjectByID (result ['parent_id' ])
657
+ ts .parent = None
658
+ ts .is_root = True
659
+ else :
660
+ # Parent is a test suite
661
+ # register it
662
+ ts .parent = ts_parent
663
+ ts .is_root = False
664
+
665
+ # Also register the project
666
+ # find it in parent object
667
+ ts .project = ts .parent .project
668
+
669
+ return ts
670
+
671
+ def getTestCase (self , testcaseid = None , testcaseexternalid = None , version = None ):
672
+ """
673
+ Return the TestCase object according to parameters
674
+ """
675
+ # Check parameters
676
+ if testcaseid is None and testcaseexternalid is None :
677
+ raise TestLinkErrors ("(getTestCase) - You must specified 'testcaseid' or 'testcaseexternalid'" )
678
+
679
+ result = super (TestLink , self ).getTestCase (testcaseid , testcaseexternalid , version )
680
+
681
+ # Check error
682
+ if 'message' in result [0 ]:
683
+ raise TestLinkErrors (result [0 ]['message' ])
684
+
685
+
686
+ # Create TestCase object
687
+ tc = TestCase ()
688
+ tc .id = result [0 ]['testcase_id' ]
689
+ tc .extid = result [0 ]['full_tc_external_id' ]
690
+ tc .version = result [0 ]['version' ]
691
+ tc .is_active = result [0 ]['active' ] == '1'
692
+ tc .is_open = result [0 ]['is_open' ] == '1'
693
+ tc .name = result [0 ]['name' ]
694
+ tc .summary = result [0 ]['summary' ]
695
+ tc .preconditions = result [0 ]['preconditions' ]
696
+ if result [0 ]['execution_type' ] == '2' :
697
+ #Automatic test
698
+ tc .execution_type = 'auto'
699
+ else :
700
+ # Manual testProjectName
701
+ tc .execution_type = 'manual'
702
+ tc .testsuite = self .getTestSuiteByID (result [0 ]['testsuite_id' ])
703
+
704
+ return tc
705
+
583
706
def getTestCaseIDByName (self , testCaseName , testSuiteName , testProjectName ):
584
707
"""
585
708
Find a test case by its name, by its suite and its project
@@ -600,20 +723,6 @@ def getTestCaseIDByName(self, testCaseName, testSuiteName, testProjectName):
600
723
def getTestCasesForTestPlan (self , testProjectName , testPlanName ):
601
724
"""
602
725
Return a list of tests case object of testProjectName project, for the selected test plan
603
- The return list is a list of the following dict:
604
- {'tcase_id': test case id
605
- 'platform_id': ?
606
- 'tcversion_id': another internal id
607
- 'tc_id': same as tcase_di
608
- 'execution_type': ??
609
- 'feature_id': ??
610
- 'version': test case version
611
- 'full_external_id': the external id (as shown in the testlink interface: <name>-<unique number>
612
- 'external_id': just the nubmer of the full_external_id
613
- 'plateform_name': ??
614
- 'execution_order': test case priority
615
- 'exec_status': 'p' for pass, 'f' for failed, 'b' for blocked', 'n' for not run
616
- }
617
726
"""
618
727
619
728
# Get test plan ID
@@ -624,37 +733,36 @@ def getTestCasesForTestPlan(self, testProjectName, testPlanName):
624
733
625
734
ret_value = []
626
735
for k in results .keys ():
627
- ret_value .append (results [k ][0 ])
736
+ # Get test case object associated of return test case id
737
+ # and append it to test case list
738
+ ret_value .append (self .getTestCase (testcaseid = k ))
628
739
629
740
return ret_value
630
741
631
- def getTestCaseCustomFieldDesignValue (self , customFieldName , testProjectName , testCaseObject ):
742
+ def getTestCaseCustomFieldDesignValue (self , customFieldName , testCaseObject ):
632
743
"""
633
744
Return custom fields value for the specified test case object
634
- Test case object is an object return by 'getTestCaseByExtID' method
635
- testProjectName is the name of test project (test case must be a test case of
636
- the given test project name
637
- Nota: test case version used is the last test case version
745
+ Test case object is an object return by 'getTestCase' method
638
746
A TestLinkErrors is raised is case of problem
639
747
"""
640
748
641
- extid = testCaseObject [ 'full_external_id' ]
642
- version = testCaseObject [ ' version' ]
643
- projectid = self . getProjectIDByName ( testProjectName )
749
+ extid = testCaseObject . extid
750
+ version = testCaseObject . version
751
+ projectid = testCaseObject . testsuite . project . id
644
752
645
753
results = super (TestLink , self ).getTestCaseCustomFieldDesignValue (extid , version , projectid , customFieldName )
646
754
647
755
return results
648
756
649
- def getProjectIDByName (self , testProjectName ):
650
- """ Return project id
757
+ def getTestProjectByName (self , testProjectName ):
758
+ """ Return project object correcponding to the testProjectName name
651
759
or raise a TestLinkErrors if project name is not found
652
760
"""
653
- results = super ( TestLink , self ) .getProjectIDByName (testProjectName )
654
- if results == - 1 :
655
- raise TestLinkErrors ("(getProjectIDByName ) - Project %s is not found" % testProjectName )
761
+ prj_id = self .getProjectIDByName (testProjectName )
762
+ if prj_id == - 1 :
763
+ raise TestLinkErrors ("(getProjectByName ) - Project %s is not found" % testProjectName )
656
764
else :
657
- return results
765
+ return self . getTestProjectByID ( prj_id )
658
766
659
767
def reportResult (self , testResult , testCaseName , testSuiteName , testNotes = "" , ** kwargs ):
660
768
"""
@@ -768,12 +876,8 @@ def getBuildByName(self, testProjectName, testPlanName, buildName):
768
876
769
877
def getTestCaseByExtID (self , testCaseExternalID ):
770
878
"""Return test case by its external ID
771
- Raise an error if external ID is not found"""
772
- results = self .getTestCase (testcaseexternalid = testCaseExternalID )
773
-
774
- if 'message' in results [0 ]:
775
- raise TestLinkErrors (results [0 ]['message' ])
776
- return results [0 ]
879
+ Error are managed by getTestCase method"""
880
+ return self .getTestCase (testcaseexternalid = testCaseExternalID )
777
881
778
882
class TestEngine (object ):
779
883
"""This class must be derived to implement an automatic test engine"""
0 commit comments