Ejemplo n.º 1
0
 def __init__(self):
     tlk_helper = TestLinkHelper()
     try:
         self.testlink = tlk_helper.connect(TestlinkAPIClient)  # 连接TestLink
     except Exception as e:
         logger.error('连接testlink失败:%s' % e)
         exit()
def main(config_module=None):
    from testlinktool.main.config import TESTLINK_SERVER, TESTLINK_PROJECT_ID, TESTLINK_PROJECT_NAME,\
                                         TESTLINK_API_KEY, CUSTOM_FIELD_NAME_LIST, UI_TEST_KEYWORD

    # use configuration
    try:
        if config_module is not None:
            TESTLINK_SERVER = getattr(config_module, "TESTLINK_SERVER")
            TESTLINK_PROJECT_ID = getattr(config_module, "TESTLINK_PROJECT_ID")
            TESTLINK_PROJECT_NAME = getattr(config_module, "TESTLINK_PROJECT_NAME")
            TESTLINK_API_KEY = getattr(config_module, "TESTLINK_API_KEY")
            CUSTOM_FIELD_NAME_LIST = getattr(config_module, "CUSTOM_FIELD_NAME_LIST")
            UI_TEST_KEYWORD = getattr(config_module, "UI_TEST_KEYWORD")
        elif exists(join(getcwd(), 'config.json')):
            with open(join(getcwd(), 'config.json')) as j_file:
                conf_dic = json_read_file(j_file)
                TESTLINK_SERVER = conf_dic["TESTLINK_SERVER"]
                TESTLINK_PROJECT_ID = conf_dic["TESTLINK_PROJECT_ID"]
                TESTLINK_PROJECT_NAME = conf_dic["TESTLINK_PROJECT_NAME"]
                TESTLINK_API_KEY = conf_dic["TESTLINK_API_KEY"]
                CUSTOM_FIELD_NAME_LIST = conf_dic["CUSTOM_FIELD_NAME_LIST"]
                UI_TEST_KEYWORD = conf_dic["UI_TEST_KEYWORD"]
    except ImportError:
        print("Warning we are using default parameters")
    parser = argparse.ArgumentParser(description='')
    group = parser.add_argument_group()
    group.add_argument('-d', '--test-dir', dest='dest_dir',
                       help="The directory path where generated tests will be sent (defaults to 'tests')",
                       default="tests")
    group.add_argument('-p', '--plan', dest='plan', help="the test plan", default=None, required=True)
    group.add_argument('-a', '--download-all', dest='download_all', default=False, action="store_true",
                       help="if used will download all tests, even those which are already coded")
    group.add_argument('-v', '--verbose', dest='verbose', default=False, action="store_true",
                       help="verbosity")
    
    args = parser.parse_args()

    tl_helper = TestLinkHelper(TESTLINK_SERVER, TESTLINK_API_KEY)
    testlink_client = tl_helper.connect(TestlinkAPIClient)
    plan_id = int(testlink_client.getTestPlanByName(TESTLINK_PROJECT_NAME, args.plan)[0]['id'])
    suites = testlink_client.getTestSuitesForTestPlan(plan_id)
    # build a id/name relation dictionary
    suites_tc_dic = {
        suite["id"]: suite["name"] for suite in suites
    }
    cases = get_tests(testlink_client, UI_TEST_KEYWORD, plan_id, TESTLINK_PROJECT_ID, CUSTOM_FIELD_NAME_LIST)
    names = [n["tcase_name"] for n in cases]
    other_cases = get_tests(testlink_client, None, plan_id, TESTLINK_PROJECT_ID, CUSTOM_FIELD_NAME_LIST)
    cases += [n for n in other_cases if n["tcase_name"] not in names]
    for case in cases:
        case["suite"] = suites_tc_dic[case["testsuite_id"]]

    tests = []
    # if we do not force to download everythin we get already defined tests to avoid erasing them
    if not args.download_all:
        tests += list(set([a for a in get_test_names(defaultTestLoader.discover(args.dest_dir))]))
    # launch true creation
    for to_be_created in cases:
        if to_be_created["tcase_name"] not in tests:
            create_test_file(to_be_created, args.dest_dir, to_be_created["keyword"] == UI_TEST_KEYWORD, args.plan)
Ejemplo n.º 3
0
    def setUp(self):
        """Initialisation
        """

        # precondition - SERVEUR_URL and KEY are defined in environment
        # TESTLINK_API_PYTHON_SERVER_URL=http://localhost/testlink/lib/api/xmlrpc.php
        # TESTLINK_API_PYTHON_DEVKEY=7ec252ab966ce88fd92c25d08635672b
        self.client = TestLinkHelper().connect(TestLink)
 def test_callServer_ProtocollError(self):
     """ test _callServer() - Server raises ProtocollError """
     
     server_url = TestLinkHelper()._server_url
     bad_server_url = server_url.split('xmlrpc.php')[0] 
     client = TestLinkHelper(bad_server_url).connect(TestlinkAPIClient)
     def a_func(api_client): api_client._callServer('sayHello')
     self.assertRaises(testlinkerrors.TLConnectionError, a_func, client)
Ejemplo n.º 5
0
 def __init__(self):
     tlk_helper = TestLinkHelper(
         server_url=
         'http://192.168.202.174/testlink-1.9.17/lib/api/xmlrpc/v1/xmlrpc.php',
         devkey='0b839ca6b6a4d8b78139e5f5f93c38f1')
     try:
         self.testlink = tlk_helper.connect(TestlinkAPIClient)  # 连接TestLink
     except Exception as e:
         logger.error('连接testlink失败:%s' % e)
         exit()
    def test_callServer_ProtocolError(self):
        """ test _callServer() - Server raises ProtocollError """
        
        server_url = TestLinkHelper()._server_url
        bad_server_url = server_url.split('xmlrpc.php')[0] 
        client = TestLinkHelper(bad_server_url).connect(TestlinkAPIClient)

        def a_func(api_client):
            api_client._callServer('sayHello')
        self.assertRaises(testlinkerrors.TLConnectionError, a_func, client)
Ejemplo n.º 7
0
 def afterEditing(self):
     self.parentApp.host = self.hostBox.value
     self.parentApp.devkey = self.devkeyBox.value
     try:
         self.statusBox.value = 'Connecting...'
         tlh = TestLinkHelper(server_url='http://'+self.parentApp.host+'/lib/api/xmlrpc/v1/xmlrpc.php', devkey=self.parentApp.devkey)
         self.parentApp.tl = tlh.connect(TestlinkAPIClient)
         self.parentApp.tl.sayHello()
     except testlinkerrors.TLConnectionError as err:
         self.statusBox.value = err
     else:
         self.parentApp.setNextForm('IMPORT')
Ejemplo n.º 8
0
class TestClass():
    def setUp(self):
        """Initialisation
        """

        # precondition - SERVEUR_URL and KEY are defined in environment
        # TESTLINK_API_PYTHON_SERVER_URL=http://localhost/testlink/lib/api/xmlrpc.php
        # TESTLINK_API_PYTHON_DEVKEY=7ec252ab966ce88fd92c25d08635672b
        self.client = TestLinkHelper().connect(TestLink)

    def test_getTestCaseIDByName(self):
        """ getTestCaseIDByName test
        """
        val = self.client.getTestCaseIDByName("Fin de programme", "Séquence 2",
                                              "Test 2")
        # 31 is test case id
        assert_equal(val, '31')

        # Check if an error is raised in case of bad parameters
        assert_raises(TestLinkError, self.client.getTestCaseIDByName,
                      "Initialisation", "Séquence 1", "Test 2")

    def test_getTestProjectByName(self):
        project = self.client.getTestProjectByName("Test 2")
        assert_equals(type(project), dict)
        # Check if an error is raised in case of bad parameters
        assert_raises(TestLinkError, self.client.getTestProjectByName,
                      "Unknown project")

    def test_getTestPlanByName(self):
        plan_ok = self.client.getTestPlanByName("Test 2", "Full")

        # Assume that plan id is 33
        assert_equal(plan_ok['id'], '33')

        assert_raises(TestLinkError, self.client.getTestPlanByName, "Test 2",
                      "Name Error")

    def test_getBuildByName(self):
        pass

    def test_reportResult(self):
        dico = {
            'testProjectName': 'Automatique',
            'testPlanName': 'FullAuto',
            'buildName': 'V0.1'
        }
        execid = self.client.reportResult("p", "test1", "S1",
                                          "An example of note", **dico)
        assert_equal(type(execid), str)

        execid = self.client.reportResult("f", "test2", "S1", **dico)
        assert_equal(type(execid), str)
 def __init__(self, server_url, project_id,
              platformname, must_create_build,
              testlink_key, verbose=False, generate_xml=False):
     self.server_url = server_url
     self.generate_xml = generate_xml
     self.project_id = project_id
     self.platformname = platformname
     self.must_create_build = must_create_build
     self.testlink_key = testlink_key
     tl_helper = TestLinkHelper(self.server_url, self.testlink_key)
     self.testlink_client = tl_helper.connect(TestlinkAPIClient)
     self.plans = self.testlink_client.getProjectTestPlans(self.project_id)
     self.verbose = verbose
Ejemplo n.º 10
0
    def create_api_client(self, client_class='TestlinkAPIClient', 
                          server_url=None, devkey=None):
        """Creates a new TestLink-API-Python-client (XMLRPC), using Python class 
        TestlinkAPIClient or TestlinkAPIGeneric. 
        """

        a_server_url  = server_url or self._server_url
        a_devkey      = devkey or self._devkey
        a_helper = TestLinkHelper(a_server_url, a_devkey)
        
        a_class_name  = client_class or self._client_class
        a_api_class   = globals()[a_class_name]
        self.api_client  = a_helper.connect(a_api_class)
        return self.api_client 
    def create_api_client(self, client_class='TestlinkAPIClient', 
                          server_url=None, devkey=None):
        """Creates a new TestLink-API-Python-client (XMLRPC), using Python class 
        TestlinkAPIClient or TestlinkAPIGeneric. 
        """

        a_server_url  = server_url or self._server_url
        a_devkey      = devkey or self._devkey
        a_helper = TestLinkHelper(a_server_url, a_devkey)
        
        a_class_name  = client_class or self._client_class
        a_api_class   = globals()[a_class_name]
        self.api_client  = a_helper.connect(a_api_class)
        return self.api_client 
Ejemplo n.º 12
0
    def setUp(self):
        """Initialisation
        """

        # precondition - SERVEUR_URL and KEY are defined in environment
        # TESTLINK_API_PYTHON_SERVER_URL=http://localhost/testlink/lib/api/xmlrpc.php
        # TESTLINK_API_PYTHON_DEVKEY=7ec252ab966ce88fd92c25d08635672b
        self.client = TestLinkHelper().connect(TestLink)
Ejemplo n.º 13
0
class TestClass():
    def setUp(self):
        """Initialisation
        """

        # precondition - SERVEUR_URL and KEY are defined in environment
        # TESTLINK_API_PYTHON_SERVER_URL=http://localhost/testlink/lib/api/xmlrpc.php
        # TESTLINK_API_PYTHON_DEVKEY=7ec252ab966ce88fd92c25d08635672b
        self.client = TestLinkHelper().connect(TestLink)

    def test_getTestCaseIDByName(self):
        """ getTestCaseIDByName test
        """
        val = self.client.getTestCaseIDByName("Fin de programme", "Séquence 2", "Test 2")
        # 31 is test case id
        assert_equal(val, '31' )

        # Check if an error is raised in case of bad parameters
        assert_raises(TestLinkError, self.client.getTestCaseIDByName, "Initialisation", "Séquence 1", "Test 2")

    def test_getTestProjectByName(self):
        project = self.client.getTestProjectByName("Test 2")
        assert_equals(type(project), dict)
        # Check if an error is raised in case of bad parameters
        assert_raises(TestLinkError, self.client.getTestProjectByName, "Unknown project")

    def test_getTestPlanByName(self):
        plan_ok = self.client.getTestPlanByName("Test 2", "Full")

        # Assume that plan id is 33
        assert_equal(plan_ok['id'], '33')

        assert_raises(TestLinkError, self.client.getTestPlanByName, "Test 2", "Name Error")

    def test_getBuildByName(self):
        pass

    def test_reportResult(self):
        dico = {'testProjectName': 'Automatique',
                'testPlanName': 'FullAuto',
                'buildName': 'V0.1'}
        execid = self.client.reportResult("p", "test1", "S1", "An example of note", **dico)
        assert_equal(type(execid), str)

        execid = self.client.reportResult("f", "test2", "S1", **dico)
        assert_equal(type(execid), str)
    def test_callServer_FaultError(self):
        """ test _callServer() - Server raises Fault Error """
        
        client = TestLinkHelper().connect(TestlinkAPIClient)

        def a_func(api_client):
            api_client._callServer('sayGoodBye')
        self.assertRaises(testlinkerrors.TLAPIError, a_func, client)
    def test_callServer_socketError(self):
        """ test _callServer() - Server raises a socket Error (IOError) """
        
        bad_server_url = 'http://111.222.333.4/testlink/lib/api/xmlrpc.php' 
        client = TestLinkHelper(bad_server_url).connect(TestlinkAPIClient)

        def a_func(api_client):
            api_client._callServer('sayHello')
        self.assertRaises(testlinkerrors.TLConnectionError, a_func, client)
 def start_suite(self, data, result):
     self.robot_variables.check_variables()
     if self.tls is None:
         self.tls = TestLinkHelper(
             self.robot_variables.server,
             self.robot_variables.devkey).connect(TestlinkAPIClient)
     self.report_kwargs = self.robot_variables.get_report_kwargs()
     self.test_prefix = self._get_prefix_from_testlink(
         self.robot_variables.testprojectname)
Ejemplo n.º 17
0
    def __init__(self):
        tlk_helper = TestLinkHelper()
        url = "http://192.168.199.13:81/testlink/lib/api/xmlrpc/v1/xmlrpc.php"
        key = "68194d618ccb4ce674f3935d73bf77ac"

        try:
            self.testlink = testlink.TestlinkAPIClient(url, key)  # 连接TestLink
        except Exception as e:
            logger.error('连接testlink失败:%s' % e)
            exit()
Ejemplo n.º 18
0
def run_report():
    failed_list = []
    tls = TestLinkHelper().connect(TestlinkAPIClient)  # connect to Testlink
    testplan_id_result = tls.getTestPlanByName(test_project, test_plan)  # get test plan id
    testplan_id = testplan_id_result[0]['id']
    testcases = get_testcase()

    for i in testcases:
        test_result = i[0]
        test_notes = i[1]
        testcase_name = i[2]
        index = i[3]
        #
        # testcase_id_result = tls.getTestCaseIDByName(testcase_name)  # get test case id
        # testcase_id = testcase_id_result[0]['id']
        # tls.reportTCResult(testcase_id, testplan_id, test_build, test_result, test_notes)

        try:
            testcase_id_result = tls.getTestCaseIDByName(testcase_name)  # get test case id
            testcase_id = testcase_id_result[0]['id']
            tls.reportTCResult(testcase_id, testplan_id, test_build, test_result, test_notes)
        except TestLinkError:
            failed_list.append((index, testcase_name))

    if len(failed_list) > 0:
        log_name = 'logFile_%s.txt' % time.time()
        curr_dir = os.path.dirname(os.path.abspath(__file__))
        dest_dir = os.path.join(curr_dir, new_dir)
        try:
            os.makedirs(dest_dir)
        except OSError:
            pass
        log_file = os.path.join(dest_dir, log_name)
        with open(log_file, 'w') as f:
            for item in failed_list:
                f.write(','.join(str(i) for i in item) + '\n')
Ejemplo n.º 19
0
def run_report():
    testcases = get_testcase()
    project = get_project()

    run_num = 0
    failed_list = []
    test_project = project[0]
    test_plan = project[1]
    test_build = project[2]

    tls = TestLinkHelper().connect(TestlinkAPIClient)  # connect to Testlink
    testplan_id_result = tls.getTestPlanByName(test_project,
                                               test_plan)  # get test plan id
    testplan_id = testplan_id_result[0]['id']

    for i in testcases:
        index = i[0]
        test_result = i[1]
        test_notes = i[2]
        testcase_name = i[3]

        # testcase_id_result = tls.getTestCaseIDByName(testcase_name)  # get test case id
        # testcase_id = testcase_id_result[0]['id']
        # tls.reportTCResult(testcase_id, testplan_id, test_build, test_result, test_notes)

        try:
            testcase_id_result = tls.getTestCaseIDByName(
                testcase_name)  # get test case id
            testcase_id = testcase_id_result[0]['id']
            tls.reportTCResult(testcase_id, testplan_id, test_build,
                               test_result, test_notes)
            run_num += 1
        except TestLinkError as e:
            failed_list.append((index, testcase_name, e))

    if len(failed_list) > 0:
        log_name = 'logFile_%s.txt' % time.time()
        curr_dir = os.path.dirname(os.path.abspath(__file__))
        dest_dir = os.path.join(curr_dir, new_dir)
        try:
            os.makedirs(dest_dir)
        except OSError:
            pass
        log_file = os.path.join(dest_dir, log_name)
        with open(log_file, 'w') as f:
            for item in failed_list:
                f.write('-----'.join(str(i) for i in item) + '\n')

    print '%s test case(s) has been written into log file.' % len(failed_list)
    print '%s test case(s) has been executed.' % run_num
class TestLinkAPIOfflineTestCase(unittest.TestCase):
    """ TestCases for TestlinkAPIClient - does not interacts with a TestLink Server.
    works with DummyAPIClientm which returns special test data
    """

    example_steps = [{'step_number' : '1', 'actions' : "action A" , 
                'expected_results' : "result A", 'execution_type' : "0"},
                 {'step_number' : '2', 'actions' : "action B" , 
                'expected_results' : "result B", 'execution_type' : "1"},
                 {'step_number' : '3', 'actions' : "action C" , 
                'expected_results' : "result C", 'execution_type' : "0"}]
    def setUp(self):
        self.api = TestLinkHelper().connect(DummyAPIClient)

