def main(config_module=None): from testlinktool.main.config import TESTLINK_SERVER, TESTLINK_PROJECT_ID, TESTLINK_PROJECT_NAME,\ TESTLINK_API_KEY, CUSTOM_FIELD_NAME_LIST, UI_TEST_KEYWORD # use configuration try: if config_module is not None: TESTLINK_SERVER = getattr(config_module, "TESTLINK_SERVER") TESTLINK_PROJECT_ID = getattr(config_module, "TESTLINK_PROJECT_ID") TESTLINK_PROJECT_NAME = getattr(config_module, "TESTLINK_PROJECT_NAME") TESTLINK_API_KEY = getattr(config_module, "TESTLINK_API_KEY") CUSTOM_FIELD_NAME_LIST = getattr(config_module, "CUSTOM_FIELD_NAME_LIST") UI_TEST_KEYWORD = getattr(config_module, "UI_TEST_KEYWORD") elif exists(join(getcwd(), 'config.json')): with open(join(getcwd(), 'config.json')) as j_file: conf_dic = json_read_file(j_file) TESTLINK_SERVER = conf_dic["TESTLINK_SERVER"] TESTLINK_PROJECT_ID = conf_dic["TESTLINK_PROJECT_ID"] TESTLINK_PROJECT_NAME = conf_dic["TESTLINK_PROJECT_NAME"] TESTLINK_API_KEY = conf_dic["TESTLINK_API_KEY"] CUSTOM_FIELD_NAME_LIST = conf_dic["CUSTOM_FIELD_NAME_LIST"] UI_TEST_KEYWORD = conf_dic["UI_TEST_KEYWORD"] except ImportError: print("Warning we are using default parameters") parser = argparse.ArgumentParser(description='') group = parser.add_argument_group() group.add_argument('-d', '--test-dir', dest='dest_dir', help="The directory path where generated tests will be sent (defaults to 'tests')", default="tests") group.add_argument('-p', '--plan', dest='plan', help="the test plan", default=None, required=True) group.add_argument('-a', '--download-all', dest='download_all', default=False, action="store_true", help="if used will download all tests, even those which are already coded") group.add_argument('-v', '--verbose', dest='verbose', default=False, action="store_true", help="verbosity") args = parser.parse_args() tl_helper = TestLinkHelper(TESTLINK_SERVER, TESTLINK_API_KEY) testlink_client = tl_helper.connect(TestlinkAPIClient) plan_id = int(testlink_client.getTestPlanByName(TESTLINK_PROJECT_NAME, args.plan)[0]['id']) suites = testlink_client.getTestSuitesForTestPlan(plan_id) # build a id/name relation dictionary suites_tc_dic = { suite["id"]: suite["name"] for suite in suites } cases = get_tests(testlink_client, UI_TEST_KEYWORD, plan_id, TESTLINK_PROJECT_ID, CUSTOM_FIELD_NAME_LIST) names = [n["tcase_name"] for n in cases] other_cases = get_tests(testlink_client, None, plan_id, TESTLINK_PROJECT_ID, CUSTOM_FIELD_NAME_LIST) cases += [n for n in other_cases if n["tcase_name"] not in names] for case in cases: case["suite"] = suites_tc_dic[case["testsuite_id"]] tests = [] # if we do not force to download everythin we get already defined tests to avoid erasing them if not args.download_all: tests += list(set([a for a in get_test_names(defaultTestLoader.discover(args.dest_dir))])) # launch true creation for to_be_created in cases: if to_be_created["tcase_name"] not in tests: create_test_file(to_be_created, args.dest_dir, to_be_created["keyword"] == UI_TEST_KEYWORD, args.plan)
def __init__(self): tlk_helper = TestLinkHelper() try: self.testlink = tlk_helper.connect(TestlinkAPIClient) # 连接TestLink except Exception as e: logger.error('连接testlink失败:%s' % e) exit()
def __init__(self): tlk_helper = TestLinkHelper( server_url= 'http://192.168.202.174/testlink-1.9.17/lib/api/xmlrpc/v1/xmlrpc.php', devkey='0b839ca6b6a4d8b78139e5f5f93c38f1') try: self.testlink = tlk_helper.connect(TestlinkAPIClient) # 连接TestLink except Exception as e: logger.error('连接testlink失败:%s' % e) exit()
def afterEditing(self): self.parentApp.host = self.hostBox.value self.parentApp.devkey = self.devkeyBox.value try: self.statusBox.value = 'Connecting...' tlh = TestLinkHelper(server_url='http://'+self.parentApp.host+'/lib/api/xmlrpc/v1/xmlrpc.php', devkey=self.parentApp.devkey) self.parentApp.tl = tlh.connect(TestlinkAPIClient) self.parentApp.tl.sayHello() except testlinkerrors.TLConnectionError as err: self.statusBox.value = err else: self.parentApp.setNextForm('IMPORT')
def __init__(self, server_url, project_id, platformname, must_create_build, testlink_key, verbose=False, generate_xml=False): self.server_url = server_url self.generate_xml = generate_xml self.project_id = project_id self.platformname = platformname self.must_create_build = must_create_build self.testlink_key = testlink_key tl_helper = TestLinkHelper(self.server_url, self.testlink_key) self.testlink_client = tl_helper.connect(TestlinkAPIClient) self.plans = self.testlink_client.getProjectTestPlans(self.project_id) self.verbose = verbose
def create_api_client(self, client_class='TestlinkAPIClient', server_url=None, devkey=None): """Creates a new TestLink-API-Python-client (XMLRPC), using Python class TestlinkAPIClient or TestlinkAPIGeneric. """ a_server_url = server_url or self._server_url a_devkey = devkey or self._devkey a_helper = TestLinkHelper(a_server_url, a_devkey) a_class_name = client_class or self._client_class a_api_class = globals()[a_class_name] self.api_client = a_helper.connect(a_api_class) return self.api_client
# # alternative precondition b) # SERVEUR_URL and KEY are defined as command line arguments # python TestLinkExample.py --server_url http://YOURSERVER/testlink/lib/api/xmlrpc.php # --devKey 7ec252ab966ce88fd92c25d08635672b # # ATTENTION: With TestLink 1.9.7, cause of the new REST API, the SERVER_URL # has changed from # (old) http://YOURSERVER/testlink/lib/api/xmlrpc.php # to # (new) http://YOURSERVER/testlink/lib/api/xmlrpc/v1/xmlrpc.php tl_helper = TestLinkHelper() tl_helper.setParamsFromArgs( '''Shows how to use the TestLinkAPI for CustomFields. => requires an existing project PROJECT_API_GENERIC-*''') myTestLink = tl_helper.connect(TestlinkAPIGeneric) myPyVersion = python_version() myPyVersionShort = myPyVersion.replace('.', '')[:2] NEWTESTPLAN_A = "TestPlan_API_GENERIC A" # NEWTESTPLAN_B="TestPlan_API_GENERIC B" # NEWTESTPLAN_C="TestPlan_API_GENERIC C - DeleteTest" # NEWPLATFORM_A='Big Bird %s' % myPyVersionShort NEWPLATFORM_B = 'Small Bird' # NEWPLATFORM_C='Ugly Bird' NEWTESTSUITE_A = "A - First Level" NEWTESTSUITE_B = "B - First Level" NEWTESTSUITE_AA = "AA - Second Level" NEWTESTCASE_AA = "TESTCASE_AA" NEWTESTCASE_B = "TESTCASE_B"
# # alternative precondition b) # SERVEUR_URL and KEY are defined as command line arguments # python TestLinkExample.py --server_url http://YOURSERVER/testlink/lib/api/xmlrpc.php # --devKey 7ec252ab966ce88fd92c25d08635672b # # ATTENTION: With TestLink 1.9.7, cause of the new REST API, the SERVER_URL # has changed from # (old) http://YOURSERVER/testlink/lib/api/xmlrpc.php # to # (new) http://YOURSERVER/testlink/lib/api/xmlrpc/v1/xmlrpc.php tl_helper = TestLinkHelper() tl_helper.setParamsFromArgs('''Shows how to use the TestLinkAPI. => Counts and lists the Projects => Create a new Project with the following structure:''') myTestLink = tl_helper.connect(TestlinkAPIGeneric) myPyVersion = python_version() myPyVersionShort = myPyVersion.replace('.', '')[:2] NEWTESTPLAN_A="TestPlan_API_GENERIC A" NEWTESTPLAN_B="TestPlan_API_GENERIC B" NEWTESTPLAN_C="TestPlan_API_GENERIC C - DeleteTest" NEWPLATFORM_A='Big Bird %s' % myPyVersionShort NEWPLATFORM_B='Small Bird' NEWPLATFORM_C='Ugly Bird' NEWTESTSUITE_A="A - First Level" NEWTESTSUITE_B="B - First Level" NEWTESTSUITE_AA="AA - Second Level" NEWTESTCASE_AA="TESTCASE_AA" NEWTESTCASE_B="TESTCASE_B"
# TESTLINK_API_PYTHON_DEVKEY=7ec252ab966ce88fd92c25d08635672b # # alternative precondition b) # SERVEUR_URL and KEY are defined as command line arguments # python TestLinkExample.py --server_url http://YOURSERVER/testlink/lib/api/xmlrpc.php # --devKey 7ec252ab966ce88fd92c25d08635672b # # ATTENTION: With TestLink 1.9.7, cause of the new REST API, the SERVER_URL # has changed from # (old) http://YOURSERVER/testlink/lib/api/xmlrpc.php # to # (new) http://YOURSERVER/testlink/lib/api/xmlrpc/v1/xmlrpc.php tl_helper = TestLinkHelper() tl_helper.setParamsFromArgs('''Shows how to use the TestLinkAPI for CustomFields. => requires an existing project NEW_PROJECT_API-*''') myTestLink = tl_helper.connect(TestlinkAPIClient) myPyVersion = python_version() myPyVersionShort = myPyVersion.replace('.', '')[:2] NEWPROJECT="NEW_PROJECT_API-%s" % myPyVersionShort NEWPREFIX="NPROAPI%s" % myPyVersionShort NEWTESTPLAN_A="TestPlan_API A" # NEWTESTPLAN_B="TestPlan_API B" # NEWPLATFORM_A='Big Bird %i' % projNr NEWPLATFORM_B='Small Birds' # NEWPLATFORM_C='Ugly Bird' NEWTESTSUITE_A="A - First Level" NEWTESTSUITE_B="B - First Level" NEWTESTSUITE_AA="AA - Second Level" NEWTESTCASE_AA="TESTCASE_AA"
# # alternative precondition b) # SERVEUR_URL and KEY are defined as command line arguments # python TestLinkExample.py --server_url http://YOURSERVER/testlink/lib/api/xmlrpc.php # --devKey 7ec252ab966ce88fd92c25d08635672b # # ATTENTION: With TestLink 1.9.7, cause of the new REST API, the SERVER_URL # has changed from # (old) http://YOURSERVER/testlink/lib/api/xmlrpc.php # to # (new) http://YOURSERVER/testlink/lib/api/xmlrpc/v1/xmlrpc.php tl_helper = TestLinkHelper() tl_helper.setParamsFromArgs('''Shows how to use the TestLinkAPI. => Counts and lists the Projects => Create a new Project with the following structure:''') myTestLink = tl_helper.connect(TestlinkAPIClient) myPyVersion = python_version() myPyVersionShort = myPyVersion.replace('.', '')[:2] NEWTESTPLAN_A="TestPlan_API A" NEWTESTPLAN_B="TestPlan_API B" NEWTESTPLAN_C="TestPlan_API C - DeleteTest" NEWTESTPLAN_G="TestPlan_API G - generated" NEWPLATFORM_A='Big Birds %s' % myPyVersionShort NEWPLATFORM_B='Small Birds' NEWPLATFORM_C='Ugly Birds' NEWPLATFORM_G='generated Birds' NEWTESTSUITE_A="A - First Level" NEWTESTSUITE_B="B - First Level" NEWTESTSUITE_AA="AA - Second Level"