1+ #! /usr/bin/python
2+ # -*- coding: UTF-8 -*-
3+
4+ # Copyright 2012 Luiko Czub, TestLink-API-Python-client developers
5+ #
6+ # Licensed under ???
7+ # see https://github.com/orenault/TestLink-API-Python-client/issues/4
8+
9+ # this test works WITHOUT an online TestLink Server
10+ # no calls are send to a TestLink Server
11+
12+ import unittest
13+ from testlink import TestLinkAPIClient , TestLinkHelper
14+
15+ # scenario_a includes response from a testlink 1.9.3 server
16+ SCENARIO_A = {'getProjects' : [
17+ {'opt' : {'requirementsEnabled' : 0 , 'testPriorityEnabled' : 1 ,
18+ 'automationEnabled' : 1 , 'inventoryEnabled' : 0 },
19+ 'prefix' : 'NPROAPI' , 'name' : 'NEW_PROJECT_API' , 'color' : '' ,
20+ 'notes' : 'This is a Project created with the API' ,
21+ 'option_priority' : '0' ,
22+ 'options' : 'O:8:"stdClass":4:{s:19:"requirementsEnabled";i:0;s:19:"testPriorityEnabled";i:1;s:17:"automationEnabled";i:1;s:16:"inventoryEnabled";i:0;}' ,
23+ 'tc_counter' : '2' , 'option_reqs' : '0' , 'active' : '1' ,
24+ 'is_public' : '1' , 'id' : '21' , 'option_automation' : '0' },
25+ {'opt' : {'requirementsEnabled' : 1 , 'testPriorityEnabled' : 1 ,
26+ 'automationEnabled' : 1 , 'inventoryEnabled' : 1 },
27+ 'prefix' : 'TP' , 'name' : 'TestProject' , 'color' : '' ,
28+ 'notes' : '<p>Initiales TestProject, um TestLink kennen zu lernen</p>' ,
29+ 'option_priority' : '0' ,
30+ 'options' : 'O:8:"stdClass":4:{s:19:"requirementsEnabled";i:1;s:19:"testPriorityEnabled";i:1;s:17:"automationEnabled";i:1;s:16:"inventoryEnabled";i:1;}' ,
31+ 'tc_counter' : '0' , 'option_reqs' : '0' , 'active' : '1' ,
32+ 'is_public' : '1' , 'id' : '1' , 'option_automation' : '0' }],
33+ 'getProjectTestPlans' : {
34+ '21' : [{'name' : 'TestPlan_API' ,
35+ 'notes' : 'New TestPlan created with the API' ,
36+ 'active' : '1' , 'is_public' : '1' ,
37+ 'testproject_id' : '21' , 'id' : '22' }] ,
38+ '1' : '' },
39+ 'getFirstLevelTestSuitesForTestProject' : {
40+ '21' : [{'node_type_id' : '2' , 'name' : 'A - First Level' ,
41+ 'parent_id' : '21' , 'node_order' : '0' ,
42+ 'node_table' : 'testsuites' , 'id' : '23' },
43+ {'node_type_id' : '2' , 'name' : 'B - First Level' ,
44+ 'parent_id' : '21' , 'node_order' : '0' ,
45+ 'node_table' : 'testsuites' , 'id' : '24' }],
46+ '1' : [{'message' : '(getFirstLevelTestSuitesForTestProject) - Test Project (TestProject) is empty.' ,
47+ 'code' : 7008 }] },
48+ 'getTestSuitesForTestPlan' : {'22' : '' },
49+ 'getTestCasesForTestPlan' : {'22' : '' },
50+ # TL(1.9.3)->getTestSuitesForTestSuite really returns {...} and not [{....}] !!!
51+ 'getTestSuitesForTestSuite' : {
52+ '23' : {'node_type_id' : '2' , 'name' : 'AA - Second Level' ,
53+ 'parent_id' : '23' , 'node_order' : '0' ,
54+ 'details' : 'Details of the Test Suite AA' , 'id' : '25' },
55+ '24' : '' },
56+ 'getTestCasesForTestSuite' : {
57+ '23' : [{'node_type_id' : '3' , 'tcversion_id' : '25' ,
58+ 'name' : 'TESTCASE_AA' , 'parent_id' : '25' ,
59+ 'node_order' : '0' , 'node_table' : 'testcases' ,
60+ 'external_id' : 'NPROAPI-1' , 'id' : '26' }],
61+ '24' : [{'node_type_id' : '3' , 'tcversion_id' : '24' ,
62+ 'name' : 'TESTCASE_B' , 'parent_id' : '24' ,
63+ 'node_order' : '0' , 'node_table' : 'testcases' ,
64+ 'external_id' : 'NPROAPI-2' , 'id' : '33' }],
65+ '25' : [{'node_type_id' : '3' , 'tcversion_id' : '25' ,
66+ 'name' : 'TESTCASE_AA' , 'parent_id' : '25' ,
67+ 'node_order' : '0' , 'node_table' : 'testcases' ,
68+ 'external_id' : 'NPROAPI-1' , 'id' : '26' }]
69+ },
70+ 'getTestPlanPlatforms' : {
71+ '22' : [{'message' : 'Test plan (name:TestPlan_API) has no platforms linked' ,
72+ 'code' : 3041 }]},
73+ 'getBuildsForTestPlan' : {'22' : '' }
74+ }
75+
76+ class DummyAPIClient (TestLinkAPIClient ):
77+ """ Dummy for Simulation TestLinkAPICLient.
78+ Overrides _callServer() Method to return test scenarios
79+ """
80+
81+ def __init__ (self , server_url , devKey ):
82+ super (DummyAPIClient , self ).__init__ (server_url , devKey )
83+ self .scenario_data = {}
84+
85+ def loadScenario (self , a_scenario ):
86+ self .scenario_data = a_scenario
87+
88+ def _callServer (self , methodAPI , argsAPI = None ):
89+ data = self .scenario_data [methodAPI ]
90+ response = None
91+ if methodAPI in ['getProjectTestPlans' ,
92+ 'getFirstLevelTestSuitesForTestProject' ]:
93+ response = data [argsAPI ['testprojectid' ]]
94+ elif methodAPI in ['getTestSuitesForTestPlan' ,
95+ 'getTestCasesForTestPlan' , 'getTestPlanPlatforms' ,
96+ 'getBuildsForTestPlan' ]:
97+ response = data [argsAPI ['testplanid' ]]
98+ elif methodAPI in ['getTestCasesForTestSuite' ,
99+ 'getTestSuitesForTestSuite' ]:
100+ response = data [argsAPI ['testsuiteid' ]]
101+ else :
102+ response = data
103+ return response
104+
105+
106+ class TestLinkAPIOfflineTestCase (unittest .TestCase ):
107+ """ TestCases for TestLinkAPIClient - does not interacts with a TestLink Server.
108+ works with DummyAPIClientm which returns special test data
109+ """
110+
111+ def setUp (self ):
112+ self .api = TestLinkHelper ().connect (DummyAPIClient )
113+
114+ # def tearDown(self):
115+ # pass
116+
117+
118+ def test_countProjects (self ):
119+ self .api .loadScenario (SCENARIO_A )
120+ response = self .api .countProjects ()
121+ self .assertEqual (2 , response )
122+
123+ def test_countTestPlans (self ):
124+ self .api .loadScenario (SCENARIO_A )
125+ response = self .api .countTestPlans ()
126+ self .assertEqual (1 , response )
127+
128+ def test_countTestSuites (self ):
129+ self .api .loadScenario (SCENARIO_A )
130+ response = self .api .countTestSuites ()
131+ self .assertEqual (0 , response )
132+
133+ def test_countTestCasesTP (self ):
134+ self .api .loadScenario (SCENARIO_A )
135+ response = self .api .countTestCasesTP ()
136+ self .assertEqual (0 , response )
137+
138+ def test_countTestCasesTS (self ):
139+ self .api .loadScenario (SCENARIO_A )
140+ response = self .api .countTestCasesTS ()
141+ self .assertEqual (0 , response )
142+
143+ def test_countPlatforms (self ):
144+ self .api .loadScenario (SCENARIO_A )
145+ response = self .api .countPlatforms ()
146+ self .assertEqual (0 , response )
147+
148+ def test_countBuilds (self ):
149+ self .api .loadScenario (SCENARIO_A )
150+ response = self .api .countBuilds ()
151+ self .assertEqual (0 , response )
152+
153+ def test_listProjects (self ):
154+ self .api .loadScenario (SCENARIO_A )
155+ self .api .listProjects ()
156+ # no assert check cause method returns nothing
157+ # 'just' prints to stdout
158+
159+ def test_getProjectIDByName (self ):
160+ self .api .loadScenario (SCENARIO_A )
161+ response = self .api .getProjectIDByName ('NEW_PROJECT_API' )
162+ self .assertEqual ('21' , response )
163+ response = self .api .getProjectIDByName ('UNKNOWN_PROJECT' )
164+ self .assertEqual (- 1 , response )
165+
166+ if __name__ == "__main__" :
167+ #import sys;sys.argv = ['', 'Test.testName']
168+ unittest .main ()
0 commit comments