#    def tearDown(self):
#        pass


    def test_countProjects(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countProjects()
        self.assertEqual(2, response)
        
    def test_countTestPlans(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countTestPlans()
        self.assertEqual(2, response)
        
    def test_countTestSuites(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countTestSuites()
        self.assertEqual(0, response)
        
    def test_countTestCasesTP(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countTestCasesTP()
        self.assertEqual(0, response)
        
    def test_countTestCasesTS(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countTestCasesTS()
        self.assertEqual(0, response)

    def test_countPlatforms(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countPlatforms()
        self.assertEqual(2, response)
        
    def test_countBuilds(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countBuilds()
        self.assertEqual(0, response)

#    def test_listProjects(self):
#        self.api.loadScenario(SCENARIO_A)
#        self.api.listProjects()
#         no assert check cause method returns nothing
#         'just' prints to stdout
        
    def test_getProjectIDByName(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getProjectIDByName('NEW_PROJECT_API')
        self.assertEqual('21', response)
        response = self.api.getProjectIDByName('UNKNOWN_PROJECT')
        self.assertEqual(-1, response)
        
    def test_initStep(self):
        self.api.initStep("action A", "result A", 0)
        steps = self.example_steps[:1]
        self.assertEqual(steps, self.api.stepsList)
        
    def test_appendStep(self):
        steps = self.example_steps
        self.api.stepsList = steps[:1] 
        self.api.appendStep("action B", "result B", 1)
        self.api.appendStep("action C", "result C", 0)
        self.assertEqual(steps, self.api.stepsList)

    def test_createTestCaseWithSteps(self):
        self.api.loadScenario(SCENARIO_STEPS)
        self.api.initStep("action A", "result A", 0)
        self.api.appendStep("action B", "result B", 1)
        self.api.appendStep("action C", "result C", 0)
        self.api.createTestCase('case 4711', 4712, 4713, 'Big Bird', 
                                'summary 4714')
        self.assertEqual(self.example_steps, self.api.callArgs['steps'])
        self.assertEqual([], self.api.stepsList)

    def test_createTestCaseWithConfusingSteps(self):
        self.api.loadScenario(SCENARIO_STEPS)
        self.api.initStep("action A", "result A", 0)
        self.api.appendStep("action B", "result B", 1)
        self.api.appendStep("action C", "result C", 0)
        with self.assertRaisesRegexp(TLArgError, 'confusing createTestCase*'):
            self.api.createTestCase('case 4711', 4712, 4713, 'Big Bird', 
                                    'summary 4714', steps=[])
        
    def test_getTestCaseIDByName_dictResult(self):
        "test that getTestCaseIDByName converts dictionary result into a list"
        self.api.loadScenario(SCENARIO_A)
        # v0.4.0 version for optional args testsuitename + testprojectname
        #response = self.api.getTestCaseIDByName('dictResult', None, 'NEW_PROJECT_API')
        # v0.4.5 version
        response = self.api.getTestCaseIDByName('dictResult', 
                                            testprojectname='NEW_PROJECT_API')
        self.assertEqual(list, type(response))
        self.assertEqual('TESTCASE_B', response[0]['name']) 
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
        
    def test_getTestCaseIDByName_listResult(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getTestCaseIDByName('listResult')
        self.assertEqual(list, type(response))
        self.assertEqual('TESTCASE_AA', response[0]['name']) 
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
        
    def test_getProjectIDByNode(self):
        self.api.loadScenario(SCENARIO_A)
        self.assertEqual('2211', self.api.getProjectIDByNode('4711'))
        
    def test__copyTC_generate_new(self):
        self.api.loadScenario(SCENARIO_A)
        self.api._copyTC('26', {}, duplicateaction = 'generate_new')
        self.assertEqual('generate_new',  
                         self.api.callArgs['actiononduplicatedname'])

    def test__copyTC_create_new_version(self):
        self.api.loadScenario(SCENARIO_A)
        self.api._copyTC('26', {}, duplicateaction = 'create_new_version')
        self.assertEqual('create_new_version',  
                         self.api.callArgs['actiononduplicatedname'])
        self.assertEqual('V2 None', self.api.callArgs['preconditions'])

    def test__copyTC_changedArgs(self):
        self.api.loadScenario(SCENARIO_A)
        self.api._copyTC('26', {'testsuiteid' :'4711'}, 
                         duplicateaction = 'generate_new')
        self.assertEqual('4711', self.api.callArgs['testsuiteid'])
        self.assertEqual('2211', self.api.callArgs['testprojectid'])

    def test__copyTC_changedArgs_version(self):
        self.api.loadScenario(SCENARIO_A)
        self.api._copyTC('26', {'testsuiteid' :'4711'}, 1,
                         duplicateaction = 'generate_new')
        self.assertEqual('4711', self.api.callArgs['testsuiteid'])
        self.assertEqual('2211', self.api.callArgs['testprojectid'])
        self.assertEqual('V1', self.api.callArgs['preconditions'])
        

    def test_copyTCnewVersion(self):
        self.api.loadScenario(SCENARIO_A)
        self.api.copyTCnewVersion('26', summary = 'The summary has changed', 
                                    importance = '33')
        self.assertEqual('create_new_version',  
                         self.api.callArgs['actiononduplicatedname'])
        self.assertEqual('V2 None', self.api.callArgs['preconditions'])
        self.assertEqual('The summary has changed', self.api.callArgs['summary'])
        self.assertEqual('33', self.api.callArgs['importance'])
        self.assertEqual('TC-C', self.api.callArgs['testcasename'])
        self.assertEqual('25', self.api.callArgs['testsuiteid'])
        self.assertEqual('21', self.api.callArgs['testprojectid'])

    def test_copyTCnewVersion_version(self):
        self.api.loadScenario(SCENARIO_A)
        self.api.copyTCnewVersion('26', 1, summary = 'The summary has changed', 
                                    importance = '33')
        self.assertEqual('create_new_version',  
                         self.api.callArgs['actiononduplicatedname'])
        self.assertEqual('V1', self.api.callArgs['preconditions'])
        self.assertEqual('The summary has changed', self.api.callArgs['summary'])
        self.assertEqual('33', self.api.callArgs['importance'])
        self.assertEqual('TC-C', self.api.callArgs['testcasename'])
        self.assertEqual('25', self.api.callArgs['testsuiteid'])
        self.assertEqual('21', self.api.callArgs['testprojectid'])

    def test_copyTCnewTestCase(self):
        self.api.loadScenario(SCENARIO_A)
        self.api.copyTCnewTestCase('26', testsuiteid = '4711')
        self.assertEqual('generate_new',  
                         self.api.callArgs['actiononduplicatedname'])
        self.assertEqual('V2 None', self.api.callArgs['preconditions'])
        self.assertEqual('4711', self.api.callArgs['testsuiteid'])
        self.assertEqual('2211', self.api.callArgs['testprojectid'])

    def test_copyTCnewTestCase_version(self):
        self.api.loadScenario(SCENARIO_A)
        self.api.copyTCnewTestCase('26', 1, testsuiteid = '4711')
        self.assertEqual('generate_new',  
                         self.api.callArgs['actiononduplicatedname'])
        self.assertEqual('V1', self.api.callArgs['preconditions'])
        self.assertEqual('4711', self.api.callArgs['testsuiteid'])
        self.assertEqual('2211', self.api.callArgs['testprojectid'])

    def test_reportTCResult_user(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.reportTCResult(4711, 4712, 'build 4713', 'p', 
                                           'note 4714', user='******') 
        self.assertEqual('reportTCResult', response[0]['operation']) 
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
        self.assertEqual('a login name', self.api.callArgs['user'])
        
    def test_whatArgs_reportTCResult(self):
        argsDescription = self.api.whatArgs('reportTCResult')
        self.assertIn('user=<user>', argsDescription)

    def test_getTestCasesForTestSuite_keyWords(self):
        self.api.loadScenario(SCENARIO_KEYWORDS)
        response = self.api.getTestCasesForTestSuite('deepFalse3', False, 
                                                     'full', getkeywords=True)
        self.assertIn('keywords', response[0])
        self.assertNotIn('keywords', response[2])
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
           
    def test_whatArgs_getTestCasesForTestSuite(self):
        argsDescription = self.api.whatArgs('getTestCasesForTestSuite')
        self.assertIn('getkeywords=<getkeywords>', argsDescription)
        
    def test_listKeywordsForTC_FullExternalId(self):
        self.api.loadScenario(SCENARIO_KEYWORDS)
        response = self.api.listKeywordsForTC('NPROAPI-2')
        self.assertEqual(['KeyWord01', 'KeyWord03'], response)
        
    def test_listKeywordsForTC_InternalId_Int(self):
        self.api.loadScenario(SCENARIO_KEYWORDS)
        response = self.api.listKeywordsForTC(8144)
        self.assertEqual(['KeyWord01', 'KeyWord03'], response)
        
    def test_listKeywordsForTC_InternalId_String(self):
        self.api.loadScenario(SCENARIO_KEYWORDS)
        response = self.api.listKeywordsForTC('8144')
        self.assertEqual(['KeyWord01', 'KeyWord03'], response)
        
    def test_listKeywordsForTC_One(self):
        self.api.loadScenario(SCENARIO_KEYWORDS)
        response = self.api.listKeywordsForTC('NPROAPI-3')
        self.assertEqual(['KeyWord02'], response)

    def test_listKeywordsForTC_None(self):
        self.api.loadScenario(SCENARIO_KEYWORDS)
        response = self.api.listKeywordsForTC('NPROAPI-4')
        self.assertEqual([], response)
        
    def test_listKeywordsForTS_NoneTC(self):
        self.api.loadScenario(SCENARIO_KEYWORDS)
        response = self.api.listKeywordsForTS('noTestCase')
        self.assertEqual({}, response)

    def test_listKeywordsForTS_NoneKW(self):
        self.api.loadScenario(SCENARIO_KEYWORDS)
        response = self.api.listKeywordsForTS('noKeywords')
        self.assertEqual({'8144' : []}, response)
        
    def test_listKeywordsForTS_Id_Int(self):
        self.api.loadScenario(SCENARIO_KEYWORDS)
        response = self.api.listKeywordsForTS(4711)
        self.assertEqual({'8144' : ['KeyWord01', 'KeyWord03']}, response)
        
    def test_listKeywordsForTS_Id_String(self):
        self.api.loadScenario(SCENARIO_KEYWORDS)
        response = self.api.listKeywordsForTS('4711')
        self.assertEqual({'8144' : ['KeyWord01', 'KeyWord03']}, response)
       
    def test_listKeywordsForTS_Multi(self):
        self.api.loadScenario(SCENARIO_KEYWORDS)
        response = self.api.listKeywordsForTS('deepFalse3')
        self.assertEqual({'8144' : ['KeyWord01', 'KeyWord03'],
                          '8159' : ['KeyWord02'], '8169' : []}, response)
        
    def test_whatArgs_getLastExecutionResult(self):
        argsDescription = self.api.whatArgs('getLastExecutionResult')
        self.assertIn('options=<options>', argsDescription)
        self.assertIn('getBugs', argsDescription)
 def setUp(self):
     self.client = TestLinkHelper().connect(TestlinkAPIGeneric)
# precondition a)
# SERVER_URL and KEY are defined in environment
# TESTLINK_API_PYTHON_SERVER_URL=http://YOURSERVER/testlink/lib/api/xmlrpc.php
# TESTLINK_API_PYTHON_DEVKEY=7ec252ab966ce88fd92c25d08635672b
# 
# alternative precondition b)
# SERVEUR_URL and KEY are defined as command line arguments
# python TestLinkExample.py --server_url http://YOURSERVER/testlink/lib/api/xmlrpc.php
#                           --devKey 7ec252ab966ce88fd92c25d08635672b
#
# ATTENTION: With TestLink 1.9.7, cause of the new REST API, the SERVER_URL 
#            has changed from 
#               (old) http://YOURSERVER/testlink/lib/api/xmlrpc.php
#            to
#               (new) http://YOURSERVER/testlink/lib/api/xmlrpc/v1/xmlrpc.php
tl_helper = TestLinkHelper()
tl_helper.setParamsFromArgs('''Shows how to use the TestLinkAPI for CustomFields.
=> requires an existing project NEW_PROJECT_API-*''')
myTestLink = tl_helper.connect(TestlinkAPIClient) 

#projNr=len(myTestLink.getProjects())+1
projNr=len(myTestLink.getProjects())

NEWPROJECT="NEW_PROJECT_API-%i" % projNr
NEWPREFIX="NPROAPI%i" % projNr
NEWTESTPLAN_A="TestPlan_API A"
# NEWTESTPLAN_B="TestPlan_API B"
# NEWPLATFORM_A='Big Bird %i' % projNr
NEWPLATFORM_B='Small Birds'
# NEWPLATFORM_C='Ugly Bird'
NEWTESTSUITE_A="A - First Level"
 def setUp(self):
     self.client = TestLinkHelper().connect(TestlinkAPIClient)
Ejemplo n.º 24
0
                return json_out

    def tearDown(self):
        self.assertEqual([], self.verificationErrors)


if __name__ == '__main__':
    # redirector default output of unittest to /dev/null
    with open( os.devnull, 'w' ) as null_stream:
        runner = TextTestRunner( stream=null_stream )
        runner.resultclass = AppDynamicsJob

        TESTLINK_API_PYTHON_SERVER_URL = 'http://127.0.0.1/testlink/lib/api/xmlrpc/v1/xmlrpc.php'
        #wpisz swój klucz w dół
        TESTLINK_API_PYTHON_DEVKEY = '724497bfde0cc05904c85a68a1263c6d'
        tl_helper = TestLinkHelper(TESTLINK_API_PYTHON_SERVER_URL, TESTLINK_API_PYTHON_DEVKEY)
        myTestLink = tl_helper.connect(TestlinkAPIClient)
        print(myTestLink.connectionInfo())

        print(myTestLink.countProjects())
        tc_info = myTestLink.getTestCase(None, testcaseexternalid='26-2')
        print(tc_info)
        tc_info = myTestLink.getProjectTestPlans('1')
        print(tc_info)
        # tls.reportTCResult(4, 2, 'SampleBuild', 'f', 'some notes', user='******', platformid='1')
        myTestLink.reportTCResult(None, 2, None, 'p', 'some notes', guess=True,
                           testcaseexternalid='26-2',
                           platformname='DPP',
                           execduration=3.9, timestamp='2020-06-10 12:03',
                           steps=[{'step_number': 1, 'result': 'p', 'notes': 'result note for passed step 1'}])
Ejemplo n.º 25
0
    def test_callServer_withArgs(self):
        """ test _callServer() - calling method with args """

        client = TestLinkHelper().connect(TestlinkAPIClient)
        response = client._callServer('repeat', {'str': 'some arg'})
        self.assertEqual('You said: some arg', response)
 def setUp(self):
     self.api = TestLinkHelper().connect(DummyAPIClient)
 def test_callServer_noArgs(self):
     """ test _callServer() - calling method with no args """
     
     client = TestLinkHelper().connect(TestlinkAPIClient)
     response = client._callServer('sayHello')
     self.assertEqual('Hello!', response)
 def setUp(self):
     self.api = TestLinkHelper().connect(DummyAPIGeneric)
     self.callArgs = None
Ejemplo n.º 29
0
# precondition a)
# SERVER_URL and KEY are defined in environment
# TESTLINK_API_PYTHON_SERVER_URL=http://YOURSERVER/testlink/lib/api/xmlrpc.php
# TESTLINK_API_PYTHON_DEVKEY=7ec252ab966ce88fd92c25d08635672b
#
# alternative precondition b)
# SERVEUR_URL and KEY are defined as command line arguments
# python TestLinkExample.py --server_url http://YOURSERVER/testlink/lib/api/xmlrpc.php
#                           --devKey 7ec252ab966ce88fd92c25d08635672b
#
# ATTENTION: With TestLink 1.9.7, cause of the new REST API, the SERVER_URL
#            has changed from
#               (old) http://YOURSERVER/testlink/lib/api/xmlrpc.php
#            to
#               (new) http://YOURSERVER/testlink/lib/api/xmlrpc/v1/xmlrpc.php
tl_helper = TestLinkHelper()
tl_helper.setParamsFromArgs('''Shows how to use the TestLinkAPI for CustomFields.
=> requires an existing project NEW_PROJECT_API-*''')
myTestLink = tl_helper.connect(TestlinkAPIClient)

myPyVersion = python_version()
myPyVersionShort = myPyVersion.replace('.', '')[:2]

NEWPROJECT="NEW_PROJECT_API-%s" % myPyVersionShort
NEWPREFIX="NPROAPI%s" % myPyVersionShort
NEWTESTPLAN_A="TestPlan_API A"
# NEWTESTPLAN_B="TestPlan_API B"
# NEWPLATFORM_A='Big Bird %i' % projNr
NEWPLATFORM_B='Small Birds'
# NEWPLATFORM_C='Ugly Bird'
NEWTESTSUITE_A="A - First Level"
class TestLinkAPIGenericOfflineTestCase(unittest.TestCase):
    """ TestCases for TestlinkAPIGeneric - does not interacts with a TestLink Server.
    works with DummyAPIGeneric which returns special test data
    """

    def setUp(self):
        self.api = TestLinkHelper().connect(DummyAPIGeneric)
        self.callArgs = None
        
#    def tearDown(self):
#        pass


    def test_convertPositionalArgs(self):
        response = self.api._convertPostionalArgs('DummyMethod',  [1,2,3])
        self.assertEqual({'Uno' : 1, 'due' :2, 'tre' : 3}, response)
        
    def test__convertPositionalArgs_missingConf(self):
        client = self.api
        def a_func(a_api): a_api._convertPostionalArgs('NoConfigMethod',  [1,2])
        self.assertRaises(TLArgError, a_func, client)
        
    def test__convertPositionalArgs_lessValues(self):
        client = self.api
        def a_func(a_api): a_api._convertPostionalArgs('DummyMethod',  [1,2])
        self.assertRaises(TLArgError, a_func, client)
        
    def test__convertPositionalArgs_moreValues(self):
        client = self.api
        def a_func(a_api): a_api._convertPostionalArgs('DummyMethod',  [1,2,3,4])
        self.assertRaises(TLArgError, a_func, client)

    def test_callServerWithPosArgs_pos(self):
        self.api.callServerWithPosArgs('DummyMethod',  1,2,3)
        self.assertEqual({'Uno' : 1, 'due' :2, 'tre' : 3}, self.api.callArgs)

    def test_callServerWithPosArgs_pos_opt(self):
        self.api.callServerWithPosArgs('DummyMethod',  1,2,3, quad=4)
        self.assertEqual({'Uno' : 1, 'due' :2, 'tre' : 3, 'quad' : 4}, self.api.callArgs)

    def test_callServerWithPosArgs_opt(self):
        self.api.callServerWithPosArgs('DummyMethod',  quad=4)
        self.assertEqual({'quad' : 4}, self.api.callArgs)

    def test_callServerWithPosArgs_none(self):
        self.api.callServerWithPosArgs('DummyMethod')
        self.assertEqual({}, self.api.callArgs)
        
    def test_checkResponse_emptyResponse(self):
        client = self.api
        def a_func(a_api, response): 
            a_api._checkResponse(response, 'DummyMethod',  
                                 {'Uno' : 1, 'due' :2, 'tre' : 3})
        self.assertRaises(TLResponseError, a_func, client, '')
        self.assertRaises(TLResponseError, a_func, client, [])
        
    def test_checkResponse_errorResponse(self):
        client = self.api
        responseA = [{'message': '(reportTCResult) - TC ID 709 does not exist!', 
                      'code': 5000}]
        def a_func(a_api, response): 
            a_api._checkResponse(response, 'DummyMethod',  
                                 {'Uno' : 1, 'due' :2, 'tre' : 3})
        self.assertRaises(TLResponseError, a_func, client, responseA)

    def test_checkResponse_okResponse(self):
        self.api._checkResponse(
                        [{'message': 'all fine, cause no key with name code'}],
                         'DummyMethod', {'Uno' : 1, 'due' :2, 'tre' : 3})
        self.api._checkResponse(
                        'some API Call juts returns one string without codes',
                         'DummyMethod', {'Uno' : 1, 'due' :2, 'tre' : 3})
        
    def test_checkResponse_booleanResponse(self):
        response = True
        self.api._checkResponse(response, 'DummyMethod', 
                                {'Uno' : 1, 'due' :2, 'tre' : 3})
        
    def test_checkResponse_dictionaryResponse(self):
        response = {'note' : 'uploadAttachment Calls return {..} and not [{..}]'}
        self.api._checkResponse(response, 'DummyMethod', 
                                {'Uno' : 1, 'due' :2, 'tre' : 3})
        
    def test_checkResponse_errorResponse_sringCode(self):
        client = self.api
        
        responseA = [{'message': '(getUserByID) - Cannot Find User with DB ID (4711).', 
                      'code': 'NO_USER_BY_ID_LOGIN'}]
        def a_func(a_api, response): 
            a_api._checkResponse(response, 'getUserByID',  
                                 {'userid' : 4711})
        self.assertRaises(TLResponseError, a_func, client, responseA)

    def test__apiMethodArgNames_noArgs(self):
        response = self.api._apiMethodArgNames('sayHello')
        self.assertEqual(response, ([], [], []))

    def test_whatArgs_noArgs(self):
        response = self.api.whatArgs('sayHello')
        self.assertRegex(response, 'sayHello().*')
        
    def test__apiMethodArgNames_onlyOptionalArgs(self):
        response = self.api._apiMethodArgNames('getTestCaseAttachments')
        self.assertEqual(response[0], [])
        self.assertGreater(len(response[1]), 0)
        self.assertEqual(response[2], [])

    def test_whatArgs_onlyOptionalArgs(self):
        response = self.api.whatArgs('getTestCaseAttachments')
        self.assertRegex(response, 'getTestCaseAttachments\(\[.*=<.*>\].*\).*')
        
    def test__apiMethodArgNames__OptionalAndPositionalArgs(self):
        response = self.api._apiMethodArgNames('createBuild')
        self.assertGreater(len(response[0]), 0)
        self.assertGreater(len(response[1]), 0)
        self.assertEqual(response[2], [])

    def test_whatArgs_OptionalAndPositionalArgs(self):
        response = self.api.whatArgs('createBuild')
        self.assertRegex(response, 'createBuild\(<.*>.*\).*')

    def test__apiMethodArgNames__MandatoryArgs(self):
        response = self.api._apiMethodArgNames('uploadExecutionAttachment')
        self.assertGreater(len(response[0]), 0)
        self.assertGreater(len(response[1]), 0)
        self.assertGreater(len(response[2]), 0)

    def test_whatArgs_MandatoryArgs(self):
        response = self.api.whatArgs('uploadExecutionAttachment')
        self.assertRegex(response, 
                    'uploadExecutionAttachment\(<attachmentfile>, <.*>.*\).*')

    def test_whatArgs_unknownMethods(self):
        response = self.api.whatArgs('apiUnknown')
        self.assertRegex(response, 
                "callServerWithPosArgs\('apiUnknown', \[apiArg=<apiArg>\]\)")
        
    def test_noWrapperName_apiMethods(self):
        " decorator test: API Methods internal function name should be unchanged "
        
        # apiMethod with decorator @decoApiCallWithoutArgs
        self.assertEqual('sayHello', self.api.sayHello.__name__)
        # apiMethod with decorator @decoApiCallWithArgs
        self.assertEqual('repeat', self.api.repeat.__name__)
        # apiMethod with decorator @decoApiCallAddDevKey 
        self.assertEqual('createBuild', self.api.createBuild.__name__)
        # apiMethod with decorator @decoMakerApiCallReplaceTLResponseError()
        self.assertEqual('getProjectTestPlans', self.api.getProjectTestPlans.__name__)
        # apiMethod with decorator @decoApiCallAddAttachment
        self.assertEqual('uploadExecutionAttachment', self.api.uploadExecutionAttachment.__name__)
        
    def test_ping(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.ping()
        self.assertEqual('Hey Folks!', response)
        
        
    def test_getProjectTestPlans_noPlan(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getProjectTestPlans('noPlan')
        self.assertEqual([], response)
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
        
    def test_getProjectTestPlans_onePlan(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getProjectTestPlans('onePlan')
        self.assertEqual('21', response[0]['testproject_id'])
        self.assertEqual(1, len(response))
        
    def test_getProjectPlatforms_noPlatform(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getProjectPlatforms('noPlatform')
        self.assertEqual({}, response)
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
        
    def test_getProjectPlatforms_twoPlatforms(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getProjectPlatforms('twoPlatforms')
        self.assertEqual('1', response['dutch']['id'])
        self.assertEqual(2, len(response))
        
        
    def test_getBuildsForTestPlan_noBuild(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getBuildsForTestPlan('noBuild')
        self.assertEqual([], response)
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
        
    def test_getTestPlanPlatforms_noPlatform(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getTestPlanPlatforms('noPlatform')
        self.assertEqual([], response)
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
        
    def test_getTestPlanPlatforms_twoPlatforms(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getTestPlanPlatforms('twoPlatforms')
        self.assertEqual('dutch', response[0]['name'])
        self.assertEqual(2, len(response))

    def test_getTestSuitesForTestPlan_noSuite(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getTestSuitesForTestPlan('noSuite')
        self.assertEqual([], response)
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
       
    def test_getTestSuitesForTestSuite_noSuite(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getTestSuitesForTestSuite('noSuite')
        self.assertEqual([], response)
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
        
    def test_getFirstLevelTestSuitesForTestProject_noSuite(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getFirstLevelTestSuitesForTestProject('noSuite')
        self.assertEqual([], response)
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
        
    def test_getTestCasesForTestSuite_noTestCase(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getTestCasesForTestSuite('noTestCase')
        self.assertEqual([], response)
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])

    def test_getTestCasesForTestSuite_keyWords(self):
        self.api.loadScenario(SCENARIO_KEYWORDS)
        response = self.api.getTestCasesForTestSuite('keyWords', details='full', 
                                                     getkeywords=True)
        self.assertIn('keywords', response[0])
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
           
    def test_whatArgs_getTestCasesForTestSuite(self):
        argsDescription = self.api.whatArgs('getTestCasesForTestSuite')
        self.assertIn('getkeywords=<getkeywords>', argsDescription)

    def test_getTestCasesForTestPlan_noTestCase(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getTestCasesForTestPlan('noTestCase')
        self.assertEqual([], response)
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
        
    def test_getTestCaseIDByName_dictResult(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getTestCaseIDByName('dictResult', 
                                            testprojectname='NEW_PROJECT_API')
        self.assertEqual(dict, type(response))
        self.assertEqual('TESTCASE_B', response['1']['name']) 
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
        
    def test_getTestCaseIDByName_listResult(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getTestCaseIDByName('listResult')
        self.assertEqual(list, type(response))
        self.assertEqual('TESTCASE_AA', response[0]['name']) 
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])

    def test_testLinkVersion_beforeTL199(self):
        self.api.loadScenario(SCENARIO_TL198)
        response = self.api.testLinkVersion()
        self.assertEqual('<= 1.9.8', response)
        
    def test_testLinkVersion_withTL199(self):
        self.api.loadScenario(SCENARIO_TL199)
        response = self.api.testLinkVersion()
        self.assertEqual('1.9.9', response)
        
    def test_connectionInfo_beforeTL199(self):
        self.api.loadScenario(SCENARIO_TL198)
        response = self.api.connectionInfo()
        self.assertRegex(response, '\d*\.\d*\.\d*')
        
    def test_getTestCaseCustomFieldDesignValue_notAssigned(self):
        self.api.loadScenario(SCENARIO_CUSTOM_FIELDS)
        with self.assertRaisesRegex(TLResponseError, '9003.*Custom Field.*not assigned'):
            response = self.api.getTestCaseCustomFieldDesignValue('GPROAPI8-2', 
                            1, '7760', 'cf_notAssigned', details='full')
            
    def test_getTestCaseCustomFieldDesignValue_full(self):
        self.api.loadScenario(SCENARIO_CUSTOM_FIELDS)
        response = self.api.getTestCaseCustomFieldDesignValue('GPROAPI8-2', 
                            1, '7760', 'cf_full', details='full') 
        self.assertEqual('a custom spec design string', response['value'])           
        self.assertEqual('1', response['enable_on_design'])           
        self.assertEqual('0', response['enable_on_testplan_design']) 
        self.assertEqual('0', response['enable_on_execution'])           

    def test_getTestCaseCustomFieldDesignValue_value(self):
        self.api.loadScenario(SCENARIO_CUSTOM_FIELDS)
        response = self.api.getTestCaseCustomFieldDesignValue('GPROAPI8-2', 
                            1, '7760', 'cf_value', details='value') 
        self.assertEqual('a custom spec design string', response)           

    def test_getTestCaseCustomFieldDesignValue_valueEmpty(self):
        self.api.loadScenario(SCENARIO_CUSTOM_FIELDS)
        response = self.api.getTestCaseCustomFieldDesignValue('GPROAPI8-2', 
                            1, '7760', 'cf_valueEmpty', details='value') 
        self.assertEqual('', response)   
                
    def test_getTestCaseCustomFieldDesignValue_simple(self):
        self.api.loadScenario(SCENARIO_CUSTOM_FIELDS)
        response = self.api.getTestCaseCustomFieldDesignValue('GPROAPI8-2', 
                            1, '7760', 'cf_simple', details='simple') 
        self.assertEqual('a custom spec design string', response['value'])           

    def test_updateTestCaseCustomFieldDesignValue_simple(self):
        self.api.loadScenario(SCENARIO_CUSTOM_FIELDS)
        response = self.api.updateTestCaseCustomFieldDesignValue('GPROAPI8-2', 
                            1, '7760', {'cf_field1'  : 'a_string'}) 
        self.assertEqual('', response)

    def test_getTestCaseCustomFieldExecutionValue_notAssigned(self):
        self.api.loadScenario(SCENARIO_CUSTOM_FIELDS)
        response = self.api.getTestCaseCustomFieldExecutionValue(
                                    'cf_notAssigned', '7760', 1, '792', '7761') 
        self.assertEqual(None, response)
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])

    def test_getTestCaseCustomFieldExecutionValue_full(self):
        self.api.loadScenario(SCENARIO_CUSTOM_FIELDS)
        response = self.api.getTestCaseCustomFieldExecutionValue(
                                        'cf_full', '7760', 1, '792', '7761') 
        self.assertEqual('a custom exec string', response['value'])           
        self.assertEqual('0', response['enable_on_design']) 
        self.assertEqual('0', response['enable_on_testplan_design']) 
        self.assertEqual('1', response['enable_on_execution'])           

    def test_getTestCaseCustomFieldTestPlanDesignValue_notAssigned(self):
        self.api.loadScenario(SCENARIO_CUSTOM_FIELDS)
        response = self.api.getTestCaseCustomFieldTestPlanDesignValue(
                                    'cf_notAssigned', '7760', 1, '7761', '779') 
        self.assertEqual(None, response)
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])

    def test_getTestCaseCustomFieldTestPlanDesignValue_full(self):
        self.api.loadScenario(SCENARIO_CUSTOM_FIELDS)
        response = self.api.getTestCaseCustomFieldTestPlanDesignValue(
                                        'cf_full', '7760', 1, '7761', '779') 
        self.assertEqual('a custom PlanDesign string', response['value'])           
        self.assertEqual('0', response['enable_on_design']) 
        self.assertEqual('1', response['enable_on_testplan_design']) 
        self.assertEqual('0', response['enable_on_execution'])           

    def test_getTestSuiteCustomFieldDesignValue_notAssigned(self):
        self.api.loadScenario(SCENARIO_CUSTOM_FIELDS)
        response = self.api.getTestSuiteCustomFieldDesignValue(
                                            'cf_notAssigned', '7760', '7762') 
        self.assertEqual(None, response)
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])

    def test_getTestSuiteCustomFieldDesignValue_full(self):
        self.api.loadScenario(SCENARIO_CUSTOM_FIELDS)
        response = self.api.getTestSuiteCustomFieldDesignValue(
                                                    'cf_full', '7760', '7762') 
        self.assertEqual('a custom TSuite string', response['value'])           
        self.assertEqual('1', response['enable_on_design']) 
        self.assertEqual('0', response['enable_on_testplan_design']) 
        self.assertEqual('0', response['enable_on_execution'])           

    def test_getTestPlanCustomFieldDesignValue_notAssigned(self):
        self.api.loadScenario(SCENARIO_CUSTOM_FIELDS)
        response = self.api.getTestPlanCustomFieldDesignValue(
                                            'cf_notAssigned', '7760', '7761') 
        self.assertEqual(None, response)
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])

    def test_getTestPlanCustomFieldDesignValue_full(self):
        self.api.loadScenario(SCENARIO_CUSTOM_FIELDS)
        response = self.api.getTestPlanCustomFieldDesignValue(
                                                    'cf_full', '7760', '7761') 
        self.assertEqual('a custom TPlan string', response['value'])           
        self.assertEqual('1', response['enable_on_design']) 
        self.assertEqual('0', response['enable_on_testplan_design']) 
        self.assertEqual('0', response['enable_on_execution'])           

    def test_getReqSpecCustomFieldDesignValue_notAssigned(self):
        self.api.loadScenario(SCENARIO_CUSTOM_FIELDS)
        response = self.api.getReqSpecCustomFieldDesignValue(
                                            'cf_notAssigned', '7760', '7789') 
        self.assertEqual(None, response)
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])

    def test_getReqSpecCustomFieldDesignValue_full(self):
        self.api.loadScenario(SCENARIO_CUSTOM_FIELDS)
        response = self.api.getReqSpecCustomFieldDesignValue(
                                                    'cf_full', '7760', '7789') 
        self.assertEqual('a custom ReqSpec string', response['value'])           
        self.assertEqual('1', response['enable_on_design']) 
        self.assertEqual('0', response['enable_on_testplan_design']) 
        self.assertEqual('0', response['enable_on_execution'])           

    def test_getRequirementCustomFieldDesignValue_notAssigned(self):
        self.api.loadScenario(SCENARIO_CUSTOM_FIELDS)
        response = self.api.getRequirementCustomFieldDesignValue(
                                            'cf_notAssigned', '7760', '7791') 
        self.assertEqual(None, response)
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])

    def test_getRequirementCustomFieldDesignValue_full(self):
        self.api.loadScenario(SCENARIO_CUSTOM_FIELDS)
        response = self.api.getRequirementCustomFieldDesignValue(
                                                    'cf_full', '7760', '7791') 
        self.assertEqual('a custom Req string', response['value'])           
        self.assertEqual('1', response['enable_on_design']) 
        self.assertEqual('0', response['enable_on_testplan_design']) 
        self.assertEqual('0', response['enable_on_execution'])   
        
    def test_reportTCResult_user(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.reportTCResult(4712, 'p', testcaseid=4711, 
                                    buildname='build 4713', notes='note 4714',
                                    user='******') 
        self.assertEqual('reportTCResult', response[0]['operation']) 
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
        self.assertEqual('a login name', self.api.callArgs['user'])
        
    def test_whatArgs_reportTCResult(self):
        argsDescription = self.api.whatArgs('reportTCResult')
        self.assertIn('user=<user>', argsDescription)
        
    def test_whatArgs_getLastExecutionResult(self):
        argsDescription = self.api.whatArgs('getLastExecutionResult')
        self.assertIn('options=<options>', argsDescription)
        self.assertIn('getBugs', argsDescription)

    def test__getAttachmentArgs_textfile(self):
        "py3 issue #39 TypeError: expected bytes-like object, not str"
        NEWATTACHMENT_PY= os.path.realpath(__file__)
        # under py2, on windows text files should be open with 'r' mode and 
        # binary files with 'rb' 
        # see http://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files
        # under py3, text files open with 'r' on windows makes problem
        # see https://github.com/lczub/TestLink-API-Python-client/issues/39
        a_file = open(NEWATTACHMENT_PY, BINARY_READ_MODE)
        args = self.api._getAttachmentArgs(a_file)
        self.assertEqual('testlinkapigeneric_offline_test.py', args['filename'])
        if sys.version_info[0] == 2 and sys.version_info[1] == 6:
            self.assertEqual('text/x-python', args['filetype'])
        else:
            self.assertEqual('text/plain', args['filetype'])

        self.assertIsNotNone(args['content'])
# precondition a)
# SERVER_URL and KEY are defined in environment
# TESTLINK_API_PYTHON_SERVER_URL=http://YOURSERVER/testlink/lib/api/xmlrpc.php
# TESTLINK_API_PYTHON_DEVKEY=7ec252ab966ce88fd92c25d08635672b
# 
# alternative precondition b)
# SERVEUR_URL and KEY are defined as command line arguments
# python TestLinkExample.py --server_url http://YOURSERVER/testlink/lib/api/xmlrpc.php
#                           --devKey 7ec252ab966ce88fd92c25d08635672b
#
# ATTENTION: With TestLink 1.9.7, cause of the new REST API, the SERVER_URL 
#            has changed from 
#               (old) http://YOURSERVER/testlink/lib/api/xmlrpc.php
#            to
#               (new) http://YOURSERVER/testlink/lib/api/xmlrpc/v1/xmlrpc.php
tl_helper = TestLinkHelper()
tl_helper.setParamsFromArgs('''Shows how to use the TestLinkAPI for CustomFields.
=> requires an existing project PROJECT_API_GENERIC-*''')
myTestLink = tl_helper.connect(TestlinkAPIGeneric) 

myPyVersion = python_version()
myPyVersionShort = myPyVersion.replace('.', '')[:2]

NEWTESTPLAN_A="TestPlan_API_GENERIC A"
# NEWTESTPLAN_B="TestPlan_API_GENERIC B"
# NEWTESTPLAN_C="TestPlan_API_GENERIC C - DeleteTest"
# NEWPLATFORM_A='Big Bird %s' % myPyVersionShort
NEWPLATFORM_B='Small Bird'
# NEWPLATFORM_C='Ugly Bird'
NEWTESTSUITE_A="A - First Level"
NEWTESTSUITE_B="B - First Level"
Ejemplo n.º 32
0
 def setUpClass(cls):
     cls.api = TestLinkHelper().connect(DummyAPIGeneric)
class TestLinkAPIOfflineTestCase(unittest.TestCase):
    """ TestCases for TestlinkAPIClient - does not interacts with a TestLink Server.
    works with DummyAPIClientm which returns special test data
    """

    example_steps = [{'step_number' : '1', 'actions' : "action A" , 
                'expected_results' : "result A", 'execution_type' : "0"},
                 {'step_number' : '2', 'actions' : "action B" , 
                'expected_results' : "result B", 'execution_type' : "1"},
                 {'step_number' : '3', 'actions' : "action C" , 
                'expected_results' : "result C", 'execution_type' : "0"}]
    def setUp(self):
        self.api = TestLinkHelper().connect(DummyAPIClient)

#    def tearDown(self):
#        pass


    def test_countProjects(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countProjects()
        self.assertEqual(2, response)
        
    def test_countTestPlans(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countTestPlans()
        self.assertEqual(2, response)
        
    def test_countTestSuites(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countTestSuites()
        self.assertEqual(0, response)
        
    def test_countTestCasesTP(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countTestCasesTP()
        self.assertEqual(0, response)
        
    def test_countTestCasesTS(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countTestCasesTS()
        self.assertEqual(0, response)

    def test_countPlatforms(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countPlatforms()
        self.assertEqual(2, response)
        
    def test_countBuilds(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countBuilds()
        self.assertEqual(0, response)

#    def test_listProjects(self):
#        self.api.loadScenario(SCENARIO_A)
#        self.api.listProjects()
#         no assert check cause method returns nothing
#         'just' prints to stdout
        
    def test_getProjectIDByName(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getProjectIDByName('NEW_PROJECT_API')
        self.assertEqual('21', response)
        response = self.api.getProjectIDByName('UNKNOWN_PROJECT')
        self.assertEqual(-1, response)
        
    def test_initStep(self):
        self.api.initStep("action A", "result A", 0)
        steps = self.example_steps[:1]
        self.assertEqual(steps, self.api.stepsList)
        
    def test_appendStep(self):
        steps = self.example_steps
        self.api.stepsList = steps[:1] 
        self.api.appendStep("action B", "result B", 1)
        self.api.appendStep("action C", "result C", 0)
        self.assertEqual(steps, self.api.stepsList)

    def test_createTestCaseWithSteps(self):
        self.api.loadScenario(SCENARIO_STEPS)
        self.api.initStep("action A", "result A", 0)
        self.api.appendStep("action B", "result B", 1)
        self.api.appendStep("action C", "result C", 0)
        self.api.createTestCase('case 4711', 4712, 4713, 'Big Bird', 
                                'summary 4714')
        self.assertEqual(self.example_steps, self.api.callArgs['steps'])
        self.assertEqual([], self.api.stepsList)
        
    def test_getTestCaseIDByName_dictResult(self):
        "test that getTestCaseIDByName converts dictionary result into a list"
        self.api.loadScenario(SCENARIO_A)
        # v0.4.0 version for optional args testsuitename + testprojectname
        #response = self.api.getTestCaseIDByName('dictResult', None, 'NEW_PROJECT_API')
        # v0.4.5 version
        response = self.api.getTestCaseIDByName('dictResult', 
                                            testprojectname='NEW_PROJECT_API')
        self.assertEqual(list, type(response))
        self.assertEqual('TESTCASE_B', response[0]['name']) 
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
        
    def test_getTestCaseIDByName_listResult(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getTestCaseIDByName('listResult')
        self.assertEqual(list, type(response))
        self.assertEqual('TESTCASE_AA', response[0]['name']) 
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
# precondition a)
# SERVER_URL and KEY are defined in environment
# TESTLINK_API_PYTHON_SERVER_URL=http://YOURSERVER/testlink/lib/api/xmlrpc.php
# TESTLINK_API_PYTHON_DEVKEY=7ec252ab966ce88fd92c25d08635672b
# 
# alternative precondition b)
# SERVEUR_URL and KEY are defined as command line arguments
# python TestLinkExample.py --server_url http://YOURSERVER/testlink/lib/api/xmlrpc.php
#                           --devKey 7ec252ab966ce88fd92c25d08635672b
#
# ATTENTION: With TestLink 1.9.7, cause of the new REST API, the SERVER_URL 
#            has changed from 
#               (old) http://YOURSERVER/testlink/lib/api/xmlrpc.php
#            to
#               (new) http://YOURSERVER/testlink/lib/api/xmlrpc/v1/xmlrpc.php
tl_helper = TestLinkHelper()
tl_helper.setParamsFromArgs('''Shows how to use the TestLinkAPI.
=> Counts and lists the Projects 
=> Create a new Project with the following structure:''')
myTestLink = tl_helper.connect(TestlinkAPIGeneric) 

myPyVersion = python_version()
myPyVersionShort = myPyVersion.replace('.', '')[:2]

NEWTESTPLAN_A="TestPlan_API_GENERIC A"
NEWTESTPLAN_B="TestPlan_API_GENERIC B"
NEWTESTPLAN_C="TestPlan_API_GENERIC C - DeleteTest"
NEWPLATFORM_A='Big Bird %s' % myPyVersionShort
NEWPLATFORM_B='Small Bird'
NEWPLATFORM_C='Ugly Bird'
NEWTESTSUITE_A="A - First Level"
class TestLinkAPIGenericOfflineTestCase(unittest.TestCase):
    """ TestCases for TestlinkAPIGeneric - does not interacts with a TestLink Server.
    works with DummyAPIGeneric which returns special test data
    """

    def setUp(self):
        self.api = TestLinkHelper().connect(DummyAPIGeneric)
        self.callArgs = None
        
#    def tearDown(self):
#        pass


    def test_convertPositionalArgs(self):
        response = self.api._convertPostionalArgs('DummyMethod',  [1,2,3])
        self.assertEqual({'Uno' : 1, 'due' :2, 'tre' : 3}, response)
        
    def test__convertPositionalArgs_missingConf(self):
        client = self.api
        def a_func(a_api): a_api._convertPostionalArgs('NoConfigMethod',  [1,2])
        self.assertRaises(TLArgError, a_func, client)
        
    def test__convertPositionalArgs_lessValues(self):
        client = self.api
        def a_func(a_api): a_api._convertPostionalArgs('DummyMethod',  [1,2])
        self.assertRaises(TLArgError, a_func, client)
        
    def test__convertPositionalArgs_moreValues(self):
        client = self.api
        def a_func(a_api): a_api._convertPostionalArgs('DummyMethod',  [1,2,3,4])
        self.assertRaises(TLArgError, a_func, client)

    def test_callServerWithPosArgs_pos(self):
        self.api.callServerWithPosArgs('DummyMethod',  1,2,3)
        self.assertEqual({'Uno' : 1, 'due' :2, 'tre' : 3}, self.api.callArgs)

    def test_callServerWithPosArgs_pos_opt(self):
        self.api.callServerWithPosArgs('DummyMethod',  1,2,3, quad=4)
        self.assertEqual({'Uno' : 1, 'due' :2, 'tre' : 3, 'quad' : 4}, self.api.callArgs)

    def test_callServerWithPosArgs_opt(self):
        self.api.callServerWithPosArgs('DummyMethod',  quad=4)
        self.assertEqual({'quad' : 4}, self.api.callArgs)

    def test_callServerWithPosArgs_none(self):
        self.api.callServerWithPosArgs('DummyMethod')
        self.assertEqual({}, self.api.callArgs)
        
    def test_checkResponse_emptyResponse(self):
        client = self.api
        def a_func(a_api, response): 
            a_api._checkResponse(response, 'DummyMethod',  
                                 {'Uno' : 1, 'due' :2, 'tre' : 3})
        self.assertRaises(TLResponseError, a_func, client, '')
        self.assertRaises(TLResponseError, a_func, client, [])
        
    def test_checkResponse_errorResponse(self):
        client = self.api
        responseA = [{'message': '(reportTCResult) - TC ID 709 does not exist!', 
                      'code': 5000}]
        def a_func(a_api, response): 
            a_api._checkResponse(response, 'DummyMethod',  
                                 {'Uno' : 1, 'due' :2, 'tre' : 3})
        self.assertRaises(TLResponseError, a_func, client, responseA)

    def test_checkResponse_okResponse(self):
        self.api._checkResponse(
                        [{'message': 'all fine, cause no key with name code'}],
                         'DummyMethod', {'Uno' : 1, 'due' :2, 'tre' : 3})
        self.api._checkResponse(
                        'some API Call juts returns one string without codes',
                         'DummyMethod', {'Uno' : 1, 'due' :2, 'tre' : 3})
        
    def test_checkResponse_booleanResponse(self):
        response = True
        self.api._checkResponse(response, 'DummyMethod', 
                                {'Uno' : 1, 'due' :2, 'tre' : 3})
        
    def test_checkResponse_dictionaryResponse(self):
        response = {'note' : 'uploadAttachment Calls return {..} and not [{..}]'}
        self.api._checkResponse(response, 'DummyMethod', 
                                {'Uno' : 1, 'due' :2, 'tre' : 3})
        
    def test_checkResponse_errorResponse_sringCode(self):
        client = self.api
        
        responseA = [{'message': '(getUserByID) - Cannot Find User with DB ID (4711).', 
                      'code': 'NO_USER_BY_ID_LOGIN'}]
        def a_func(a_api, response): 
            a_api._checkResponse(response, 'getUserByID',  
                                 {'userid' : 4711})
        self.assertRaises(TLResponseError, a_func, client, responseA)

    def test__apiMethodArgNames_noArgs(self):
        response = self.api._apiMethodArgNames('sayHello')
        self.assertEqual(response, ([], [], []))

    def test_whatArgs_noArgs(self):
        response = self.api.whatArgs('sayHello')
        self.assertRegexpMatches(response, 'sayHello().*')
        
    def test__apiMethodArgNames_onlyOptionalArgs(self):
        response = self.api._apiMethodArgNames('getTestCaseAttachments')
        self.assertEqual(response[0], [])
        self.assertGreater(len(response[1]), 0)
        self.assertEqual(response[2], [])

    def test_whatArgs_onlyOptionalArgs(self):
        response = self.api.whatArgs('getTestCaseAttachments')
        self.assertRegexpMatches(response, 'getTestCaseAttachments\(\[.*=<.*>\].*\).*')
        
    def test__apiMethodArgNames__OptionalAndPositionalArgs(self):
        response = self.api._apiMethodArgNames('createBuild')
        self.assertGreater(len(response[0]), 0)
        self.assertGreater(len(response[1]), 0)
        self.assertEqual(response[2], [])

    def test_whatArgs_OptionalAndPositionalArgs(self):
        response = self.api.whatArgs('createBuild')
        self.assertRegexpMatches(response, 'createBuild\(<.*>.*\).*')

    def test__apiMethodArgNames__MandatoryArgs(self):
        response = self.api._apiMethodArgNames('uploadExecutionAttachment')
        self.assertGreater(len(response[0]), 0)
        self.assertGreater(len(response[1]), 0)
        self.assertGreater(len(response[2]), 0)

    def test_whatArgs_MandatoryArgs(self):
        response = self.api.whatArgs('uploadExecutionAttachment')
        self.assertRegexpMatches(response, 
                    'uploadExecutionAttachment\(<attachmentfile>, <.*>.*\).*')

    def test_whatArgs_unknownMethods(self):
        response = self.api.whatArgs('apiUnknown')
        self.assertRegexpMatches(response, 
                "callServerWithPosArgs\('apiUnknown', \[apiArg=<apiArg>\]\)")
        
    def test_noWrapperName_apiMethods(self):
        " decorator test: API Methods internal function name should be unchanged "
        
        # apiMethod with decorator @decoApiCallWithoutArgs
        self.assertEqual('sayHello', self.api.sayHello.__name__)
        # apiMethod with decorator @decoApiCallWithArgs
        self.assertEqual('repeat', self.api.repeat.__name__)
        # apiMethod with decorator @decoApiCallAddDevKey 
        self.assertEqual('createBuild', self.api.createBuild.__name__)
        # apiMethod with decorator @decoMakerApiCallReplaceTLResponseError()
        self.assertEqual('getProjectTestPlans', self.api.getProjectTestPlans.__name__)
        # apiMethod with decorator @decoApiCallAddAttachment
        self.assertEqual('uploadExecutionAttachment', self.api.uploadExecutionAttachment.__name__)
        
    def test_ping(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.ping()
        self.assertEqual('Hey Folks!', response)
        
        
    def test_getProjectTestPlans_noPlan(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getProjectTestPlans('noPlan')
        self.assertEqual([], response)
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
        
    def test_getProjectTestPlans_onePlan(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getProjectTestPlans('onePlan')
        self.assertEqual('21', response[0]['testproject_id'])
        self.assertEqual(1, len(response))
        
    def test_getProjectPlatforms_noPlatform(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getProjectPlatforms('noPlatform')
        self.assertEqual({}, response)
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
        
    def test_getProjectPlatforms_twoPlatforms(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getProjectPlatforms('twoPlatforms')
        self.assertEqual('1', response['dutch']['id'])
        self.assertEqual(2, len(response))
        
        
    def test_getBuildsForTestPlan_noBuild(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getBuildsForTestPlan('noBuild')
        self.assertEqual([], response)
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
        
    def test_getTestPlanPlatforms_noPlatform(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getTestPlanPlatforms('noPlatform')
        self.assertEqual([], response)
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
        
    def test_getTestPlanPlatforms_twoPlatforms(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getTestPlanPlatforms('twoPlatforms')
        self.assertEqual('dutch', response[0]['name'])
        self.assertEqual(2, len(response))

    def test_getTestSuitesForTestPlan_noSuite(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getTestSuitesForTestPlan('noSuite')
        self.assertEqual([], response)
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
       
    def test_getTestSuitesForTestSuite_noSuite(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getTestSuitesForTestSuite('noSuite')
        self.assertEqual([], response)
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
        
    def test_getFirstLevelTestSuitesForTestProject_noSuite(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getFirstLevelTestSuitesForTestProject('noSuite')
        self.assertEqual([], response)
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
        
    def test_getTestCasesForTestSuite_noTestCase(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getTestCasesForTestSuite('noTestCase')
        self.assertEqual([], response)
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
           
    def test_getTestCasesForTestPlan_noTestCase(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getTestCasesForTestPlan('noTestCase')
        self.assertEqual([], response)
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
        
    def test_getTestCaseIDByName_dictResult(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getTestCaseIDByName('dictResult', 
                                            testprojectname='NEW_PROJECT_API')
        self.assertEqual(dict, type(response))
        self.assertEqual('TESTCASE_B', response['1']['name']) 
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
        
    def test_getTestCaseIDByName_listResult(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getTestCaseIDByName('listResult')
        self.assertEqual(list, type(response))
        self.assertEqual('TESTCASE_AA', response[0]['name']) 
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])

    def test_testLinkVersion_beforeTL199(self):
        self.api.loadScenario(SCENARIO_TL198)
        response = self.api.testLinkVersion()
        self.assertEqual('<= 1.9.8', response)
        
    def test_testLinkVersion_withTL199(self):
        self.api.loadScenario(SCENARIO_TL199)
        response = self.api.testLinkVersion()
        self.assertEqual('1.9.9', response)
        
    def test_connectionInfo_beforeTL199(self):
        self.api.loadScenario(SCENARIO_TL198)
        response = self.api.connectionInfo()
        self.assertRegexpMatches(response, '\d*\.\d*\.\d*')
class TestLinkAPIOnlineTestCase(unittest.TestCase):
    """ TestCases for TestlinkAPIClient - interacts with a TestLink Server.
    works with the example project NEW_PROJECT_API (see TestLinkExample.py)
    """

    def setUp(self):
        self.client = TestLinkHelper().connect(TestlinkAPIClient)

    #    def tearDown(self):
    #        pass

    def test_checkDevKey(self):
        response = self.client.checkDevKey()
        self.assertEqual(True, response)

    def test_about(self):
        response = self.client.about()
        self.assertIn("Testlink API", response)

    def test_ping(self):
        response = self.client.ping()
        self.assertEqual("Hello!", response)

    def test_echo(self):
        response = self.client.echo("Yellow Submarine")
        self.assertEqual("You said: Yellow Submarine", response)

    def test_doesUserExist_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "10000.*Big Bird"):
            self.client.doesUserExist("Big Bird")

    def test_getBuildsForTestPlan_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "3000.*40000711"):
            self.client.getBuildsForTestPlan(40000711)

    def test_getFirstLevelTestSuitesForTestProject_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "7000.*40000711"):
            self.client.getFirstLevelTestSuitesForTestProject(40000711)

    def test_getFullPath_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "getFullPath.*234"):
            self.client.getFullPath("40000711")

    def test_getLastExecutionResult_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "3000.*40000711"):
            self.client.getLastExecutionResult(40000711, 40000712)

    def test_getLatestBuildForTestPlan_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "3000.*40000711"):
            self.client.getLatestBuildForTestPlan(40000711)

    def test_getProjects(self):
        response = self.client.getProjects()
        self.assertIsNotNone(response)

    def test_getProjectTestPlans_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "7000.*40000711"):
            self.client.getProjectTestPlans(40000711)

    def test_getProjectPlatforms_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "7000.*40000711"):
            self.client.getProjectPlatforms(40000711)

    def test_getTestCase_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "5000.*40000711"):
            self.client.getTestCase(40000711)

    def test_getTestCase_unknownExternalID(self):
        with self.assertRaisesRegex(TLResponseError, "5040.*N-2"):
            self.client.getTestCase(testcaseexternalid="N-2")

    def test_getTestCaseAttachments_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "5000.*40000711"):
            self.client.getTestCaseAttachments(40000711)

    def test_getTestCaseCustomFieldDesignValue_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "7000.*40000711"):
            self.client.getTestCaseCustomFieldDesignValue("TC-40000712", 1, 40000711, "a_field", "a_detail")

    def test_getTestCaseIDByName_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "5030.*Cannot find"):
            self.client.getTestCaseIDByName("Big Bird")

    def test_getTestCasesForTestPlan_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "3000.*40000711"):
            self.client.getTestCasesForTestPlan(40000711)

    def test_getTestCasesForTestSuite_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "8000.*40000711"):
            self.client.getTestCasesForTestSuite(40000711, 2, "a_detail")

    def test_getTestPlanByName_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "7011.*40000711"):
            self.client.getTestPlanByName("project 40000711", "plan 40000712")

    def test_getTestPlanPlatforms_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "3000.*40000711"):
            self.client.getTestPlanPlatforms(40000711)

    def test_getTestProjectByName_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "7011.*40000711"):
            self.client.getTestProjectByName("project 40000711")

    def test_getTestSuiteByID_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "8000.*40000711"):
            self.client.getTestSuiteByID(40000711)

    def test_getTestSuitesForTestPlan_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "3000.*40000711"):
            self.client.getTestSuitesForTestPlan(40000711)

    def test_getTestSuitesForTestSuite_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "8000.*40000711"):
            self.client.getTestSuitesForTestSuite(40000711)

    def test_getTotalsForTestPlan_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "3000.*40000711"):
            self.client.getTotalsForTestPlan(40000711)

    def test_createTestProject_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "7001.*Empty name"):
            self.client.createTestProject("", "P40000711")

    def test_createBuild_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "3000.*40000711"):
            self.client.createBuild(40000711, "Build 40000712", "note 40000713")

    def test_createTestPlan_projectname_posArg_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "7011.*40000712"):
            self.client.createTestPlan("plan 40000711", "project 40000712")

    def test_createTestSuite_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "7000.*40000711"):
            self.client.createTestSuite(40000711, "suite 40000712", "detail 40000713")

    def test_createTestCase_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "7000.*40000713"):
            self.client.createTestCase("case 40000711", 40000712, 40000713, "Big Bird", "summary 40000714")

    def test_reportTCResult_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "5000.*40000711"):
            self.client.reportTCResult(40000711, 40000712, "build 40000713", "p", "note 40000714")

    def test_uploadExecutionAttachment_unknownID(self):
        attachemantFile = open(os.path.realpath(__file__), "r")
        with self.assertRaisesRegex(TLResponseError, "6004.*40000712"):
            self.client.uploadExecutionAttachment(attachemantFile, 40000712, "title 40000713", "descr. 40000714")

    def test_getProjectIDByName_unknownID(self):
        response = self.client.getProjectIDByName("project 40000711")
        self.assertEqual(-1, response)

    def test_createPlatform_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "7011.*40000711"):
            self.client.createPlatform("Project 40000711", "Platform 40000712", notes="note 40000713")

    def test_addTestCaseToTestPlan_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "7000.*40000711"):
            self.client.addTestCaseToTestPlan(40000711, 40000712, "N-40000713", 1)

    def test_updateTestCase_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "5040.*N-40000711"):
            self.client.updateTestCase("N-40000711", version=1)

    def test_createTestCaseSteps_unknownID(self):
        steps = [
            {
                "actions": "Step action 6 -b added by updateTestCase",
                "expected_results": "Step result 6 - b added",
                "step_number": 6,
                "execution_type": 1,
            }
        ]
        with self.assertRaisesRegex(TLResponseError, "5040.*N-40000711"):
            self.client.createTestCaseSteps("update", steps, testcaseexternalid="N-40000711", version=1)

    def test_deleteTestCaseSteps_unknownID(self):
        steps = [2, 8]
        with self.assertRaisesRegex(TLResponseError, "5040.*N-40000711"):
            self.client.deleteTestCaseSteps("N-40000711", steps, version=1)

    def test_uploadRequirementSpecificationAttachment_unknownID(self):
        attachemantFile = open(ATTACHMENT_EXAMPLE_TEXT, "r")
        with self.assertRaisesRegex(TLResponseError, "6004.*40000712"):
            self.client.uploadRequirementSpecificationAttachment(
                attachemantFile, 40000712, title="title 40000713", description="descr. 40000714"
            )

    def test_uploadRequirementAttachment_unknownID(self):
        attachemantFile = open(ATTACHMENT_EXAMPLE_TEXT, "r")
        with self.assertRaisesRegex(TLResponseError, "6004.*40000712"):
            self.client.uploadRequirementAttachment(
                attachemantFile, 40000712, title="title 40000713", description="descr. 40000714"
            )

    def test_uploadTestProjectAttachment_unknownID(self):
        attachemantFile = open(ATTACHMENT_EXAMPLE_TEXT, "r")
        with self.assertRaisesRegex(TLResponseError, "7000.*40000712"):
            self.client.uploadTestProjectAttachment(
                attachemantFile, 40000712, title="title 40000713", description="descr. 40000714"
            )

    def test_uploadTestSuiteAttachment_unknownID(self):
        attachemantFile = open(ATTACHMENT_EXAMPLE_TEXT, "r")
        with self.assertRaisesRegex(TLResponseError, "8000.*40000712"):
            self.client.uploadTestSuiteAttachment(
                attachemantFile, 40000712, title="title 40000713", description="descr. 40000714"
            )

    def test_uploadTestCaseAttachment_unknownID(self):
        attachemantFile = open(ATTACHMENT_EXAMPLE_TEXT, "r")
        with self.assertRaisesRegex(TLResponseError, "5000.*testcaseid"):
            self.client.uploadTestCaseAttachment(
                attachemantFile, 40000712, title="title 40000713", description="descr. 40000714"
            )

    def test_uploadAttachment_unknownID(self):
        attachemantFile = open(ATTACHMENT_EXAMPLE_TEXT, "r")
        with self.assertRaisesRegex(TLResponseError, "6004.*Invalid Foreign Key ID"):
            self.client.uploadAttachment(
                attachemantFile, "0000", "nodes_hierarchy", title="title 40000713", description="descr. 40000714"
            )

    def test_testLinkVersion(self):
        response = self.client.testLinkVersion()
        self.assertRegex(response, "\d*\.\d*\.\d*")

    def test_getUserByLogin_unknownKey(self):
        with self.assertRaisesRegex(TLResponseError, "10000.*User Login"):
            self.client.getUserByLogin(user="******")

    #     def test_setTestMode(self):
    #         response = self.client.setTestMode(True)
    #         self.assertTrue(response)
    #         response = self.client.setTestMode(False)
    #         self.assertTrue(response)

    def test_deleteExecution_unknownKey(self):
        try:
            response = self.client.deleteExecution(40000711)
            # case: TL configuration allows deletion of executions
            # response returns Success, even if executionID is unkown
            self.assertEqual(
                [{"status": True, "message": "Success!", "id": 40000711, "operation": "deleteExecution"}], response
            )
        except TLResponseError as tl_err:
            # case: TL configuration does not allow deletion of executions
            # Expects: 232: Configuration does not allow delete executions
            self.assertEqual(232, tl_err.code)

    def test_setTestCaseExecutionType_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "7000.*40000712"):
            self.client.setTestCaseExecutionType("N-40000711", 1, 40000712, 1)

    def test_assignRequirements_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "7000.*40000712"):
            self.client.assignRequirements(
                "N-40000711",
                40000712,
                [
                    {"req_spec": 40000713, "requirements": [40000714, 40000717]},
                    {"req_spec": 4723, "requirements": [4725]},
                ],
            )

    def test_getExecCountersByBuild_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "3000.*40000711"):
            self.client.getExecCountersByBuild(40000711)

    def test_getTestCaseCustomFieldExecutionValue_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "236.*version/executionid"):
            self.client.getTestCaseCustomFieldExecutionValue("cf_full", "40000711", 1, "715", "40000713")

    def test_getTestCaseCustomFieldTestPlanDesignValue_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "7000.*40000711"):
            self.client.getTestCaseCustomFieldTestPlanDesignValue("cf_full", "40000711", 1, "40000713", "615")

    def test_updateTestCaseCustomFieldDesignValue_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "7000.*40000711"):
            self.client.updateTestCaseCustomFieldDesignValue(
                "TC-40000712", 1, 40000711, {"cf_field1": "value1", "cf_field2": "value2"}
            )

    def test_getTestSuiteCustomFieldDesignValue_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "7000.*40000711"):
            self.client.getTestSuiteCustomFieldDesignValue("cf_full", 40000711, 40000713)

    def test_getTestPlanCustomFieldDesignValue_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "7000.*40000711"):
            self.client.getTestPlanCustomFieldDesignValue("cf_full", 40000711, 40000712)

    def test_getReqSpecCustomFieldDesignValue_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "7000.*40000711"):
            self.client.getReqSpecCustomFieldDesignValue("cf_full", 40000711, 4732)

    def test_getRequirementCustomFieldDesignValue_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "7000.*40000711"):
            self.client.getRequirementCustomFieldDesignValue("cf_full", 40000711, 4734)

    def test_assignTestCaseExecutionTask_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "3000.*40000711"):
            self.client.assignTestCaseExecutionTask(
                "username", 40000711, "TC-40000712", buildname="build 40000713", platformname="platform 40000714"
            )

    def test_getTestCaseBugs_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "3000.*40000711"):
            self.client.getTestCaseBugs(
                40000711, testcaseexternalid="TC-40000712", buildname="build 40000713", platformname="platform 40000714"
            )

    def test_getTestCaseAssignedTester_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "3000.*40000711"):
            self.client.getTestCaseAssignedTester(
                40000711, "TC-40000712", buildname="build 40000713", platformname="platform 40000714"
            )

    def test_unassignTestCaseExecutionTask_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "3000.*40000711"):
            self.client.unassignTestCaseExecutionTask(
                40000711,
                "TC-40000712",
                buildname="build 40000713",
                platformname="platform 40000714",
                user="******",
                action="unassignOne",
            )

    def test_getProjectKeywords_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "7000.*40000711"):
            self.client.getProjectKeywords(40000711)

    def test_getTestCaseKeywords_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "5040.*40000712"):
            self.client.getTestCaseKeywords(testcaseid=40000712)

    def test_getTestCaseKeywords_unknownID_set(self):
        with self.assertRaisesRegex(TLResponseError, "5040.*40000712"):
            self.client.getTestCaseKeywords(testcaseid=[40000712, 40000713])

    def test_getTestCaseKeywords_unknownID_external_single(self):
        with self.assertRaisesRegex(TLResponseError, "5040.*TC-40000712"):
            self.client.getTestCaseKeywords(testcaseexternalid="TC-40000712")

    def test_getTestCaseKeywords_unknownID_external_set(self):
        with self.assertRaisesRegex(TLResponseError, "5040.*TC-40000712"):
            self.client.getTestCaseKeywords(testcaseexternalid=["TC-40000712", "TC-40000713"])

    def test_deleteTestPlan_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "3000.*40000711"):
            self.client.deleteTestPlan(40000711)

    def test_addTestCaseKeywords_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "5040.*TC-40000712"):
            self.client.addTestCaseKeywords({"TC-40000712": ["KeyWord01", "KeyWord03"]})

    def test_removeTestCaseKeywords_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "5040.*TC-40000712"):
            self.client.removeTestCaseKeywords({"TC-40000712": ["KeyWord01"]})

    def test_deleteTestProject_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "7013.*TProjectPrefix"):
            self.client.deleteTestProject("TProjectPrefix")

    def test_createTestPlan_projectname_optArg_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "7011.*40000712"):
            self.client.createTestPlan("plan 40000711", testprojectname="project 40000712")

    def test_createTestPlan_prefix_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "NO.*TProjectPrefix"):
            self.client.createTestPlan("plan 40000713", prefix="TProjectPrefix")

    def test_updateTestSuiteCustomFieldDesignValue_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, "7000.*40000712"):
            self.client.updateTestSuiteCustomFieldDesignValue(
                "40000712 TP-ID", "40000711 TS-ID", {"cf_tc_ex_string": "a custom exec value", "cf_tc_ex_numeric": 111}
            )
 def test_callServer_withArgs(self):
     """ test _callServer() - calling method with args """
     
     client = TestLinkHelper().connect(TestlinkAPIClient)
     response = client._callServer('repeat', {'str' : 'some arg'})
     self.assertEqual('You said: some arg', response)
