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 requires an online TestLink Server, which connection parameters
10
+ # are defined in environment variables
11
+ # TESTLINK_API_PYTHON_DEVKEY and TESTLINK_API_PYTHON_DEVKEY
12
+
13
+ import unittest
14
+ from testlink import TestLinkAPIClient , TestLinkHelper
15
+ from testlink import testlinkerrors
16
+
17
+
18
+ class TestLinkAPIcallServerTestCase (unittest .TestCase ):
19
+ """ TestCases for TestLinkAPICleint._callServer() """
20
+
21
+
22
+ def test_callServer_noArgs (self ):
23
+ """ test _callServer() - calling method with no args """
24
+
25
+ client = TestLinkHelper ().connect (TestLinkAPIClient )
26
+ response = client ._callServer ('sayHello' )
27
+ self .assertEqual ('Hello!' , response )
28
+
29
+ def test_callServer_withArgs (self ):
30
+ """ test _callServer() - calling method with args """
31
+
32
+ client = TestLinkHelper ().connect (TestLinkAPIClient )
33
+ response = client ._callServer ('repeat' , {'str' : 'some arg' })
34
+ self .assertEqual ('You said: some arg' , response )
35
+
36
+ def test_callServer_ProtocollError (self ):
37
+ """ test _callServer() - Server raises ProtocollError """
38
+
39
+ server_url = TestLinkHelper ()._server_url
40
+ bad_server_url = server_url .split ('xmlrpc.php' )[0 ]
41
+ client = TestLinkHelper (bad_server_url ).connect (TestLinkAPIClient )
42
+ def a_func (api_client ): api_client ._callServer ('sayHello' )
43
+ self .assertRaises (testlinkerrors .TLConnectionError , a_func , client )
44
+
45
+ def test_callServer_socketError (self ):
46
+ """ test _callServer() - Server raises a socket Error (IOError) """
47
+
48
+ bad_server_url = 'http://111.222.333.4/testlink/lib/api/xmlrpc.php'
49
+ client = TestLinkHelper (bad_server_url ).connect (TestLinkAPIClient )
50
+ def a_func (api_client ): api_client ._callServer ('sayHello' )
51
+ self .assertRaises (testlinkerrors .TLConnectionError , a_func , client )
52
+
53
+ def test_callServer_FaultError (self ):
54
+ """ test _callServer() - Server raises Fault Error """
55
+
56
+ client = TestLinkHelper ().connect (TestLinkAPIClient )
57
+ def a_func (api_client ): api_client ._callServer ('sayGoodBye' )
58
+ self .assertRaises (testlinkerrors .TLAPIError , a_func , client )
59
+
60
+ if __name__ == "__main__" :
61
+ #import sys;sys.argv = ['', 'Test.testName']
62
+ unittest .main ()
0 commit comments