Loading examples/SOL002/Another-API/IndividualVNFPackage.robot 0 → 100644 +68 −0 Original line number Diff line number Diff line *** Settings *** Library JSONSchemaLibrary schemas/ Resource environment/generic.txt # Generic Parameters Resource environment/individualVnfPackage.txt Library JSONLibrary Library REST ${NFVO_SCHEMA}://${NFVO_HOST}:${NFVO_PORT} *** Test Cases *** GET Individual VNF Package Log Trying to get a VNF Package present in the NFVO Catalogue Set Headers {"Accept": "${ACCEPT_JSON}"} Run Keyword If ${AUTH_USAGE} == 1 Set Headers {"Authorization": "${AUTHORIZATION}"} GET ${apiRoot}/${apiName}/${apiVersion}/vnf_packages/${vnfPackageId} Integer response status 200 ${contentType}= Output response headers Content-Type Should Contain ${contentType} ${CONTENT_TYPE_JSON} Log Trying to validate response ${vnfPkgInfo}= Output response body ${json}= evaluate json.loads('''${vnfPkgInfo}''') json Validate Json vnfPkgInfo.schema.json ${json} Log Validation OK GET Individual VNF Package - Negative (Not Found) Log Trying to perform a negative get, using wrong authorization bearer Set Headers {"Accept": "${ACCEPT_JSON}"} Run Keyword If ${AUTH_USAGE} == 1 Set Headers {"Authorization": "${AUTHORIZATION}"} GET ${apiRoot}/${apiName}/${apiVersion}/vnf_packages/${erroneousVnfPackageId} Integer response status 404 Log Received 404 Not Found as expected ${contentType}= Output response headers Content-Type Should Contain ${contentType} ${CONTENT_TYPE_JSON} Log Trying to validate ProblemDetails ${problemDetails}= Output response body ${json}= evaluate json.loads('''${problemDetails}''') json Validate Json ProblemDetails.schema.json ${json} Log Validation OK POST Individual VNF Package - (Method not implemented) Log Trying to perform a POST (method should not be implemented) Set Headers {"Accept": "${ACCEPT_JSON}"} Run Keyword If ${AUTH_USAGE} == 1 Set Headers {"Authorization": "${AUTHORIZATION}"} POST ${apiRoot}/${apiName}/${apiVersion}/vnf_packages/${vnfPackageId} Integer response status 405 Log Received 405 Method not implemented as expected PUT Individual VNF Package - (Method not implemented) Log Trying to perform a PUT. This method should not be implemented Set Headers {"Accept": "${ACCEPT_JSON}"} Run Keyword If ${AUTH_USAGE} == 1 Set Headers {"Authorization": "${AUTHORIZATION}"} PUT ${apiRoot}/${apiName}/${apiVersion}/vnf_packages/${vnfPackageId} Integer response status 405 Log Received 405 Method not implemented as expected PATCH Individual VNF Package - (Method not implemented) Log Trying to perform a PATCH. This method should not be implemented Set Headers {"Accept": "${ACCEPT_JSON}"} Run Keyword If ${AUTH_USAGE} == 1 Set Headers {"Authorization": "${AUTHORIZATION}"} PATCH ${apiRoot}/${apiName}/${apiVersion}/vnf_packages/${vnfPackageId} Integer response status 405 Log Received 405 Method not implemented as expected DELETE Individual VNF Package - (Method not implemented) Log Trying to perform a DELETE. This method should not be implemented Set Headers {"Accept": "${ACCEPT_JSON}"} Run Keyword If ${AUTH_USAGE} == 1 Set Headers {"Authorization": "${AUTHORIZATION}"} DELETE ${apiRoot}/${apiName}/${apiVersion}/vnf_packages/${vnfPackageId} Integer response status 405 Log Received 405 Method not implemented as expected robot2doc/config.py +4 −4 Original line number Diff line number Diff line #!/env/python #!/env/python3 VERSION = "0.0.3" VERSION = "0.0.4" DOC_CLAUSE_LVL_1 = "9" DOC_CLAUSE_LVL_1 = "6" DOC_CLAUSE_LVL_2 = 8 DOC_CLAUSE_LVL_3 = 7 DOC_CLAUSE_LVL_4 = 6 Loading Loading @@ -30,4 +30,4 @@ QUIET = False # the Robot file. NOTE: if the final slash is not present it will not be included. # Example: # GIT_COMMIT = "http://acme.com/my/example/abcde/" GIT_COMMIT_PREFIX = "https://forge.etsi.org/rep/nfv/api-tests/raw/deadbeef" GIT_URL_PREFIX = "https://forge.etsi.org/rep/nfv/api-tests/raw/" robot2doc/lib.py 0 → 100644 +148 −0 Original line number Diff line number Diff line #!/env/python3 import os import sys from robot.api import TestSuiteBuilder import config from testspec import TestSpec, DOC_TC_LEVEL from testpurpose import TP DOC_CLAUSE_LVL_1 = config.DOC_CLAUSE_LVL_1 DOC_CLAUSE_LVL_2 = config.DOC_CLAUSE_LVL_2 DOC_CLAUSE_LVL_3 = config.DOC_CLAUSE_LVL_3 DOC_CLAUSE_LVL_4 = config.DOC_CLAUSE_LVL_4 DRY_RUN = config.DRY_RUN QUIET = config.QUIET BASE_SPEC = config.BASE_SPEC class TestDoc(): def __init__(self,src, doc_fn, doc_main_tit, commit_id, sol, api): self.src = src self.doc_fn = doc_fn self.doc_main_tit = doc_main_tit self.commit_id = commit_id self.sol = sol self.api = api def keyword_to_line(k): ''' Takes a Robot Framework keyword object and returns a string with keyword and arguments on a single line ''' return str(k) + " " + " ".join(k.args) def keywords_to_text(kws): ''' Takes a list of Robot Framework words and returns a multiline text ''' return "\n".join(map(keyword_to_line, kws)) def gen_test(suite, this_test, spec, sec, subsec, workspace, commit_id, sol, api): ''' Generate the Docx part for an individual test ''' ntp = TP(this_test.doc) log_line = ["TD", str(workspace), str(suite), str(this_test), ntp.tp_id or "No ID"] not QUIET and print(",".join(log_line)) if DRY_RUN: return if ntp.tp_id is not None: spec.add_heading(str(this_test), DOC_TC_LEVEL, ntp.tp_id) else: subsec = subsec + 1 spec.add_heading( str(this_test), DOC_TC_LEVEL, DOC_CLAUSE_LVL_1, sec, DOC_CLAUSE_LVL_3, subsec ) ntp.add_to_spec( spec, keywords_to_text(this_test.keywords), str(suite)+".robot", commit_id, sol, api ) def gen_api_suite(sec, suite, spec, workspace, commit_id, sol, api): sec = sec + 1 subsec = DOC_CLAUSE_LVL_4 print(" Generating test suite: " + str(suite)) spec.add_sub_heading(str(suite), DOC_CLAUSE_LVL_1, sec, DOC_CLAUSE_LVL_3, subsec) for i in suite.tests: gen_test(suite, i, spec, sec, subsec, workspace, commit_id, sol, api) def gen_doc(src, doc_fn, doc_main_tit, commit_id, sol, api): ''' Converts a Robot test suite to a word document src file or directory containing Robot tests doc_fn the filename for the output doc_main_tit top level title for the section in the doc ''' not QUIET and print("### robot2doc version " + config.VERSION) not QUIET and print("Starting..") script_dir = os.path.dirname(os.path.realpath(__file__)) cwd = os.getcwd() # Using the absolute path has caused issues. The quick fix is to # move temporarily to the source directory os.chdir(script_dir) try: spec = TestSpec(BASE_SPEC) finally: os.chdir(cwd) print("Loading tests from: " + str(src)) workspace = [] try: if isinstance(src, list): for suites_folder in src: workspace.append(TestSuiteBuilder().build(suites_folder)) else: workspace.append(TestSuiteBuilder().build(src)) except: print("Please check that first argument is a folder of Robot files or a single file.") sys.exit(-1) tot_suites = sum([len(x.suites) for x in workspace]) tot_tests = sum([len(x.tests) for x in workspace]) not QUIET and print("Loaded "+ str(tot_suites) + " test suites.") not QUIET and print("Loaded "+ str(tot_tests) + " tests.") sec = DOC_CLAUSE_LVL_2 - 1 for api_dir in workspace: spec.add_main_heading(DOC_CLAUSE_LVL_1 + "\t" + str(api_dir)) # TODO # spec.add_main_heading(doc_main_tit) for test_file in api_dir.suites: print("------> ", api_dir, test_file) gen_api_suite(sec, test_file, spec, api_dir, commit_id, sol, str(api_dir)) if len(api_dir.suites) == 0: suite = str(api_dir) gen_api_suite(sec, suite, spec, workspace, commit_id, sol, api_dir) not QUIET and print("Saving to: " + doc_fn) not DRY_RUN and spec.save(doc_fn) not QUIET and print("Finished.") robot2doc/main.py +32 −115 Original line number Diff line number Diff line #!/env/python #!/env/python3 # # Usage: python main.py <FILE_OR_FOLDER> [OUTPUT_FILENAME [MAIN_TITLE]] # import sys import os import sys from robot.api import TestSuiteBuilder from testspec import TestSpec, DOC_TC_LEVEL from testpurpose import TP import config as cfg # Configuration DOC_CLAUSE_LVL_1 = cfg.DOC_CLAUSE_LVL_1 DOC_CLAUSE_LVL_2 = cfg.DOC_CLAUSE_LVL_2 DOC_CLAUSE_LVL_3 = cfg.DOC_CLAUSE_LVL_3 DOC_CLAUSE_LVL_4 = cfg.DOC_CLAUSE_LVL_4 DOC_MAIN_TITLE = cfg.DOC_MAIN_TITLE DOC_FILENAME = cfg.DOC_FILENAME FILE = cfg.DOC_FILENAME BASE_SPEC = cfg.BASE_SPEC DRY_RUN = cfg.DRY_RUN QUIET = cfg.QUIET def keyword_to_line(k): ''' Takes a Robot Framework keyword object and returns a string with keyword and arguments on a single line ''' return str(k) + " " + " ".join(k.args) def keywords_to_text(kws): ''' Takes a list of Robot Framework words and returns a multiline text ''' return "\n".join(map(keyword_to_line, kws)) def gen_test(suite, this_test, spec, sec, subsec, workspace, commit_id, sol, api): ''' Generate the Docx part for an individual test ''' global DRY_RUN ntp = TP(this_test.doc) log_line = ["TD", str(workspace), str(suite), str(this_test), ntp.tp_id or "No ID"] not QUIET and print(",".join(log_line)) if DRY_RUN: return if ntp.tp_id is not None: spec.add_heading(str(this_test), DOC_TC_LEVEL, ntp.tp_id) else: subsec = subsec + 1 spec.add_heading(str(this_test), DOC_TC_LEVEL, DOC_CLAUSE_LVL_1, sec, DOC_CLAUSE_LVL_3, subsec) tp.add_to_spec(spec, keywords_to_text(this_test.keywords), str(suite)+".robot", commit_id, sol, api) def gen_doc(src, doc_fn, doc_main_tit, commit_id, sol, api): ''' Converts a Robot test suite to a word document src file or directory containing Robot tests doc_fn the filename for the output doc_main_tit top level title for the section in the doc ''' not QUIET and print("### robot2doc version " + cfg.VERSION) not QUIET and print("Starting..") script_dir = os.path.dirname(os.path.realpath(__file__)) cwd = os.getcwd() # Using the absolute path has caused issues. The quick fix is to # move temporarily to the source directory os.chdir(script_dir) try: spec = TestSpec(BASE_SPEC) finally: os.chdir(cwd) print("Loading tests from: " + src) try: workspace = TestSuiteBuilder().build(src) except: print("Please check that first argument is a folder of Robot files or a single file.") sys.exit(-1) not QUIET and print("Loaded "+ str(len(workspace.suites)) + " test suites.") not QUIET and print("Loaded "+ str(len(workspace.tests)) + " tests.") sec = DOC_CLAUSE_LVL_2 - 1 spec.add_main_heading(doc_main_tit) for suite in workspace.suites: sec = sec + 1 subsec = DOC_CLAUSE_LVL_4 print(" Generating test suite: " + str(suite)) spec.add_sub_heading(str(suite), DOC_CLAUSE_LVL_1, sec, DOC_CLAUSE_LVL_3, subsec) for i in suite.tests: gen_test(suite, i, spec, sec, subsec, workspace, commit_id, sol, api) if len(workspace.suites) == 0: sec = sec + 1 subsec = DOC_CLAUSE_LVL_4 suite = str(workspace) spec.add_sub_heading(suite, DOC_CLAUSE_LVL_1, sec, DOC_CLAUSE_LVL_3, subsec) for i in workspace.tests: gen_test(suite, i, spec, sec, subsec, workspace, commit_id, sol, api) not QUIET and print("Saving to: " + doc_fn) not DRY_RUN and spec.save(doc_fn) not QUIET and print("Finished.") import config import lib if __name__ == "__main__": Loading @@ -123,10 +16,34 @@ if __name__ == "__main__": sys.exit(-1) FILE = sys.argv[1] DOC_FILENAME = sys.argv[2] if len(sys.argv) > 2 else DOC_FILENAME DOC_MAIN_TITLE = sys.argv[3] if len(sys.argv) > 3 else DOC_MAIN_TITLE DOC_FILENAME = sys.argv[2] if len(sys.argv) > 2 else config.DOC_FILENAME DOC_MAIN_TITLE = sys.argv[3] if len(sys.argv) > 3 else config.DOC_MAIN_TITLE COMMIT_ID = sys.argv[4] if len(sys.argv) > 4 else None SOL = sys.argv[5] if len(sys.argv) > 5 else None API = sys.argv[6] if len(sys.argv) > 6 else None print(sys.argv[1:]) gen_doc(FILE, DOC_FILENAME, DOC_MAIN_TITLE, COMMIT_ID, SOL, API) print("Received arguments: ", sys.argv[1:]) tstdoc = lib.TestDoc(FILE, DOC_FILENAME, DOC_MAIN_TITLE, COMMIT_ID, SOL, API) if FILE.split("/")[-1].startswith("SOL0"): sol = FILE.split("/")[-1] apis = [ os.path.realpath(os.path.join(FILE, item.name)) for item in os.scandir(FILE) if item.is_dir() ] lib.gen_doc( apis, DOC_FILENAME, DOC_MAIN_TITLE, COMMIT_ID, sol, "MICHELE" ) #for item in os.scandir(FILE): # if item.is_dir(): sys.exit(1) lib.gen_doc(FILE, DOC_FILENAME, DOC_MAIN_TITLE, COMMIT_ID, SOL, API) robot2doc/testpurpose.py +5 −4 Original line number Diff line number Diff line Loading @@ -32,7 +32,8 @@ class TP(): self.tp_id = field.value continue if field.value and not field.value[0].isupper(): raise Exception("Found field starting with lowercase character: " + field.value) print("WARNING: Found field starting with lowercase character: " + field.value) #raise Exception("Found field starting with lowercase character: " + field.value) if field.key.startswith("Reference"): if "ETSI GS NFV-SOL" not in field.value: raise Exception( Loading @@ -49,11 +50,11 @@ class TP(): ''' spec.add_tp(self.tp_fields, testbehaviour) configured_prefix = config.GIT_COMMIT_PREFIX configured_prefix = config.GIT_URL_PREFIX if commit_id is not None: spec.add_commit_url(robot_file, commit_id, sol, api) spec.add_commit_url(robot_file, configured_prefix + commit_id, sol, api) else: if configured_prefix != "": spec.add_commit_url(robot_file, configured_prefix, "SOLAAA", "MyAPI") spec.add_commit_url(robot_file, configured_prefix + "deadbeed", "SOLAAA", "MyAPI") Loading
examples/SOL002/Another-API/IndividualVNFPackage.robot 0 → 100644 +68 −0 Original line number Diff line number Diff line *** Settings *** Library JSONSchemaLibrary schemas/ Resource environment/generic.txt # Generic Parameters Resource environment/individualVnfPackage.txt Library JSONLibrary Library REST ${NFVO_SCHEMA}://${NFVO_HOST}:${NFVO_PORT} *** Test Cases *** GET Individual VNF Package Log Trying to get a VNF Package present in the NFVO Catalogue Set Headers {"Accept": "${ACCEPT_JSON}"} Run Keyword If ${AUTH_USAGE} == 1 Set Headers {"Authorization": "${AUTHORIZATION}"} GET ${apiRoot}/${apiName}/${apiVersion}/vnf_packages/${vnfPackageId} Integer response status 200 ${contentType}= Output response headers Content-Type Should Contain ${contentType} ${CONTENT_TYPE_JSON} Log Trying to validate response ${vnfPkgInfo}= Output response body ${json}= evaluate json.loads('''${vnfPkgInfo}''') json Validate Json vnfPkgInfo.schema.json ${json} Log Validation OK GET Individual VNF Package - Negative (Not Found) Log Trying to perform a negative get, using wrong authorization bearer Set Headers {"Accept": "${ACCEPT_JSON}"} Run Keyword If ${AUTH_USAGE} == 1 Set Headers {"Authorization": "${AUTHORIZATION}"} GET ${apiRoot}/${apiName}/${apiVersion}/vnf_packages/${erroneousVnfPackageId} Integer response status 404 Log Received 404 Not Found as expected ${contentType}= Output response headers Content-Type Should Contain ${contentType} ${CONTENT_TYPE_JSON} Log Trying to validate ProblemDetails ${problemDetails}= Output response body ${json}= evaluate json.loads('''${problemDetails}''') json Validate Json ProblemDetails.schema.json ${json} Log Validation OK POST Individual VNF Package - (Method not implemented) Log Trying to perform a POST (method should not be implemented) Set Headers {"Accept": "${ACCEPT_JSON}"} Run Keyword If ${AUTH_USAGE} == 1 Set Headers {"Authorization": "${AUTHORIZATION}"} POST ${apiRoot}/${apiName}/${apiVersion}/vnf_packages/${vnfPackageId} Integer response status 405 Log Received 405 Method not implemented as expected PUT Individual VNF Package - (Method not implemented) Log Trying to perform a PUT. This method should not be implemented Set Headers {"Accept": "${ACCEPT_JSON}"} Run Keyword If ${AUTH_USAGE} == 1 Set Headers {"Authorization": "${AUTHORIZATION}"} PUT ${apiRoot}/${apiName}/${apiVersion}/vnf_packages/${vnfPackageId} Integer response status 405 Log Received 405 Method not implemented as expected PATCH Individual VNF Package - (Method not implemented) Log Trying to perform a PATCH. This method should not be implemented Set Headers {"Accept": "${ACCEPT_JSON}"} Run Keyword If ${AUTH_USAGE} == 1 Set Headers {"Authorization": "${AUTHORIZATION}"} PATCH ${apiRoot}/${apiName}/${apiVersion}/vnf_packages/${vnfPackageId} Integer response status 405 Log Received 405 Method not implemented as expected DELETE Individual VNF Package - (Method not implemented) Log Trying to perform a DELETE. This method should not be implemented Set Headers {"Accept": "${ACCEPT_JSON}"} Run Keyword If ${AUTH_USAGE} == 1 Set Headers {"Authorization": "${AUTHORIZATION}"} DELETE ${apiRoot}/${apiName}/${apiVersion}/vnf_packages/${vnfPackageId} Integer response status 405 Log Received 405 Method not implemented as expected
robot2doc/config.py +4 −4 Original line number Diff line number Diff line #!/env/python #!/env/python3 VERSION = "0.0.3" VERSION = "0.0.4" DOC_CLAUSE_LVL_1 = "9" DOC_CLAUSE_LVL_1 = "6" DOC_CLAUSE_LVL_2 = 8 DOC_CLAUSE_LVL_3 = 7 DOC_CLAUSE_LVL_4 = 6 Loading Loading @@ -30,4 +30,4 @@ QUIET = False # the Robot file. NOTE: if the final slash is not present it will not be included. # Example: # GIT_COMMIT = "http://acme.com/my/example/abcde/" GIT_COMMIT_PREFIX = "https://forge.etsi.org/rep/nfv/api-tests/raw/deadbeef" GIT_URL_PREFIX = "https://forge.etsi.org/rep/nfv/api-tests/raw/"
robot2doc/lib.py 0 → 100644 +148 −0 Original line number Diff line number Diff line #!/env/python3 import os import sys from robot.api import TestSuiteBuilder import config from testspec import TestSpec, DOC_TC_LEVEL from testpurpose import TP DOC_CLAUSE_LVL_1 = config.DOC_CLAUSE_LVL_1 DOC_CLAUSE_LVL_2 = config.DOC_CLAUSE_LVL_2 DOC_CLAUSE_LVL_3 = config.DOC_CLAUSE_LVL_3 DOC_CLAUSE_LVL_4 = config.DOC_CLAUSE_LVL_4 DRY_RUN = config.DRY_RUN QUIET = config.QUIET BASE_SPEC = config.BASE_SPEC class TestDoc(): def __init__(self,src, doc_fn, doc_main_tit, commit_id, sol, api): self.src = src self.doc_fn = doc_fn self.doc_main_tit = doc_main_tit self.commit_id = commit_id self.sol = sol self.api = api def keyword_to_line(k): ''' Takes a Robot Framework keyword object and returns a string with keyword and arguments on a single line ''' return str(k) + " " + " ".join(k.args) def keywords_to_text(kws): ''' Takes a list of Robot Framework words and returns a multiline text ''' return "\n".join(map(keyword_to_line, kws)) def gen_test(suite, this_test, spec, sec, subsec, workspace, commit_id, sol, api): ''' Generate the Docx part for an individual test ''' ntp = TP(this_test.doc) log_line = ["TD", str(workspace), str(suite), str(this_test), ntp.tp_id or "No ID"] not QUIET and print(",".join(log_line)) if DRY_RUN: return if ntp.tp_id is not None: spec.add_heading(str(this_test), DOC_TC_LEVEL, ntp.tp_id) else: subsec = subsec + 1 spec.add_heading( str(this_test), DOC_TC_LEVEL, DOC_CLAUSE_LVL_1, sec, DOC_CLAUSE_LVL_3, subsec ) ntp.add_to_spec( spec, keywords_to_text(this_test.keywords), str(suite)+".robot", commit_id, sol, api ) def gen_api_suite(sec, suite, spec, workspace, commit_id, sol, api): sec = sec + 1 subsec = DOC_CLAUSE_LVL_4 print(" Generating test suite: " + str(suite)) spec.add_sub_heading(str(suite), DOC_CLAUSE_LVL_1, sec, DOC_CLAUSE_LVL_3, subsec) for i in suite.tests: gen_test(suite, i, spec, sec, subsec, workspace, commit_id, sol, api) def gen_doc(src, doc_fn, doc_main_tit, commit_id, sol, api): ''' Converts a Robot test suite to a word document src file or directory containing Robot tests doc_fn the filename for the output doc_main_tit top level title for the section in the doc ''' not QUIET and print("### robot2doc version " + config.VERSION) not QUIET and print("Starting..") script_dir = os.path.dirname(os.path.realpath(__file__)) cwd = os.getcwd() # Using the absolute path has caused issues. The quick fix is to # move temporarily to the source directory os.chdir(script_dir) try: spec = TestSpec(BASE_SPEC) finally: os.chdir(cwd) print("Loading tests from: " + str(src)) workspace = [] try: if isinstance(src, list): for suites_folder in src: workspace.append(TestSuiteBuilder().build(suites_folder)) else: workspace.append(TestSuiteBuilder().build(src)) except: print("Please check that first argument is a folder of Robot files or a single file.") sys.exit(-1) tot_suites = sum([len(x.suites) for x in workspace]) tot_tests = sum([len(x.tests) for x in workspace]) not QUIET and print("Loaded "+ str(tot_suites) + " test suites.") not QUIET and print("Loaded "+ str(tot_tests) + " tests.") sec = DOC_CLAUSE_LVL_2 - 1 for api_dir in workspace: spec.add_main_heading(DOC_CLAUSE_LVL_1 + "\t" + str(api_dir)) # TODO # spec.add_main_heading(doc_main_tit) for test_file in api_dir.suites: print("------> ", api_dir, test_file) gen_api_suite(sec, test_file, spec, api_dir, commit_id, sol, str(api_dir)) if len(api_dir.suites) == 0: suite = str(api_dir) gen_api_suite(sec, suite, spec, workspace, commit_id, sol, api_dir) not QUIET and print("Saving to: " + doc_fn) not DRY_RUN and spec.save(doc_fn) not QUIET and print("Finished.")
robot2doc/main.py +32 −115 Original line number Diff line number Diff line #!/env/python #!/env/python3 # # Usage: python main.py <FILE_OR_FOLDER> [OUTPUT_FILENAME [MAIN_TITLE]] # import sys import os import sys from robot.api import TestSuiteBuilder from testspec import TestSpec, DOC_TC_LEVEL from testpurpose import TP import config as cfg # Configuration DOC_CLAUSE_LVL_1 = cfg.DOC_CLAUSE_LVL_1 DOC_CLAUSE_LVL_2 = cfg.DOC_CLAUSE_LVL_2 DOC_CLAUSE_LVL_3 = cfg.DOC_CLAUSE_LVL_3 DOC_CLAUSE_LVL_4 = cfg.DOC_CLAUSE_LVL_4 DOC_MAIN_TITLE = cfg.DOC_MAIN_TITLE DOC_FILENAME = cfg.DOC_FILENAME FILE = cfg.DOC_FILENAME BASE_SPEC = cfg.BASE_SPEC DRY_RUN = cfg.DRY_RUN QUIET = cfg.QUIET def keyword_to_line(k): ''' Takes a Robot Framework keyword object and returns a string with keyword and arguments on a single line ''' return str(k) + " " + " ".join(k.args) def keywords_to_text(kws): ''' Takes a list of Robot Framework words and returns a multiline text ''' return "\n".join(map(keyword_to_line, kws)) def gen_test(suite, this_test, spec, sec, subsec, workspace, commit_id, sol, api): ''' Generate the Docx part for an individual test ''' global DRY_RUN ntp = TP(this_test.doc) log_line = ["TD", str(workspace), str(suite), str(this_test), ntp.tp_id or "No ID"] not QUIET and print(",".join(log_line)) if DRY_RUN: return if ntp.tp_id is not None: spec.add_heading(str(this_test), DOC_TC_LEVEL, ntp.tp_id) else: subsec = subsec + 1 spec.add_heading(str(this_test), DOC_TC_LEVEL, DOC_CLAUSE_LVL_1, sec, DOC_CLAUSE_LVL_3, subsec) tp.add_to_spec(spec, keywords_to_text(this_test.keywords), str(suite)+".robot", commit_id, sol, api) def gen_doc(src, doc_fn, doc_main_tit, commit_id, sol, api): ''' Converts a Robot test suite to a word document src file or directory containing Robot tests doc_fn the filename for the output doc_main_tit top level title for the section in the doc ''' not QUIET and print("### robot2doc version " + cfg.VERSION) not QUIET and print("Starting..") script_dir = os.path.dirname(os.path.realpath(__file__)) cwd = os.getcwd() # Using the absolute path has caused issues. The quick fix is to # move temporarily to the source directory os.chdir(script_dir) try: spec = TestSpec(BASE_SPEC) finally: os.chdir(cwd) print("Loading tests from: " + src) try: workspace = TestSuiteBuilder().build(src) except: print("Please check that first argument is a folder of Robot files or a single file.") sys.exit(-1) not QUIET and print("Loaded "+ str(len(workspace.suites)) + " test suites.") not QUIET and print("Loaded "+ str(len(workspace.tests)) + " tests.") sec = DOC_CLAUSE_LVL_2 - 1 spec.add_main_heading(doc_main_tit) for suite in workspace.suites: sec = sec + 1 subsec = DOC_CLAUSE_LVL_4 print(" Generating test suite: " + str(suite)) spec.add_sub_heading(str(suite), DOC_CLAUSE_LVL_1, sec, DOC_CLAUSE_LVL_3, subsec) for i in suite.tests: gen_test(suite, i, spec, sec, subsec, workspace, commit_id, sol, api) if len(workspace.suites) == 0: sec = sec + 1 subsec = DOC_CLAUSE_LVL_4 suite = str(workspace) spec.add_sub_heading(suite, DOC_CLAUSE_LVL_1, sec, DOC_CLAUSE_LVL_3, subsec) for i in workspace.tests: gen_test(suite, i, spec, sec, subsec, workspace, commit_id, sol, api) not QUIET and print("Saving to: " + doc_fn) not DRY_RUN and spec.save(doc_fn) not QUIET and print("Finished.") import config import lib if __name__ == "__main__": Loading @@ -123,10 +16,34 @@ if __name__ == "__main__": sys.exit(-1) FILE = sys.argv[1] DOC_FILENAME = sys.argv[2] if len(sys.argv) > 2 else DOC_FILENAME DOC_MAIN_TITLE = sys.argv[3] if len(sys.argv) > 3 else DOC_MAIN_TITLE DOC_FILENAME = sys.argv[2] if len(sys.argv) > 2 else config.DOC_FILENAME DOC_MAIN_TITLE = sys.argv[3] if len(sys.argv) > 3 else config.DOC_MAIN_TITLE COMMIT_ID = sys.argv[4] if len(sys.argv) > 4 else None SOL = sys.argv[5] if len(sys.argv) > 5 else None API = sys.argv[6] if len(sys.argv) > 6 else None print(sys.argv[1:]) gen_doc(FILE, DOC_FILENAME, DOC_MAIN_TITLE, COMMIT_ID, SOL, API) print("Received arguments: ", sys.argv[1:]) tstdoc = lib.TestDoc(FILE, DOC_FILENAME, DOC_MAIN_TITLE, COMMIT_ID, SOL, API) if FILE.split("/")[-1].startswith("SOL0"): sol = FILE.split("/")[-1] apis = [ os.path.realpath(os.path.join(FILE, item.name)) for item in os.scandir(FILE) if item.is_dir() ] lib.gen_doc( apis, DOC_FILENAME, DOC_MAIN_TITLE, COMMIT_ID, sol, "MICHELE" ) #for item in os.scandir(FILE): # if item.is_dir(): sys.exit(1) lib.gen_doc(FILE, DOC_FILENAME, DOC_MAIN_TITLE, COMMIT_ID, SOL, API)
robot2doc/testpurpose.py +5 −4 Original line number Diff line number Diff line Loading @@ -32,7 +32,8 @@ class TP(): self.tp_id = field.value continue if field.value and not field.value[0].isupper(): raise Exception("Found field starting with lowercase character: " + field.value) print("WARNING: Found field starting with lowercase character: " + field.value) #raise Exception("Found field starting with lowercase character: " + field.value) if field.key.startswith("Reference"): if "ETSI GS NFV-SOL" not in field.value: raise Exception( Loading @@ -49,11 +50,11 @@ class TP(): ''' spec.add_tp(self.tp_fields, testbehaviour) configured_prefix = config.GIT_COMMIT_PREFIX configured_prefix = config.GIT_URL_PREFIX if commit_id is not None: spec.add_commit_url(robot_file, commit_id, sol, api) spec.add_commit_url(robot_file, configured_prefix + commit_id, sol, api) else: if configured_prefix != "": spec.add_commit_url(robot_file, configured_prefix, "SOLAAA", "MyAPI") spec.add_commit_url(robot_file, configured_prefix + "deadbeed", "SOLAAA", "MyAPI")