Ejemplo n.º 38
0
 def setUpClass(cls):
     cls.api = TestLinkHelper().connect(DummyAPIClient)
Ejemplo n.º 39
0
    def test_callServer_noArgs(self):
        """ test _callServer() - calling method with no args """

        client = TestLinkHelper().connect(TestlinkAPIClient)
        response = client._callServer('sayHello')
        self.assertEqual('Hello!', response)
Ejemplo n.º 40
0
class TestLinkAPIOnlineTestCase(unittest.TestCase):
    """ TestCases for TestlinkAPIClient - interacts with a TestLink Server.
    works with the example project NEW_PROJECT_API (see TestLinkExample.py)
    """
    def setUp(self):
        self.client = TestLinkHelper().connect(TestlinkAPIClient)

#    def tearDown(self):
#        pass

    def test_checkDevKey(self):
        response = self.client.checkDevKey()
        self.assertEqual(True, response)

    def test_about(self):
        response = self.client.about()
        self.assertIn('Testlink API', response)

    def test_ping(self):
        response = self.client.ping()
        self.assertEqual('Hello!', response)

    def test_echo(self):
        response = self.client.echo('Yellow Submarine')
        self.assertEqual('You said: Yellow Submarine', response)

    def test_doesUserExist_unknownID(self):
        response = self.client.doesUserExist('Big Bird')
        self.assertIn('Big Bird', response[0]['message'])
        self.assertEqual(10000, response[0]['code'])

    def test_getBuildsForTestPlan_unknownID(self):
        response = self.client.getBuildsForTestPlan(4711)
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(3000, response[0]['code'])

    def test_getFirstLevelTestSuitesForTestProject_unknownID(self):
        response = self.client.getFirstLevelTestSuitesForTestProject(4711)
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(7000, response[0]['code'])

    def test_getFullPath_unknownID(self):
        response = self.client.getFullPath(4711)
        self.assertIn('getFullPath', response[0]['message'])
        self.assertEqual(234, response[0]['code'])

    def test_getLastExecutionResult_unknownID(self):
        response = self.client.getLastExecutionResult(4711, 4712)
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(3000, response[0]['code'])

    def test_getLatestBuildForTestPlan_unknownID(self):
        response = self.client.getLatestBuildForTestPlan(4711)
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(3000, response[0]['code'])

    def test_getProjects(self):
        response = self.client.getProjects()
        self.assertIsNotNone(response)

    def test_getProjectTestPlans_unknownID(self):
        response = self.client.getProjectTestPlans(4711)
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(7000, response[0]['code'])

    def test_getTestCase_unknownID(self):
        response = self.client.getTestCase(4711)
        # FAILURE in 1.9.3 API message: replacement does not work
        # The Test Case ID (testcaseid: %s) provided does not exist!
        #self.assertIn('4711', response[0]['message'])
        self.assertEqual(5000, response[0]['code'])

    def test_getTestCaseAttachments_unknownID(self):
        response = self.client.getTestCaseAttachments(4711)
        # FAILURE in 1.9.3 API message: replacement does not work
        # The Test Case ID (testcaseid: %s) provided does not exist!
        #self.assertIn('4711', response[0]['message'])
        self.assertEqual(5000, response[0]['code'])

    def test_getTestCaseCustomFieldDesignValue_unknownID(self):
        response = self.client.getTestCaseCustomFieldDesignValue(
            4712, 1, 4711, 'a_field', 'a_detail')
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(7000, response[0]['code'])

    def test_getTestCaseIDByName_unknownID(self):
        response = self.client.getTestCaseIDByName('Big Bird')
        self.assertIn('getTestCaseIDByName', response[0]['message'])
        self.assertEqual(5030, response[0]['code'])

    def test_getTestCasesForTestPlan_unknownID(self):
        response = self.client.getTestCasesForTestPlan(4711)
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(3000, response[0]['code'])

    def test_getTestCasesForTestSuite_unknownID(self):
        response = self.client.getTestCasesForTestSuite(4711, 2, 'a_detail')
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(8000, response[0]['code'])

    def test_getTestPlanByName_unknownID(self):
        response = self.client.getTestPlanByName('project 4711', 'plan 4712')
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(7011, response[0]['code'])

    def test_getTestPlanPlatforms_unknownID(self):
        response = self.client.getTestPlanPlatforms(4711)
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(3000, response[0]['code'])

    def test_getTestProjectByName_unknownID(self):
        response = self.client.getTestProjectByName('project 4711')
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(7011, response[0]['code'])

    def test_getTestSuiteByID_unknownID(self):
        response = self.client.getTestSuiteByID(4711)
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(8000, response[0]['code'])

    def test_getTestSuitesForTestPlan_unknownID(self):
        response = self.client.getTestSuitesForTestPlan(4711)
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(3000, response[0]['code'])

    def test_getTestSuitesForTestSuite_unknownID(self):
        response = self.client.getTestSuitesForTestSuite(4711)
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(8000, response[0]['code'])

    def test_getTotalsForTestPlan_unknownID(self):
        response = self.client.getTotalsForTestPlan(4711)
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(3000, response[0]['code'])

    def test_createTestProject_unknownID(self):
        response = self.client.createTestProject('', 'P4711')
        self.assertIn('Empty name', response[0]['message'])
        self.assertEqual(7001, response[0]['code'])

    def test_createBuild_unknownID(self):
        response = self.client.createBuild(4711, 'Build 4712', 'note 4713')
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(3000, response[0]['code'])

    def test_createTestPlan_unknownID(self):
        response = self.client.createTestPlan('plan 4711', 'project 4712')
        self.assertIn('4712', response[0]['message'])
        self.assertEqual(7011, response[0]['code'])

    def test_createTestSuite_unknownID(self):
        response = self.client.createTestSuite(4711, 'suite 4712',
                                               'detail 4713')
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(7000, response[0]['code'])

    def test_createTestCase_unknownID(self):
        response = self.client.createTestCase('case 4711', 4712, 4713,
                                              'Big Bird', 'summary 4714')
        self.assertIn('4713', response[0]['message'])
        self.assertEqual(7000, response[0]['code'])

    def test_reportTCResult_unknownID(self):
        response = self.client.reportTCResult(4711, 4712, 'build 4713', 'p',
                                              'note 4714')
        # FAILURE in 1.9.3 API message: replacement does not work
        # The Test Case ID (testcaseid: %s) provided does not exist!
        #self.assertIn('4711', response[0]['message'])
        self.assertEqual(5000, response[0]['code'])


