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 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'])
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_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]
                                           }])
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} )
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)
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}
            )
예제 #8
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(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')
예제 #10
0
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'])