#    def test_uploadExecutionAttachment_unknownID(self):
#        response = self.client.uploadExecutionAttachment('file 4711', 4712,
#                        'title 4713', 'descr. 4714')
#        self.assertIn('4711', response[0]['message'])

    def test_getProjectIDByName_unknownID(self):
        response = self.client.getProjectIDByName('project 4711')
        self.assertEqual(-1, response)
class TestLinkAPIOnlineTestCase(unittest.TestCase):
    """ TestCases for TestlinkAPIClient - interacts with a TestLink Server.
    works with the example project NEW_PROJECT_API (see TestLinkExample.py)
    """

    def setUp(self):
        self.client = TestLinkHelper().connect(TestlinkAPIClient)


#    def tearDown(self):
#        pass


    def test_checkDevKey(self):
        response = self.client.checkDevKey()
        self.assertEqual(True, response)
        
    def test_about(self):
        response = self.client.about()
        self.assertIn('Testlink API', response)

    def test_ping(self):
        response = self.client.ping()
        self.assertEqual('Hello!', response)

    def test_echo(self):
        response = self.client.echo('Yellow Submarine')
        self.assertEqual('You said: Yellow Submarine', response)
        
    def test_doesUserExist_unknownID(self):
        response = self.client.doesUserExist('Big Bird')
        self.assertIn('Big Bird', response[0]['message'])
        self.assertEqual(10000, response[0]['code'])
        
    def test_getBuildsForTestPlan_unknownID(self):
        response = self.client.getBuildsForTestPlan(4711)
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(3000, response[0]['code'])
        
    def test_getFirstLevelTestSuitesForTestProject_unknownID(self):
        response = self.client.getFirstLevelTestSuitesForTestProject(4711)
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(7000, response[0]['code'])

    def test_getFullPath_unknownID(self):
        response = self.client.getFullPath(4711)
        self.assertIn('getFullPath', response[0]['message'])
        self.assertEqual(234, response[0]['code'])

    def test_getLastExecutionResult_unknownID(self):
        response = self.client.getLastExecutionResult(4711, 4712)
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(3000, response[0]['code'])
        
    def test_getLatestBuildForTestPlan_unknownID(self):
        response = self.client.getLatestBuildForTestPlan(4711)
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(3000, response[0]['code'])
        
    def test_getProjects(self):
        response = self.client.getProjects()
        self.assertIsNotNone(response)
        
    def test_getProjectTestPlans_unknownID(self):
        response = self.client.getProjectTestPlans(4711)
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(7000, response[0]['code'])
        
    def test_getTestCase_unknownID(self):
        response = self.client.getTestCase(4711)
        # FAILURE in 1.9.3 API message: replacement does not work
        # The Test Case ID (testcaseid: %s) provided does not exist!
        #self.assertIn('4711', response[0]['message'])
        self.assertEqual(5000, response[0]['code'])
        
    def test_getTestCaseAttachments_unknownID(self):
        response = self.client.getTestCaseAttachments(4711)
        # FAILURE in 1.9.3 API message: replacement does not work
        # The Test Case ID (testcaseid: %s) provided does not exist!
        #self.assertIn('4711', response[0]['message'])
        self.assertEqual(5000, response[0]['code'])
        
    def test_getTestCaseCustomFieldDesignValue_unknownID(self):
        response = self.client.getTestCaseCustomFieldDesignValue(
                   4712, 1, 4711, 'a_field', 'a_detail')
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(7000, response[0]['code'])
        
    def test_getTestCaseIDByName_unknownID(self):
        response = self.client.getTestCaseIDByName('Big Bird')
        self.assertIn('getTestCaseIDByName', response[0]['message'])
        self.assertEqual(5030, response[0]['code'])

    def test_getTestCasesForTestPlan_unknownID(self):
        response = self.client.getTestCasesForTestPlan(4711)
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(3000, response[0]['code'])

    def test_getTestCasesForTestSuite_unknownID(self):
        response = self.client.getTestCasesForTestSuite(4711, 2, 'a_detail')
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(8000, response[0]['code'])

    def test_getTestPlanByName_unknownID(self):
        response = self.client.getTestPlanByName('project 4711', 'plan 4712')
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(7011, response[0]['code'])

    def test_getTestPlanPlatforms_unknownID(self):
        response = self.client.getTestPlanPlatforms(4711)
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(3000, response[0]['code'])

    def test_getTestProjectByName_unknownID(self):
        response = self.client.getTestProjectByName('project 4711')
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(7011, response[0]['code'])

    def test_getTestSuiteByID_unknownID(self):
        response = self.client.getTestSuiteByID(4711)
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(8000, response[0]['code'])

    def test_getTestSuitesForTestPlan_unknownID(self):
        response = self.client.getTestSuitesForTestPlan(4711)
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(3000, response[0]['code'])

    def test_getTestSuitesForTestSuite_unknownID(self):
        response = self.client.getTestSuitesForTestSuite(4711)
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(8000, response[0]['code'])

    def test_getTotalsForTestPlan_unknownID(self):
        response = self.client.getTotalsForTestPlan(4711)
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(3000, response[0]['code'])

    def test_createTestProject_unknownID(self):
        response = self.client.createTestProject('', 'P4711')
        self.assertIn('Empty name', response[0]['message'])
        self.assertEqual(7001, response[0]['code'])

    def test_createBuild_unknownID(self):
        response = self.client.createBuild(4711, 'Build 4712', 'note 4713')
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(3000, response[0]['code'])

    def test_createTestPlan_unknownID(self):
        response = self.client.createTestPlan('plan 4711', 'project 4712')
        self.assertIn('4712', response[0]['message'])
        self.assertEqual(7011, response[0]['code'])

    def test_createTestSuite_unknownID(self):
        response = self.client.createTestSuite( 4711, 'suite 4712', 'detail 4713')
        self.assertIn('4711', response[0]['message'])
        self.assertEqual(7000, response[0]['code'])

    def test_createTestCase_unknownID(self):
        response = self.client.createTestCase('case 4711', 4712, 4713, 
                                               'Big Bird', 'summary 4714')
        self.assertIn('4713', response[0]['message'])
        self.assertEqual(7000, response[0]['code'])

    def test_reportTCResult_unknownID(self):
        response = self.client.reportTCResult(4711, 4712, 'build 4713', 'p', 
                                              'note 4714')
        # FAILURE in 1.9.3 API message: replacement does not work
        # The Test Case ID (testcaseid: %s) provided does not exist!
        #self.assertIn('4711', response[0]['message'])
        self.assertEqual(5000, response[0]['code'])

#    def test_uploadExecutionAttachment_unknownID(self):
#        response = self.client.uploadExecutionAttachment('file 4711', 4712, 
#                        'title 4713', 'descr. 4714')
#        self.assertIn('4711', response[0]['message'])

    def test_getProjectIDByName_unknownID(self):
        response = self.client.getProjectIDByName('project 4711')
        self.assertEqual(-1, response)
class TestLinkAPIOnlineTestCase(unittest.TestCase):
    """ TestCases for TestlinkAPIClient - interacts with a TestLink Server.
    works with the example project NEW_PROJECT_API (see TestLinkExample.py)
    """

    def setUp(self):
        self.client = TestLinkHelper().connect(TestlinkAPIGeneric)

#    def tearDown(self):
#        pass

    def test_checkDevKey(self):
        response = self.client.checkDevKey()
        self.assertEqual(True, response)
        
    def test_checkDevKey_unknownKey(self):
        with self.assertRaisesRegexp(TLResponseError, '2000.*invalid'):
            self.client.checkDevKey(devKey='unknownKey')
        
    def test_sayHello(self):
        response = self.client.sayHello()
        self.assertEqual('Hello!', response)

    def test_repeat(self):
        response = self.client.repeat('Yellow Submarine')
        self.assertEqual('You said: Yellow Submarine', response)
        
    def test_about(self):
        response = self.client.about()
        self.assertIn('Testlink API', response)

    def test_doesUserExist_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '10000.*Big Bird'):
            self.client.doesUserExist('Big Bird')
        
    def test_createTestProject_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7001.*Empty name'):
            self.client.createTestProject(testprojectname='', 
                                                 testcaseprefix='P4711')
 
    def test_getProjects(self):
        response = self.client.getProjects()
        self.assertIsNotNone(response)
         
    def test_createTestPlan_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7011.*4712'):
            self.client.createTestPlan('plan 4711', 'project 4712')
 
    def test_createTestSuite_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7000.*4711'):
            self.client.createTestSuite( 4711, 'suite 4712', 'detail 4713')
        
    def test_createTestCase_unknownID(self):
        tc_steps = []
        with self.assertRaisesRegexp(TLResponseError, '7000.*4713'):
            self.client.createTestCase('case 4711', 4712, 4713, 
                                        'Big Bird', 'summary 4714', tc_steps)
 
    def test_getBuildsForTestPlan_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.getBuildsForTestPlan(4711)
         
    def test_getFirstLevelTestSuitesForTestProject_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7000.*4711'):
            self.client.getFirstLevelTestSuitesForTestProject(4711)
 
    def test_getFullPath_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, 'getFullPath.*234'):
            self.client.getFullPath('4711')
 
    def test_getLastExecutionResult_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.getLastExecutionResult(4711, testcaseid=4712)
         
    def test_getLatestBuildForTestPlan_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.getLatestBuildForTestPlan(4711)
         
    def test_getProjectTestPlans_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7000.*4711'):
            self.client.getProjectTestPlans(4711)
         
    def test_getTestCase_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '5000.*4711'):
            self.client.getTestCase(testcaseid=4711)
         
    def test_getTestCase_unknownExternalID(self):
        with self.assertRaisesRegexp(TLResponseError, '5040.*GPROAPI-4711'):
            self.client.getTestCase(testcaseexternalid='GPROAPI-4711')
         
    def test_getTestCaseAttachments_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '5000.*4711'):
            self.client.getTestCaseAttachments(testcaseid=4711)
         
    def test_getTestCaseCustomFieldDesignValue_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7000.*4711'):
            self.client.getTestCaseCustomFieldDesignValue(
                   'TC-4712', 1, 4711, 'a_field', details='a_detail')
         
    def test_getTestCaseIDByName_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '5030.*Cannot find'):
            self.client.getTestCaseIDByName('Big Bird')
 
    def test_getTestCasesForTestPlan_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.getTestCasesForTestPlan(4711)
 
    def test_getTestCasesForTestSuite_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '8000.*4711'):
            self.client.getTestCasesForTestSuite(4711)
 
    def test_getTestPlanByName_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7011.*4711'):
            self.client.getTestPlanByName('project 4711', 'plan 4712')
 
    def test_getTestPlanPlatforms_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.getTestPlanPlatforms(4711)
 
    def test_getTestProjectByName_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7011.*4711'):
            self.client.getTestProjectByName('project 4711')
 
    def test_getTestSuiteByID_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '8000.*4711'):
            self.client.getTestSuiteByID(4711)
 
    def test_getTestSuitesForTestPlan_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.getTestSuitesForTestPlan(4711)
 
    def test_getTestSuitesForTestSuite_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '8000.*4711'):
            self.client.getTestSuitesForTestSuite(4711)
 
    def test_getTotalsForTestPlan_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.getTotalsForTestPlan(4711)
 
    def test_createBuild_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.createBuild(4711, 'Build 4712', buildnotes='note 4713')
 
    def test_reportTCResult_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '5000.*4711'):
            self.client.reportTCResult(4712, 'p', testcaseid=4711, 
                                       buildname='build 4713', notes='note 4714' )
 
    def test_uploadExecutionAttachment_unknownID(self):
        attachemantFile = open(os.path.realpath(__file__), 'r')
        with self.assertRaisesRegexp(TLResponseError, '6004.*4712'):
            self.client.uploadExecutionAttachment(attachemantFile, 4712, 
                        title='title 4713', description='descr. 4714')
class TestLinkAPIOnlineTestCase(unittest.TestCase):
    """ TestCases for TestlinkAPIClient - interacts with a TestLink Server.
    works with the example project NEW_PROJECT_API (see TestLinkExample.py)
    """

    def setUp(self):
        self.client = TestLinkHelper().connect(TestlinkAPIClient)


#    def tearDown(self):
#        pass


    def test_checkDevKey(self):
        response = self.client.checkDevKey()
        self.assertEqual(True, response)
        
    def test_about(self):
        response = self.client.about()
        self.assertIn('Testlink API', response)

    def test_ping(self):
        response = self.client.ping()
        self.assertEqual('Hello!', response)

    def test_echo(self):
        response = self.client.echo('Yellow Submarine')
        self.assertEqual('You said: Yellow Submarine', response)
        
    def test_doesUserExist_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '10000.*Big Bird'):
            self.client.doesUserExist('Big Bird')
        
    def test_getBuildsForTestPlan_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.getBuildsForTestPlan(4711)
        
    def test_getFirstLevelTestSuitesForTestProject_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7000.*4711'):
            self.client.getFirstLevelTestSuitesForTestProject(4711)

    def test_getFullPath_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, 'getFullPath.*234'):
            self.client.getFullPath('4711')

    def test_getLastExecutionResult_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.getLastExecutionResult(4711, 4712)
        
    def test_getLatestBuildForTestPlan_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.getLatestBuildForTestPlan(4711)
        
    def test_getProjects(self):
        response = self.client.getProjects()
        self.assertIsNotNone(response)
        
    def test_getProjectTestPlans_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7000.*4711'):
            self.client.getProjectTestPlans(4711)

    def test_getProjectPlatforms_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7000.*4711'):
            self.client.getProjectPlatforms(4711)
        
    def test_getTestCase_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '5000.*4711'):
            self.client.getTestCase(4711)
        
    def test_getTestCase_unknownExternalID(self):
        with self.assertRaisesRegexp(TLResponseError, '5040.*N-2'):
            self.client.getTestCase(testcaseexternalid='N-2')
        
    def test_getTestCaseAttachments_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '5000.*4711'):
            self.client.getTestCaseAttachments(4711)
        
    def test_getTestCaseCustomFieldDesignValue_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7000.*4711'):
            self.client.getTestCaseCustomFieldDesignValue(
                   'TC-4712', 1, 4711, 'a_field', 'a_detail')
        
    def test_getTestCaseIDByName_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '5030.*Cannot find'):
            self.client.getTestCaseIDByName('Big Bird')

    def test_getTestCasesForTestPlan_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.getTestCasesForTestPlan(4711)

    def test_getTestCasesForTestSuite_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '8000.*4711'):
            self.client.getTestCasesForTestSuite(4711, 2, 'a_detail')

    def test_getTestPlanByName_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7011.*4711'):
            self.client.getTestPlanByName('project 4711', 'plan 4712')

    def test_getTestPlanPlatforms_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.getTestPlanPlatforms(4711)

    def test_getTestProjectByName_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7011.*4711'):
            self.client.getTestProjectByName('project 4711')

    def test_getTestSuiteByID_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '8000.*4711'):
            self.client.getTestSuiteByID(4711)

    def test_getTestSuitesForTestPlan_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.getTestSuitesForTestPlan(4711)

    def test_getTestSuitesForTestSuite_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '8000.*4711'):
            self.client.getTestSuitesForTestSuite(4711)

    def test_getTotalsForTestPlan_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.getTotalsForTestPlan(4711)

    def test_createTestProject_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7001.*Empty name'):
            self.client.createTestProject('', 'P4711')

    def test_createBuild_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.createBuild(4711, 'Build 4712', 'note 4713')

    def test_createTestPlan_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7011.*4712'):
            self.client.createTestPlan('plan 4711', 'project 4712')

    def test_createTestSuite_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7000.*4711'):
            self.client.createTestSuite( 4711, 'suite 4712', 'detail 4713')

    def test_createTestCase_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7000.*4713'):
            self.client.createTestCase('case 4711', 4712, 4713, 
                                               'Big Bird', 'summary 4714')

    def test_reportTCResult_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '5000.*4711'):
            self.client.reportTCResult(4711, 4712, 'build 4713', 'p', 
                                              'note 4714')

    def test_uploadExecutionAttachment_unknownID(self):
        attachemantFile = open(os.path.realpath(__file__), 'r')
        with self.assertRaisesRegexp(TLResponseError, '6004.*4712'):
            self.client.uploadExecutionAttachment(attachemantFile, 4712, 
                        'title 4713', 'descr. 4714')

    def test_getProjectIDByName_unknownID(self):
        response = self.client.getProjectIDByName('project 4711')
        self.assertEqual(-1, response)
        
    def test_createPlatform_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7011.*4711'):
            self.client.createPlatform('Project 4711', 'Platform 4712', 
                                       notes='note 4713')
        
    def test_addTestCaseToTestPlan_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7000.*4711'):
            self.client.addTestCaseToTestPlan(4711, 4712, 'N-4713', 1)
            
    def test_updateTestCase_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '5040.*N-4711'):
            self.client.updateTestCase('N-4711', version=1)

    def test_createTestCaseSteps_unknownID(self):
        steps = [{'actions' : "Step action 6 -b added by updateTestCase" , 
                  'expected_results' : "Step result 6 - b added", 
                  'step_number' : 6, 'execution_type' : 1}]
        with self.assertRaisesRegexp(TLResponseError, '5040.*N-4711'):
            self.client.createTestCaseSteps('update', steps, 
                                        testcaseexternalid='N-4711', version=1)
            
    def test_deleteTestCaseSteps_unknownID(self):
        steps = [2,8]
        with self.assertRaisesRegexp(TLResponseError, '5040.*N-4711'):
            self.client.deleteTestCaseSteps('N-4711', steps, version=1)

    def test_uploadRequirementSpecificationAttachment_unknownID(self):
        attachemantFile = open(os.path.realpath(__file__), 'r')
        with self.assertRaisesRegexp(TLResponseError, '6004.*4712'):
            self.client.uploadRequirementSpecificationAttachment(attachemantFile, 4712, 
                        title='title 4713', description='descr. 4714')
 
    def test_uploadRequirementAttachment_unknownID(self):
        attachemantFile = open(os.path.realpath(__file__), 'r')
        with self.assertRaisesRegexp(TLResponseError, '6004.*4712'):
            self.client.uploadRequirementAttachment(attachemantFile, 4712, 
                        title='title 4713', description='descr. 4714')
 
    def test_uploadTestProjectAttachment_unknownID(self):
        attachemantFile = open(os.path.realpath(__file__), 'r')
        with self.assertRaisesRegexp(TLResponseError, '7000.*4712'):
            self.client.uploadTestProjectAttachment(attachemantFile, 4712, 
                        title='title 4713', description='descr. 4714')
 
    def test_uploadTestSuiteAttachment_unknownID(self):
        attachemantFile = open(os.path.realpath(__file__), 'r')
        with self.assertRaisesRegexp(TLResponseError, '8000.*4712'):
            self.client.uploadTestSuiteAttachment(attachemantFile, 4712, 
                        title='title 4713', description='descr. 4714')
 
    def test_uploadTestCaseAttachment_unknownID(self):
        attachemantFile = open(os.path.realpath(__file__), 'r')
        with self.assertRaisesRegexp(TLResponseError, '5000.*testcaseid'):
            self.client.uploadTestCaseAttachment(attachemantFile, 4712, 
                        title='title 4713', description='descr. 4714')
 
    def test_uploadAttachment_unknownID(self):
        attachemantFile = open(os.path.realpath(__file__), 'r')
        with self.assertRaisesRegexp(TLResponseError, '6004.*4712'):
            self.client.uploadAttachment(attachemantFile, 4712, 'nodes_hierarchy',
                        title='title 4713', description='descr. 4714')

    def test_testLinkVersion(self):
        response = self.client.testLinkVersion()
        self.assertRegexpMatches(response, '\d*\.\d*\.\d*')

    def test_getUserByLogin_unknownKey(self):
        with self.assertRaisesRegexp(TLResponseError, '10000.*User Login'):
            self.client.getUserByLogin(user='******')
            
#     def test_setTestMode(self):
#         response = self.client.setTestMode(True)
#         self.assertTrue(response)
#         response = self.client.setTestMode(False)
#         self.assertTrue(response)
            
    def test_deleteExecution_unknownKey(self):
        try:
            response = self.client.deleteExecution(4711)
            # case: TL configuration allows deletion of executions
            # response returns Success, even if executionID is unkown
            self.assertEqual([{'status': True, 'message': 'Success!', 'id': 4711, 
                               'operation': 'deleteExecution'}], response)
        except TLResponseError as tl_err:
            # case: TL configuration does not allow deletion of executions
            # Expects: 232: Configuration does not allow delete executions
            self.assertEqual(232, tl_err.code)
            
    def test_setTestCaseExecutionType_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7000.*4712'):
            self.client.setTestCaseExecutionType('N-4711', 1, 4712, 1)

    def test_assignRequirements_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7000.*4712'):
            self.client.assignRequirements('N-4711', 4712, 
                        [{'req_spec' : 4713, 'requirements' : [4714, 4717]}, 
                         {'req_spec' : 4723, 'requirements' : [4725]}])
            
    def test_getExecCountersByBuild_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.getExecCountersByBuild(4711)

    def test_assignTestCaseExecutionTask_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.assignTestCaseExecutionTask('username', 4711, 'TC-4712', 
                                            buildname='build 4713', 
                                            platformname='platform 4714')                         
            
    def test_getTestCaseBugs_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.getTestCaseBugs(4711, testcaseexternalid='TC-4712', 
                                        buildname='build 4713',
                                        platformname='platform 4714')                         
                                  
    def test_getTestCaseAssignedTester_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.getTestCaseAssignedTester(4711, 'TC-4712', 
                                            buildname='build 4713', 
                                            platformname='platform 4714') 
class TestLinkAPIGenericOnlineTestCase(unittest.TestCase):
    """ TestCases for TestlinkAPIClient - interacts with a TestLink Server.
    works with the example project NEW_PROJECT_API (see TestLinkExample.py)
    """

    def setUp(self):
        self.client = TestLinkHelper().connect(TestlinkAPIGeneric)

#    def tearDown(self):
#        pass

    def test_checkDevKey(self):
        response = self.client.checkDevKey()
        self.assertEqual(True, response)
        
    def test_checkDevKey_unknownKey(self):
        with self.assertRaisesRegex(TLResponseError, '2000.*invalid'):
            self.client.checkDevKey(devKey='unknownKey')
        
    def test_sayHello(self):
        response = self.client.sayHello()
        self.assertEqual('Hello!', response)

    def test_repeat(self):
        response = self.client.repeat('Yellow Submarine')
        self.assertEqual('You said: Yellow Submarine', response)
        
    def test_about(self):
        response = self.client.about()
        self.assertIn('Testlink API', response)

    def test_doesUserExist_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '10000.*Big Bird'):
            self.client.doesUserExist('Big Bird')
        
    def test_createTestProject_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '7001.*Empty name'):
            self.client.createTestProject(testprojectname='', 
                                                 testcaseprefix='P40000711')
 
    def test_createTestProject_unknownITS(self):
        with self.assertRaisesRegex(TLResponseError, '13000.*Unable to find'):
            self.client.createTestProject(testprojectname='aProject', 
                                testcaseprefix='aPrefix', itsname='unknownITS')
 
    def test_getProjects(self):
        response = self.client.getProjects()
        self.assertIsNotNone(response)
         
    def test_createTestPlan_projectname_posArg_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '7011.*40000712'):
            self.client.createTestPlan('plan 40000711', 'project 40000712')
 
    def test_createTestSuite_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '7000.*40000711'):
            self.client.createTestSuite( 40000711, 'suite 40000712', 'detail 40000713')
        
    def test_createTestCase_unknownID(self):
        tc_steps = []
        with self.assertRaisesRegex(TLResponseError, '7000.*40000713'):
            self.client.createTestCase('case 40000711', 40000712, 40000713, 
                                        'Big Bird', 'summary 40000714', tc_steps)
 
    def test_getBuildsForTestPlan_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '3000.*40000711'):
            self.client.getBuildsForTestPlan(40000711)
         
    def test_getFirstLevelTestSuitesForTestProject_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '7000.*40000711'):
            self.client.getFirstLevelTestSuitesForTestProject(40000711)
 
    def test_getFullPath_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, 'getFullPath.*234'):
            self.client.getFullPath('40000711')
 
    def test_getLastExecutionResult_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '3000.*40000711'):
            self.client.getLastExecutionResult(40000711, testcaseid=40000712)
         
    def test_getLatestBuildForTestPlan_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '3000.*40000711'):
            self.client.getLatestBuildForTestPlan(40000711)
         
    def test_getProjectTestPlans_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '7000.*40000711'):
            self.client.getProjectTestPlans(40000711)
         
    def test_getProjectPlatforms_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '7000.*40000711'):
            self.client.getProjectPlatforms(40000711)
        
    def test_getTestCase_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '5000.*40000711'):
            self.client.getTestCase(testcaseid=40000711)
         
    def test_getTestCase_unknownExternalID(self):
        with self.assertRaisesRegex(TLResponseError, '5040.*GPROAPI-40000711'):
            self.client.getTestCase(testcaseexternalid='GPROAPI-40000711')
            
    def test_getTestCaseAttachments_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '5000.*40000711'):
            self.client.getTestCaseAttachments(testcaseid=40000711)
         
    def test_getTestCaseCustomFieldDesignValue_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '7000.*40000711'):
            self.client.getTestCaseCustomFieldDesignValue(
                   'TC-40000712', 1, 40000711, 'a_field', details='full')
         
    def test_getTestCaseIDByName_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '5030.*Cannot find'):
            self.client.getTestCaseIDByName('Big Bird')
 
    def test_getTestCasesForTestPlan_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '3000.*40000711'):
            self.client.getTestCasesForTestPlan(40000711)
 
    def test_getTestCasesForTestSuite_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '8000.*40000711'):
            self.client.getTestCasesForTestSuite(40000711)
 
    def test_getTestPlanByName_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '7011.*40000711'):
            self.client.getTestPlanByName('project 40000711', 'plan 40000712')
 
    def test_getTestPlanPlatforms_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '3000.*40000711'):
            self.client.getTestPlanPlatforms(40000711)
 
    def test_getTestProjectByName_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '7011.*40000711'):
            self.client.getTestProjectByName('project 40000711')
 
    def test_getTestSuiteByID_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '8000.*40000711'):
            self.client.getTestSuiteByID(40000711)
 
    def test_getTestSuitesForTestPlan_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '3000.*40000711'):
            self.client.getTestSuitesForTestPlan(40000711)
 
    def test_getTestSuitesForTestSuite_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '8000.*40000711'):
            self.client.getTestSuitesForTestSuite(40000711)
 
    def test_getTotalsForTestPlan_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '3000.*40000711'):
            self.client.getTotalsForTestPlan(40000711)
 
    def test_createBuild_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '3000.*40000711'):
            self.client.createBuild(40000711, 'Build 40000712', buildnotes='note 40000713')
 
    def test_reportTCResult_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '5000.*40000711'):
            self.client.reportTCResult(40000712, 'p', testcaseid=40000711, 
                                       buildname='build 40000713', notes='note 40000714' )
 
    def test_uploadExecutionAttachment_unknownID(self):
        attachemantFile = open(os.path.realpath(__file__), 'r')
        with self.assertRaisesRegex(TLResponseError, '6004.*40000712'):
            self.client.uploadExecutionAttachment(attachemantFile, 40000712, 
                        title='title 40000713', description='descr. 40000714')
 
    def test_createPlatform_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '7011.*40000711'):
            self.client.createPlatform('Project 40000711', 'Platform 40000712', 
                                       notes='note 40000713')
            
    def test_addPlatformToTestPlan_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '3000.*40000711'):
            self.client.addPlatformToTestPlan(40000711, 'Platform 40000712')
            
    def test_removePlatformFromTestPlan_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '3000.*40000711'):
            self.client.removePlatformFromTestPlan(40000711, 'Platform 40000712')
            
    def test_addTestCaseToTestPlan_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '7000.*40000711'):
            self.client.addTestCaseToTestPlan(40000711, 40000712, 'N-40000713', 1)
            
    def test_updateTestCase_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '5040.*N-40000711'):
            self.client.updateTestCase('N-40000711', version=1)
        
    def test_createTestCaseSteps_unknownID(self):
        steps = [{'actions' : "Step action 6 -b added by updateTestCase" , 
                  'expected_results' : "Step result 6 - b added", 
                  'step_number' : 6, 'execution_type' : 1}]
        with self.assertRaisesRegex(TLResponseError, '5040.*N-40000711'):
            self.client.createTestCaseSteps('update', steps, 
                                        testcaseexternalid='N-40000711', version=1)
            
    def test_deleteTestCaseSteps_unknownID(self):
        steps = [2,8]
        with self.assertRaisesRegex(TLResponseError, '5040.*N-40000711'):
            self.client.deleteTestCaseSteps('N-40000711', steps, version=1)
            
    def test_uploadRequirementSpecificationAttachment_unknownID(self):
        attachemantFile = open(ATTACHMENT_EXAMPLE_TEXT, 'r')
        with self.assertRaisesRegex(TLResponseError, '6004.*40000712'):
            self.client.uploadRequirementSpecificationAttachment(attachemantFile, 40000712, 
                        title='title 40000713', description='descr. 40000714')
 
    def test_uploadRequirementAttachment_unknownID(self):
        attachemantFile = open(ATTACHMENT_EXAMPLE_TEXT, 'r')
        with self.assertRaisesRegex(TLResponseError, '6004.*40000712'):
            self.client.uploadRequirementAttachment(attachemantFile, 40000712, 
                        title='title 40000713', description='descr. 40000714')
 
    def test_uploadTestProjectAttachment_unknownID(self):
        attachemantFile = open(ATTACHMENT_EXAMPLE_TEXT, 'r')
        with self.assertRaisesRegex(TLResponseError, '7000.*40000712'):
            self.client.uploadTestProjectAttachment(attachemantFile, 40000712, 
                        title='title 40000713', description='descr. 40000714')
 
    def test_uploadTestSuiteAttachment_unknownID(self):
        attachemantFile = open(ATTACHMENT_EXAMPLE_TEXT, 'r')
        with self.assertRaisesRegex(TLResponseError, '8000.*40000712'):
            self.client.uploadTestSuiteAttachment(attachemantFile, 40000712, 
                        title='title 40000713', description='descr. 40000714')
 
    def test_uploadTestCaseAttachment_unknownID(self):
        attachemantFile = open(ATTACHMENT_EXAMPLE_TEXT, 'r')
        with self.assertRaisesRegex(TLResponseError, '5000.*testcaseid'):
            self.client.uploadTestCaseAttachment(attachemantFile, 40000712, 
                        title='title 40000713', description='descr. 40000714')
 
    def test_uploadAttachment_unknownID(self):
        attachemantFile = open(ATTACHMENT_EXAMPLE_TEXT, 'r')
        with self.assertRaisesRegex(TLResponseError, '6004.*Invalid Foreign Key ID'):
            self.client.uploadAttachment(attachemantFile, '0000', 'nodes_hierarchy',
                        title='title 40000713', description='descr. 40000714')

    def test_testLinkVersion(self):
        response = self.client.testLinkVersion()
        self.assertRegex(response, '\d*\.\d*\.\d*')

    def test_getUserByLogin_unknownKey(self):
        with self.assertRaisesRegex(TLResponseError, '10000.*User Login'):
            self.client.getUserByLogin('unknownUser')
            
    def test_getUserByID_unknownKey(self):
         with self.assertRaisesRegex(TLResponseError, 'NO_USER_BY_ID_LOGIN.*User with DB ID'):
            self.client.getUserByID(40000711)
            
#     def test_setTestMode(self):
#         response = self.client.setTestMode(True)
#         self.assertTrue(response)
#         response = self.client.setTestMode(False)
#         self.assertTrue(response)

    def test_deleteExecution_unknownKey(self):
        try:
            response = self.client.deleteExecution(40000711)
            # case: TL configuration allows deletion of executions
            # response returns Success, even if executionID is unkown
            self.assertEqual([{'status': True, 'message': 'Success!', 'id': 40000711, 
                               'operation': 'deleteExecution'}], response)
        except TLResponseError as tl_err:
            # case: TL configuration does not allow deletion of executions
            # Expects: 232: Configuration does not allow delete executions
            self.assertEqual(232, tl_err.code)

    def test_setTestCaseExecutionType_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '7000.*40000712'):
            self.client.setTestCaseExecutionType('N-40000711', 1, 40000712, 1)
            
    def test_assignRequirements_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '7000.*40000712'):
            self.client.assignRequirements('N-40000711', 40000712, 
                        [{'req_spec' : 40000713, 'requirements' : [40000714, 40000717]}, 
                         {'req_spec' : 4723, 'requirements' : [4725]}])
            
    def test_getExecCountersByBuild_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '3000.*40000711'):
            self.client.getExecCountersByBuild(40000711)
            
    def test_getTestCaseCustomFieldExecutionValue_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '236.*version/executionid'):
            self.client.getTestCaseCustomFieldExecutionValue(
                            'cf_full', '40000711', 1, '715', '40000713')
            
    def test_getTestCaseCustomFieldTestPlanDesignValue_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '7000.*40000711'):
            self.client.getTestCaseCustomFieldTestPlanDesignValue(
                            'cf_full', '40000711', 1, '40000713', '615')
            
    def test_updateTestCaseCustomFieldDesignValue_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '7000.*40000711'):
            self.client.updateTestCaseCustomFieldDesignValue(
                            'TC-40000712', 1, 40000711, {'cf_field1' : 'value1',
                                                 'cf_field2' : 'value2'})

    def test_getTestSuiteCustomFieldDesignValue_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '7000.*40000711'):
            self.client.getTestSuiteCustomFieldDesignValue(
                                                    'cf_full', 40000711, 40000713) 
            
    def test_getTestPlanCustomFieldDesignValue_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '7000.*40000711'):
            self.client.getTestPlanCustomFieldDesignValue(
                                                    'cf_full', 40000711, 40000712)             

    def test_getReqSpecCustomFieldDesignValue_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '7000.*40000711'):
            self.client.getReqSpecCustomFieldDesignValue(
                                                    'cf_full', 40000711, 4732)             

    def test_getRequirementCustomFieldDesignValue_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '7000.*40000711'):
            self.client.getRequirementCustomFieldDesignValue(
                                                    'cf_full', 40000711, 4734)  
            
    def test_assignTestCaseExecutionTask_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '3000.*40000711'):
            self.client.assignTestCaseExecutionTask('username', 40000711, 'TC-40000712', 
                                            buildname='build 40000713', 
                                            platformname='platform 40000714') 
              
    def test_getTestCaseBugs_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '3000.*40000711'):
            self.client.getTestCaseBugs(40000711, testcaseexternalid='TC-40000712', 
                                        buildname='build 40000713',
                                        platformname='platform 40000714')                         

    def test_getTestCaseAssignedTester_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '3000.*40000711'):
            self.client.getTestCaseAssignedTester(40000711, 'TC-40000712', 
                                            buildname='build 40000713', 
                                            platformname='platform 40000714') 
              
    def test_unassignTestCaseExecutionTask_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '3000.*40000711'):
            self.client.unassignTestCaseExecutionTask(40000711, 'TC-40000712', 
                                        buildname='build 40000713', 
                                        platformname='platform 40000714',
                                        user='******',action='unassignOne') 
    
    def test_getProjectKeywords_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '7000.*40000711'):
            self.client.getProjectKeywords(40000711) 

    def test_getTestCaseKeywords_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '5040.*40000712'):
            self.client.getTestCaseKeywords(testcaseid=40000712) 

    def test_getTestCaseKeywords_unknownID_set(self):
        with self.assertRaisesRegex(TLResponseError, '5040.*40000712'):
            self.client.getTestCaseKeywords(testcaseid=[40000712, 40000713]) 

    def test_getTestCaseKeywords_unknownID_external_single(self):
        with self.assertRaisesRegex(TLResponseError, '5040.*TC-40000712'):
            self.client.getTestCaseKeywords(testcaseexternalid='TC-40000712')
            
    def test_getTestCaseKeywords_unknownID_external_set(self):
        with self.assertRaisesRegex(TLResponseError, '5040.*TC-40000712'):
            self.client.getTestCaseKeywords(testcaseexternalid=['TC-40000712', 'TC-40000713'])

    def test_deleteTestPlan_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '3000.*40000711'):
            self.client.deleteTestPlan(40000711) 

    def test_addTestCaseKeywords_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '5040.*TC-40000712'):
            self.client.addTestCaseKeywords({'TC-40000712' :  
                                             ['KeyWord01', 'KeyWord03']}) 

    def test_removeTestCaseKeywords_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '5040.*TC-40000712'):
            self.client.removeTestCaseKeywords({'TC-40000712' : ['KeyWord01']}) 

    def test_deleteTestProject_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '7013.*TProjectPrefix'):
            self.client.deleteTestProject('TProjectPrefix') 

    def test_createTestPlan_projectname_optArg_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '7011.*40000712'):
            self.client.createTestPlan('plan 40000711', 
                                       testprojectname='project 40000712')

    def test_createTestPlan_prefix_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, 'NO.*TProjectPrefix'):
            self.client.createTestPlan('plan 40000713', 
                                       prefix='TProjectPrefix')

    def test_updateTestSuiteCustomFieldDesignValue_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '7000.*40000712'):
            self.client.updateTestSuiteCustomFieldDesignValue(
                            '40000712 TP-ID', '40000711 TS-ID',  
                            {'cf_tc_ex_string' : 'a custom exec value', 
                             'cf_tc_ex_numeric' : 111} )

    def test_getTestSuite_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, 'NO.*TProjectPrefix'):
            self.client.getTestSuite('suite 40000712', 'TProjectPrefix')
            

    def test_updateTestSuite_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '7000.*40000711'):
            self.client.updateTestSuite(40000712, testprojectid=40000711, 
                                    testsuitename = 'suite 40000712 updated',
                                    details = 'detail 40000713 updated',
                                    order =1)
            
    def test_getIssueTrackerSystem_unknownITS(self):
        with self.assertRaisesRegex(TLResponseError, '13000.*Unable to find'):
            self.client.getIssueTrackerSystem('unknownITS')
 
    def test_updateBuildCustomFieldsValues_unknownID(self):
        with self.assertRaisesRegex(TLResponseError, '7000.*40000712'):
            self.client.updateBuildCustomFieldsValues(
                            '40000712 project', '40000713 plan', '40000714 build', 
                            {'cf_b_ex_string' : 'a custom exec value', 
                             'cf_b_ex_numeric' : 111} )
Ejemplo n.º 45
0
 def connect_testlink(self):
     return TestLinkHelper(self.testlink_server,
                           self.dev_key).connect(TestlinkAPIGeneric)

def iterTCasesfromTProject(api, TProjName, date1, date2):
    """ returns as iterator all test cases of project TPROJTNAME, which are 
    created between DATE1 and DATE2 
    DATE1 and DATE2 must be of type time.struct_time """
    TProjId = api.getTestProjectByName(TProjName)[0]['id']
    for TSinfo in api.getFirstLevelTestSuitesForTestProject(TProjId):
        TSuiteId = TSinfo['id']
        for TCid in api.getTestCasesForTestSuite(TSuiteId,
                                                 deep=1,
                                                 details='only_id'):
            TCdata = api.getTestCase(TCid)[0]  #really only one TC?
            dateTC = time.strptime(TCdata['creation_ts'][:10], '%Y-%m-%d')
            if (date1 <= dateTC) and (dateTC <= date2):
                yield TCdata


if __name__ == '__main__':
    tlapi = TestLinkHelper().connect(TestlinkAPIClient)
    projName = 'NEW_PROJECT_API'
    currentTime = time.localtime()
    oldTime = time.localtime(time.time() - 3600 * 24 * 7)

    print '%s test cases created between %s and %s' % \
            (projName, time.strftime('%Y-%m-%d', oldTime),
             time.strftime('%Y-%m-%d', currentTime))
    for TCdata in iterTCasesfromTProject(tlapi, projName, oldTime,
                                         currentTime):
        print '  %(name)s %(version)s %(creation_ts)s' % TCdata
	print 'Successfully uploaded all case result to testlink !'

if __name__ == '__main__':
	#retrieve result from output.xml
	print sys.argv
	if len(sys.argv) != 6:
		print 'Please input 5 parameters: project name, testplan name, build name, platform name(input no_platform if there is no platform), fullpath of output.xml'
		print sys.exit()
	projName = sys.argv[1]
	testPlanName = sys.argv[2]
	buildName = sys.argv[3]
	platformName = sys.argv[4]
	robot_result_path = sys.argv[5]
	result_map = getTestResultMap(robot_result_path)
	#prepare to upload test result
	tlapi = TestLinkHelper().connect(TestlinkAPIClient)
	#get testplan id
	testplan_res = tlapi.getTestPlanByName(projName, testPlanName)
	if len(testplan_res) != 1 :
		raise Exception('Find %s testplan(%s) in project(%s)'%(len(testplan_res), testPlanName, projName))
	if not testplan_res[0].has_key('id'):
		raise Exception('Did not find testplan(%s) id!')
	testplan_id = testplan_res[0]['id']
	#get platforms
	platform_id = ''
	if platformName != 'no_platform':
		platform_list = tlapi.getTestPlanPlatforms(testplan_id)
		#[{'notes': '<p>\n\tCPMS+PAB+CAL+CPDS+FS</p>', 'id': '240', 'name': 'Fusion-CPMS Backend'}, {'notes': '<p>\n\tMX+PAB+CAL+mOS+SUR</p>', 'id': '241', 'name': 'Fusion-MX Backend'}]
		for platform in platform_list:
			if platform['name'] == platformName:
				platform_id = platform['id']
Ejemplo n.º 48
0
class TestClass():
    def setUp(self):
        """Initialisation
        """

        # precondition - SERVEUR_URL and KEY are defined in environment
        # TESTLINK_API_PYTHON_SERVER_URL=http://localhost/testlink/lib/api/xmlrpc.php
        # TESTLINK_API_PYTHON_DEVKEY=7ec252ab966ce88fd92c25d08635672b
        self.client = TestLinkHelper().connect(TestLink)

    def test_getTestCaseIDByName(self):
        """ getTestCaseIDByName test
        """
        val = self.client.getTestCaseIDByName("Fin de programme", "Séquence 2",
                                              "Test 2")
        # 31 is test case id
        assert_equal(val, '31')

        # Check if an error is raised in case of bad parameters
        assert_raises(TestLinkError, self.client.getTestCaseIDByName,
                      "Initialisation", "Séquence 1", "Test 2")

    def test_getTestProjectByName(self):
        project = self.client.getTestProjectByName("Test 2")
        assert_equals(type(project), dict)
        # Check if an error is raised in case of bad parameters
        assert_raises(TestLinkError, self.client.getTestProjectByName,
                      "Unknown project")

    def test_getTestPlanByName(self):
        plan_ok = self.client.getTestPlanByName("Test 2", "Full")

        # Assume that plan id is 33
        assert_equal(plan_ok['id'], '33')

        assert_raises(TestLinkError, self.client.getTestPlanByName, "Test 2",
                      "Name Error")

    def test_getBuildByName(self):
        pass

    def test_reportResult(self):
        dico = {'testPlanName': 'FullAuto', 'buildName': 'V0.1'}
        execid = self.client.reportResult("p", "test1", "S1",
                                          "An example of note", **dico)
        assert_equal(type(execid), str)

        execid = self.client.reportResult("f", "test2", "S1", **dico)
        assert_equal(type(execid), str)

    def test_getTestCasesForTestPlan(self):
        results = self.client.getTestCasesForTestPlan("Automatique",
                                                      "FullAuto")
        for result in results:
            print result
        #TODO
#        assert_equal(type(results), list)

#for elem in results:
#assert_equal(type(elem), dict)

    def test_getTestCaseCustomFieldDesignValue(self):
        test_list = self.client.getTestCasesForTestPlan(
            "Automatique", "FullAuto")
        for test in test_list:
            #print test
            results = self.client.getTestCaseCustomFieldDesignValue(
                "AutomaticTestFunction", "Automatique", test)
            if results != '':
                assert_equal(results, 'Fonction_auto-5')

    def test_getProjectIDByName(self):
        projectid = self.client.getProjectIDByName("Automatique")
        assert_equal(projectid, '52')

    def test_getTestCaseByExtID(self):
        """getTestCaseByExtID test method"""

        assert_raises(TestLinkErrors, self.client.getTestCaseByExtID,
                      'Id not known')

        extid = 'auto-5'
        tc = self.client.getTestCaseByExtID(extid)
        assert_equal(tc.extid, extid)

    def test_getTestCase(self):
        """getTestCase test method"""

        tc = self.client.getTestCase(testcaseexternalid='auto-5')

        # tc must be an TestCase object
        assert_equal(tc.extid, 'auto-5')

        # Test failed Return
        assert_raises(TestLinkErrors, self.client.getTestCase, 'Id not known')
Ejemplo n.º 49
0
class TestClass():
    def setUp(self):
        """Initialisation
        """

        # precondition - SERVEUR_URL and KEY are defined in environment
        # TESTLINK_API_PYTHON_SERVER_URL=http://localhost/testlink/lib/api/xmlrpc.php
        # TESTLINK_API_PYTHON_DEVKEY=7ec252ab966ce88fd92c25d08635672b
        self.client = TestLinkHelper().connect(TestLink)

    def test_getTestCaseIDByName(self):
        """ getTestCaseIDByName test
        """
        val = self.client.getTestCaseIDByName("Fin de programme", "Séquence 2", "Test 2")
        # 31 is test case id
        assert_equal(val, '31' )

        # Check if an error is raised in case of bad parameters
        assert_raises(TestLinkError, self.client.getTestCaseIDByName, "Initialisation", "Séquence 1", "Test 2")

    def test_getTestProjectByName(self):
        project = self.client.getTestProjectByName("Test 2")
        assert_equals(type(project), dict)
        # Check if an error is raised in case of bad parameters
        assert_raises(TestLinkError, self.client.getTestProjectByName, "Unknown project")

    def test_getTestPlanByName(self):
        plan_ok = self.client.getTestPlanByName("Test 2", "Full")

        # Assume that plan id is 33
        assert_equal(plan_ok['id'], '33')

        assert_raises(TestLinkError, self.client.getTestPlanByName, "Test 2", "Name Error")

    def test_getBuildByName(self):
        pass

    def test_reportResult(self):
        dico = {'testPlanName': 'FullAuto',
                'buildName': 'V0.1'}
        execid = self.client.reportResult("p", "test1", "S1", "An example of note", **dico)
        assert_equal(type(execid), str)

        execid = self.client.reportResult("f", "test2", "S1", **dico)
        assert_equal(type(execid), str)

    def test_getTestCasesForTestPlan(self):
        results = self.client.getTestCasesForTestPlan("Automatique", "FullAuto")
        for result in results:
            print result
        #TODO
#        assert_equal(type(results), list)

        #for elem in results:
            #assert_equal(type(elem), dict)

    def test_getTestCaseCustomFieldDesignValue(self):
        test_list = self.client.getTestCasesForTestPlan("Automatique", "FullAuto")
        for test in test_list:
            #print test
            results = self.client.getTestCaseCustomFieldDesignValue("AutomaticTestFunction", "Automatique", test )
            if results != '':
                assert_equal(results, 'Fonction_auto-5')

    def test_getProjectIDByName(self):
        projectid = self.client.getProjectIDByName("Automatique")
        assert_equal(projectid, '52')

    def test_getTestCaseByExtID(self):
        """getTestCaseByExtID test method"""

        assert_raises(TestLinkErrors, self.client.getTestCaseByExtID, 'Id not known')

        extid = 'auto-5'
        tc = self.client.getTestCaseByExtID(extid)
        assert_equal(tc.extid, extid)

    def test_getTestCase(self):
        """getTestCase test method"""

        tc = self.client.getTestCase(testcaseexternalid='auto-5')

        # tc must be an TestCase object
        assert_equal(tc.extid, 'auto-5')

        # Test failed Return
        assert_raises(TestLinkErrors, self.client.getTestCase, 'Id not known')
Ejemplo n.º 50
0
 def setUp(self):
     self.api = TestLinkHelper().connect(DummyAPIGeneric)
     self.callArgs = None
class TestLinkAPIOfflineTestCase(unittest.TestCase):
    """ TestCases for TestlinkAPIClient - does not interacts with a TestLink Server.
    works with DummyAPIClientm which returns special test data
    """

    def setUp(self):
        self.api = TestLinkHelper().connect(DummyAPIClient)

#    def tearDown(self):
#        pass


    def test_countProjects(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countProjects()
        self.assertEqual(2, response)
        
    def test_countTestPlans(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countTestPlans()
        self.assertEqual(1, response)
        
    def test_countTestSuites(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countTestSuites()
        self.assertEqual(0, response)
        
    def test_countTestCasesTP(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countTestCasesTP()
        self.assertEqual(0, response)
        
    def test_countTestCasesTS(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countTestCasesTS()
        self.assertEqual(0, response)

    def test_countPlatforms(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countPlatforms()
        self.assertEqual(0, response)
        
    def test_countBuilds(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countBuilds()
        self.assertEqual(0, response)

#    def test_listProjects(self):
#        self.api.loadScenario(SCENARIO_A)
#        self.api.listProjects()
#         no assert check cause method returns nothing
#         'just' prints to stdout
        
    def test_getProjectIDByName(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getProjectIDByName('NEW_PROJECT_API')
        self.assertEqual('21', response)
        response = self.api.getProjectIDByName('UNKNOWN_PROJECT')
        self.assertEqual(-1, response)
Ejemplo n.º 52
0
class TestLinkAPIOfflineTestCase(unittest.TestCase):
    """ TestCases for TestlinkAPIClient - does not interacts with a TestLink Server.
    works with DummyAPIClientm which returns special test data
    """
    def setUp(self):
        self.api = TestLinkHelper().connect(DummyAPIClient)

#    def tearDown(self):
#        pass

    def test_countProjects(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countProjects()
        self.assertEqual(2, response)

    def test_countTestPlans(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countTestPlans()
        self.assertEqual(1, response)

    def test_countTestSuites(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countTestSuites()
        self.assertEqual(0, response)

    def test_countTestCasesTP(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countTestCasesTP()
        self.assertEqual(0, response)

    def test_countTestCasesTS(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countTestCasesTS()
        self.assertEqual(0, response)

    def test_countPlatforms(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countPlatforms()
        self.assertEqual(0, response)

    def test_countBuilds(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countBuilds()
        self.assertEqual(0, response)


#    def test_listProjects(self):
#        self.api.loadScenario(SCENARIO_A)
#        self.api.listProjects()
#         no assert check cause method returns nothing
#         'just' prints to stdout

    def test_getProjectIDByName(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getProjectIDByName('NEW_PROJECT_API')
        self.assertEqual('21', response)
        response = self.api.getProjectIDByName('UNKNOWN_PROJECT')
        self.assertEqual(-1, response)
 def setUp(self):
     self.api = TestLinkHelper().connect(DummyAPIClient)
class TestLinkAPIOnlineTestCase(unittest.TestCase):
    """ TestCases for TestlinkAPIClient - interacts with a TestLink Server.
    works with the example project NEW_PROJECT_API (see TestLinkExample.py)
    """
    def setUp(self):
        self.client = TestLinkHelper().connect(TestlinkAPIGeneric)

#    def tearDown(self):
#        pass

    def test_checkDevKey(self):
        response = self.client.checkDevKey()
        self.assertEqual(True, response)

    def test_checkDevKey_unknownKey(self):
        with self.assertRaisesRegexp(TLResponseError, '2000.*invalid'):
            self.client.checkDevKey(devKey='unknownKey')

    def test_sayHello(self):
        response = self.client.sayHello()
        self.assertEqual('Hello!', response)

    def test_repeat(self):
        response = self.client.repeat('Yellow Submarine')
        self.assertEqual('You said: Yellow Submarine', response)

    def test_about(self):
        response = self.client.about()
        self.assertIn('Testlink API', response)

    def test_doesUserExist_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '10000.*Big Bird'):
            self.client.doesUserExist('Big Bird')

    def test_createTestProject_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7001.*Empty name'):
            self.client.createTestProject(testprojectname='',
                                          testcaseprefix='P4711')

    def test_getProjects(self):
        response = self.client.getProjects()
        self.assertIsNotNone(response)

    def test_createTestPlan_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7011.*4712'):
            self.client.createTestPlan('plan 4711', 'project 4712')

    def test_createTestSuite_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7000.*4711'):
            self.client.createTestSuite(4711, 'suite 4712', 'detail 4713')

    def test_createTestCase_unknownID(self):
        tc_steps = []
        with self.assertRaisesRegexp(TLResponseError, '7000.*4713'):
            self.client.createTestCase('case 4711', 4712, 4713, 'Big Bird',
                                       'summary 4714', tc_steps)

    def test_getBuildsForTestPlan_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.getBuildsForTestPlan(4711)

    def test_getFirstLevelTestSuitesForTestProject_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7000.*4711'):
            self.client.getFirstLevelTestSuitesForTestProject(4711)

    def test_getFullPath_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, 'getFullPath.*234'):
            self.client.getFullPath('4711')

    def test_getLastExecutionResult_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.getLastExecutionResult(4711, testcaseid=4712)

    def test_getLatestBuildForTestPlan_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.getLatestBuildForTestPlan(4711)

    def test_getProjectTestPlans_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7000.*4711'):
            self.client.getProjectTestPlans(4711)

    def test_getProjectPlatforms_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7000.*4711'):
            self.client.getProjectPlatforms(4711)

    def test_getTestCase_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '5000.*4711'):
            self.client.getTestCase(testcaseid=4711)

    def test_getTestCase_unknownExternalID(self):
        with self.assertRaisesRegexp(TLResponseError, '5040.*GPROAPI-4711'):
            self.client.getTestCase(testcaseexternalid='GPROAPI-4711')

    def test_getTestCaseAttachments_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '5000.*4711'):
            self.client.getTestCaseAttachments(testcaseid=4711)

    def test_getTestCaseCustomFieldDesignValue_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7000.*4711'):
            self.client.getTestCaseCustomFieldDesignValue('TC-4712',
                                                          1,
                                                          4711,
                                                          'a_field',
                                                          details='a_detail')

    def test_getTestCaseIDByName_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '5030.*Cannot find'):
            self.client.getTestCaseIDByName('Big Bird')

    def test_getTestCasesForTestPlan_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.getTestCasesForTestPlan(4711)

    def test_getTestCasesForTestSuite_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '8000.*4711'):
            self.client.getTestCasesForTestSuite(4711)

    def test_getTestPlanByName_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7011.*4711'):
            self.client.getTestPlanByName('project 4711', 'plan 4712')

    def test_getTestPlanPlatforms_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.getTestPlanPlatforms(4711)

    def test_getTestProjectByName_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7011.*4711'):
            self.client.getTestProjectByName('project 4711')

    def test_getTestSuiteByID_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '8000.*4711'):
            self.client.getTestSuiteByID(4711)

    def test_getTestSuitesForTestPlan_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.getTestSuitesForTestPlan(4711)

    def test_getTestSuitesForTestSuite_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '8000.*4711'):
            self.client.getTestSuitesForTestSuite(4711)

    def test_getTotalsForTestPlan_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.getTotalsForTestPlan(4711)

    def test_createBuild_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.createBuild(4711, 'Build 4712', buildnotes='note 4713')

    def test_reportTCResult_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '5000.*4711'):
            self.client.reportTCResult(4712,
                                       'p',
                                       testcaseid=4711,
                                       buildname='build 4713',
                                       notes='note 4714')

    def test_uploadExecutionAttachment_unknownID(self):
        attachemantFile = open(os.path.realpath(__file__), 'r')
        with self.assertRaisesRegexp(TLResponseError, '6004.*4712'):
            self.client.uploadExecutionAttachment(attachemantFile,
                                                  4712,
                                                  title='title 4713',
                                                  description='descr. 4714')

    def test_createPlatform_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7011.*4711'):
            self.client.createPlatform('Project 4711',
                                       'Platform 4712',
                                       notes='note 4713')

    def test_addPlatformToTestPlan_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.addPlatformToTestPlan(4711, 'Platform 4712')

    def test_removePlatformFromTestPlan_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
            self.client.removePlatformFromTestPlan(4711, 'Platform 4712')

    def test_addTestCaseToTestPlan_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7000.*4711'):
            self.client.addTestCaseToTestPlan(4711, 4712, 'N-4713', 1)

    def test_updateTestCase_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '5040.*N-4711'):
            self.client.updateTestCase('N-4711', version=1)

    def test_createTestCaseSteps_unknownID(self):
        steps = [{
            'actions': "Step action 6 -b added by updateTestCase",
            'expected_results': "Step result 6 - b added",
            'step_number': 6,
            'execution_type': 1
        }]
        with self.assertRaisesRegexp(TLResponseError, '5040.*N-4711'):
            self.client.createTestCaseSteps('update',
                                            steps,
                                            testcaseexternalid='N-4711',
                                            version=1)

    def test_deleteTestCaseSteps_unknownID(self):
        steps = [2, 8]
        with self.assertRaisesRegexp(TLResponseError, '5040.*N-4711'):
            self.client.deleteTestCaseSteps('N-4711', steps, version=1)

    def test_uploadRequirementSpecificationAttachment_unknownID(self):
        attachemantFile = open(os.path.realpath(__file__), 'r')
        with self.assertRaisesRegexp(TLResponseError, '6004.*4712'):
            self.client.uploadRequirementSpecificationAttachment(
                attachemantFile,
                4712,
                title='title 4713',
                description='descr. 4714')

    def test_uploadRequirementAttachment_unknownID(self):
        attachemantFile = open(os.path.realpath(__file__), 'r')
        with self.assertRaisesRegexp(TLResponseError, '6004.*4712'):
            self.client.uploadRequirementAttachment(attachemantFile,
                                                    4712,
                                                    title='title 4713',
                                                    description='descr. 4714')

    def test_uploadTestProjectAttachment_unknownID(self):
        attachemantFile = open(os.path.realpath(__file__), 'r')
        with self.assertRaisesRegexp(TLResponseError, '7000.*4712'):
            self.client.uploadTestProjectAttachment(attachemantFile,
                                                    4712,
                                                    title='title 4713',
                                                    description='descr. 4714')

    def test_uploadTestSuiteAttachment_unknownID(self):
        attachemantFile = open(os.path.realpath(__file__), 'r')
        with self.assertRaisesRegexp(TLResponseError, '8000.*4712'):
            self.client.uploadTestSuiteAttachment(attachemantFile,
                                                  4712,
                                                  title='title 4713',
                                                  description='descr. 4714')

    def test_uploadTestCaseAttachment_unknownID(self):
        attachemantFile = open(os.path.realpath(__file__), 'r')
        with self.assertRaisesRegexp(TLResponseError, '5000.*testcaseid'):
            self.client.uploadTestCaseAttachment(attachemantFile,
                                                 4712,
                                                 title='title 4713',
                                                 description='descr. 4714')

    def test_uploadAttachment_unknownID(self):
        attachemantFile = open(os.path.realpath(__file__), 'r')
        with self.assertRaisesRegexp(TLResponseError, '6004.*4712'):
            self.client.uploadAttachment(attachemantFile,
                                         4712,
                                         'nodes_hierarchy',
                                         title='title 4713',
                                         description='descr. 4714')

    def test_checkDevKey_unknownKey(self):
        with self.assertRaisesRegexp(TLResponseError, '2000.*invalid'):
            self.client.checkDevKey(devKey='unknownKey')

    def test_testLinkVersion(self):
        response = self.client.testLinkVersion()
        self.assertRegexpMatches(response, '\d*\.\d*\.\d*')

    def test_getUserByLogin_unknownKey(self):
        with self.assertRaisesRegexp(TLResponseError, '10000.*User Login'):
            self.client.getUserByLogin('unknownUser')

    def test_getUserByID_unknownKey(self):
        with self.assertRaisesRegexp(TLResponseError,
                                     'NO_USER_BY_ID_LOGIN.*User with DB ID'):
            self.client.getUserByID(4711)


#     def test_setTestMode(self):
#         response = self.client.setTestMode(True)
#         self.assertTrue(response)
#         response = self.client.setTestMode(False)
#         self.assertTrue(response)

    def test_deleteExecution_unknownKey(self):
        try:
            response = self.client.deleteExecution(4711)
            # case: TL configuration allows deletion of executions
            # response returns Success, even if executionID is unkown
            self.assertEqual([{
                'status': True,
                'message': 'Success!',
                'id': 4711,
                'operation': 'deleteExecution'
            }], response)
        except TLResponseError as tl_err:
            # case: TL configuration does not allow deletion of executions
            # Expects: 232: Configuration does not allow delete executions
            self.assertEqual(232, tl_err.code)

    def test_setTestCaseExecutionType_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7000.*4712'):
            self.client.setTestCaseExecutionType('N-4711', 1, 4712, 1)

    def test_assignRequirements_unknownID(self):
        with self.assertRaisesRegexp(TLResponseError, '7000.*4712'):
            self.client.assignRequirements('N-4711', 4712,
                                           [{
                                               'req_spec': 4713,
                                               'requirements': [4714, 4717]
                                           }, {
                                               'req_spec': 4723,
                                               'requirements': [4725]
                                           }])
Ejemplo n.º 55
0
# precondition a)
# SERVER_URL and KEY are defined in environment
# TESTLINK_API_PYTHON_SERVER_URL=http://YOURSERVER/testlink/lib/api/xmlrpc.php
# TESTLINK_API_PYTHON_DEVKEY=7ec252ab966ce88fd92c25d08635672b
#
# alternative precondition b)
# SERVEUR_URL and KEY are defined as command line arguments
# python TestLinkExample.py --server_url http://YOURSERVER/testlink/lib/api/xmlrpc.php
#                           --devKey 7ec252ab966ce88fd92c25d08635672b
#
# ATTENTION: With TestLink 1.9.7, cause of the new REST API, the SERVER_URL
#            has changed from
#               (old) http://YOURSERVER/testlink/lib/api/xmlrpc.php
#            to
#               (new) http://YOURSERVER/testlink/lib/api/xmlrpc/v1/xmlrpc.php
tl_helper = TestLinkHelper()
tl_helper.setParamsFromArgs(
    '''Shows how to use the TestLinkAPI for CustomFields.
=> requires an existing project PROJECT_API_GENERIC-*''')
myTestLink = tl_helper.connect(TestlinkAPIGeneric)

myPyVersion = python_version()
myPyVersionShort = myPyVersion.replace('.', '')[:2]

NEWTESTPLAN_A = "TestPlan_API_GENERIC A"
# NEWTESTPLAN_B="TestPlan_API_GENERIC B"
# NEWTESTPLAN_C="TestPlan_API_GENERIC C - DeleteTest"
# NEWPLATFORM_A='Big Bird %s' % myPyVersionShort
NEWPLATFORM_B = 'Small Bird'
# NEWPLATFORM_C='Ugly Bird'
NEWTESTSUITE_A = "A - First Level"
class TestLinkAPIOfflineTestCase(unittest.TestCase):
    """ TestCases for TestlinkAPIClient - does not interacts with a TestLink Server.
    works with DummyAPIClientm which returns special test data
    """

    example_steps = [{'step_number' : '1', 'actions' : "action A" , 
                'expected_results' : "result A", 'execution_type' : "0"},
                 {'step_number' : '2', 'actions' : "action B" , 
                'expected_results' : "result B", 'execution_type' : "1"},
                 {'step_number' : '3', 'actions' : "action C" , 
                'expected_results' : "result C", 'execution_type' : "0"}]
    def setUp(self):
        self.api = TestLinkHelper().connect(DummyAPIClient)

#    def tearDown(self):
#        pass


    def test_countProjects(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countProjects()
        self.assertEqual(2, response)
        
    def test_countTestPlans(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countTestPlans()
        self.assertEqual(2, response)
        
    def test_countTestSuites(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countTestSuites()
        self.assertEqual(0, response)
        
    def test_countTestCasesTP(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countTestCasesTP()
        self.assertEqual(0, response)
        
    def test_countTestCasesTS(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countTestCasesTS()
        self.assertEqual(0, response)

    def test_countPlatforms(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countPlatforms()
        self.assertEqual(2, response)
        
    def test_countBuilds(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.countBuilds()
        self.assertEqual(0, response)

#    def test_listProjects(self):
#        self.api.loadScenario(SCENARIO_A)
#        self.api.listProjects()
#         no assert check cause method returns nothing
#         'just' prints to stdout
        
    def test_getProjectIDByName(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getProjectIDByName('NEW_PROJECT_API')
        self.assertEqual('21', response)
        response = self.api.getProjectIDByName('UNKNOWN_PROJECT')
        self.assertEqual(-1, response)
        
    def test_initStep(self):
        self.api.initStep("action A", "result A", 0)
        steps = self.example_steps[:1]
        self.assertEqual(steps, self.api.stepsList)
        
    def test_appendStep(self):
        steps = self.example_steps
        self.api.stepsList = steps[:1] 
        self.api.appendStep("action B", "result B", 1)
        self.api.appendStep("action C", "result C", 0)
        self.assertEqual(steps, self.api.stepsList)

    def test_createTestCaseWithSteps(self):
        self.api.loadScenario(SCENARIO_STEPS)
        self.api.initStep("action A", "result A", 0)
        self.api.appendStep("action B", "result B", 1)
        self.api.appendStep("action C", "result C", 0)
        self.api.createTestCase('case 4711', 4712, 4713, 'Big Bird', 
                                'summary 4714')
        self.assertEqual(self.example_steps, self.api.callArgs['steps'])
        self.assertEqual([], self.api.stepsList)

    def test_createTestCaseWithConfusingSteps(self):
        self.api.loadScenario(SCENARIO_STEPS)
        self.api.initStep("action A", "result A", 0)
        self.api.appendStep("action B", "result B", 1)
        self.api.appendStep("action C", "result C", 0)
        with self.assertRaisesRegexp(TLArgError, 'confusing createTestCase*'):
            self.api.createTestCase('case 4711', 4712, 4713, 'Big Bird', 
                                    'summary 4714', steps=[])
        
    def test_getTestCaseIDByName_dictResult(self):
        "test that getTestCaseIDByName converts dictionary result into a list"
        self.api.loadScenario(SCENARIO_A)
        # v0.4.0 version for optional args testsuitename + testprojectname
        #response = self.api.getTestCaseIDByName('dictResult', None, 'NEW_PROJECT_API')
        # v0.4.5 version
        response = self.api.getTestCaseIDByName('dictResult', 
                                            testprojectname='NEW_PROJECT_API')
        self.assertEqual(list, type(response))
        self.assertEqual('TESTCASE_B', response[0]['name']) 
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
        
    def test_getTestCaseIDByName_listResult(self):
        self.api.loadScenario(SCENARIO_A)
        response = self.api.getTestCaseIDByName('listResult')
        self.assertEqual(list, type(response))
        self.assertEqual('TESTCASE_AA', response[0]['name']) 
        self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
        
    def test_getProjectIDByNode(self):
        self.api.loadScenario(SCENARIO_A)
        self.assertEqual('2211', self.api.getProjectIDByNode('4711'))
        
    def test__copyTC_generate_new(self):
        self.api.loadScenario(SCENARIO_A)
        self.api._copyTC('26', {}, duplicateaction = 'generate_new')
        self.assertEqual('generate_new',  
                         self.api.callArgs['actiononduplicatedname'])

    def test__copyTC_create_new_version(self):
        self.api.loadScenario(SCENARIO_A)
        self.api._copyTC('26', {}, duplicateaction = 'create_new_version')
        self.assertEqual('create_new_version',  
                         self.api.callArgs['actiononduplicatedname'])
        self.assertEqual('V2 None', self.api.callArgs['preconditions'])

    def test__copyTC_changedArgs(self):
        self.api.loadScenario(SCENARIO_A)
        self.api._copyTC('26', {'testsuiteid' :'4711'}, 
                         duplicateaction = 'generate_new')
        self.assertEqual('4711', self.api.callArgs['testsuiteid'])
        self.assertEqual('2211', self.api.callArgs['testprojectid'])

    def test__copyTC_changedArgs_version(self):
        self.api.loadScenario(SCENARIO_A)
        self.api._copyTC('26', {'testsuiteid' :'4711'}, 1,
                         duplicateaction = 'generate_new')
        self.assertEqual('4711', self.api.callArgs['testsuiteid'])
        self.assertEqual('2211', self.api.callArgs['testprojectid'])
        self.assertEqual('V1', self.api.callArgs['preconditions'])
        

    def test_copyTCnewVersion(self):
        self.api.loadScenario(SCENARIO_A)
        self.api.copyTCnewVersion('26', summary = 'The summary has changed', 
                                    importance = '33')
        self.assertEqual('create_new_version',  
                         self.api.callArgs['actiononduplicatedname'])
        self.assertEqual('V2 None', self.api.callArgs['preconditions'])
        self.assertEqual('The summary has changed', self.api.callArgs['summary'])
        self.assertEqual('33', self.api.callArgs['importance'])
        self.assertEqual('TC-C', self.api.callArgs['testcasename'])
        self.assertEqual('25', self.api.callArgs['testsuiteid'])
        self.assertEqual('21', self.api.callArgs['testprojectid'])

    def test_copyTCnewVersion_version(self):
        self.api.loadScenario(SCENARIO_A)
        self.api.copyTCnewVersion('26', 1, summary = 'The summary has changed', 
                                    importance = '33')
        self.assertEqual('create_new_version',  
                         self.api.callArgs['actiononduplicatedname'])
        self.assertEqual('V1', self.api.callArgs['preconditions'])
        self.assertEqual('The summary has changed', self.api.callArgs['summary'])
        self.assertEqual('33', self.api.callArgs['importance'])
        self.assertEqual('TC-C', self.api.callArgs['testcasename'])
        self.assertEqual('25', self.api.callArgs['testsuiteid'])
        self.assertEqual('21', self.api.callArgs['testprojectid'])

    def test_copyTCnewTestCase(self):
        self.api.loadScenario(SCENARIO_A)
        self.api.copyTCnewTestCase('26', testsuiteid = '4711')
        self.assertEqual('generate_new',  
                         self.api.callArgs['actiononduplicatedname'])
        self.assertEqual('V2 None', self.api.callArgs['preconditions'])
        self.assertEqual('4711', self.api.callArgs['testsuiteid'])
        self.assertEqual('2211', self.api.callArgs['testprojectid'])

    def test_copyTCnewTestCase_version(self):
        self.api.loadScenario(SCENARIO_A)
        self.api.copyTCnewTestCase('26', 1, testsuiteid = '4711')
        self.assertEqual('generate_new',  
                         self.api.callArgs['actiononduplicatedname'])
        self.assertEqual('V1', self.api.callArgs['preconditions'])
        self.assertEqual('4711', self.api.callArgs['testsuiteid'])
        self.assertEqual('2211', self.api.callArgs['testprojectid'])