Loading doc/analysis/checks.py +58 −9 Original line number Diff line number Diff line Loading @@ -85,24 +85,69 @@ class Checks: 'params': ['status_code'], 'position': [1] }, 'Check Response Body Type When Using Session Request': { 'position': [2], }, 'Check Response Body Containing ProblemDetails Element Containing Type Element set to': { 'params': ['type'], 'position': [2], 'position': [2] }, 'Check Response Headers Containing Content-Type set to': { 'params': ['content_type'], 'position': [] }, 'Check Response Body Containing an Attribute set to': { 'params': ['attribute_name'], 'position': [] }, 'Check Response Body Containing List Containing EntityTemporal elements': { 'params': ['timeRel', 'timeAt'], 'position': [] }, 'Check Response Body Containing List Containing Subscription elements': { 'params': ['number'], 'position': [] }, 'Check Response Body Containing Number Of Entities': { 'params': ['entity_type', 'number_entities'], 'position': [] }, 'Check Response Body Containing Context Source Registration element': { 'params': ['csr_description'], 'position': [] }, 'Check Response Body Containing EntityTypeList element': { 'params': ['description'], 'position': [] }, 'Check Response Body Containing EntityType element': { 'params': ['description'], 'position': [] }, 'Check Response Body Type When Using Session Request': { 'params': ['type'], 'position': [2] }, 'Check RL Response Body Containing ProblemDetails Element Containing Type Element set to': { 'position': [2], 'params': ['type'], 'position': [2] }, 'Check JSON Value In Response Body': { 'position': [1, 2], 'params': ['key', 'value'], 'position': [1, 2] }, 'Check Pagination Prev And Next Headers': { 'position': [2, 3], 'params': ['previous', 'next'], 'position': [2, 3] }, 'Check Updated Resources Set To': { 'params': ['number_entities'], 'position': [] }, 'Check SUT Not Containing Resource': { 'position': [1], 'params': ['status_code'], 'position': [1] }, 'Check NotificationParams': { 'params': ['format', 'uri', 'accept', 'status', 'timesSent'], 'position': [] } } Loading Loading @@ -227,7 +272,6 @@ class Checks: else: raise Exception(f"ERROR, expected csr_description attribute, but received: {kwargs}") @staticmethod def check_response_body_containing_entitytypelist_element(kwargs: list) -> str: if 'description' in kwargs: Loading Loading @@ -332,14 +376,17 @@ class Checks: def check_created_resource_set_to(kwargs: list) -> str: return "Created Entity set to ${entity}" @staticmethod def check_updated_resource_set_to(kwargs: list) -> str: return "Updated Entity set to ${entity}" @staticmethod def check_updated_resources_set_to(kwargs: list) -> str: if 'number_entities' in kwargs: number_entities = kwargs['number_entities'] return f"Updated Entities set to '{number_entities}' valid entities" @staticmethod def check_sut_not_containing_resource(kwargs: list) -> str: if "status_code" in kwargs: status_code = kwargs['status_code'] Loading @@ -347,9 +394,11 @@ class Checks: else: raise Exception(f'ERROR, Expected status_code parameter but received: {kwargs}') @staticmethod def check_sut_not_containing_resources(kwargs: list) -> str: return f'Response body is empty' @staticmethod def check_notificationparams(kwargs: list) -> str: expected_parameters = ["format", "uri", "accept", "status", "timesSent"] result = [x for x in expected_parameters if x not in kwargs] Loading doc/analysis/generaterobotdata.py +8 −1 Original line number Diff line number Diff line Loading @@ -108,6 +108,9 @@ class GenerateRobotData: self.test_cases[index]['http_verb'] = verb self.test_cases[index]['endpoint'] = self.get_header_value(key=url) self.test_cases[index]['when'] = self.robot.generate_when_content(http_verb=self.test_cases[index]['http_verb'], endpoint=self.test_cases[index]['endpoint'], when=self.test_cases[index]['when']) #expected_status_code = self.robot.get_expected_status_code(keyword='Check Response Status Code') #self.test_cases[index]['expected_status_code'] = expected_status_code Loading Loading @@ -236,6 +239,9 @@ class GenerateRobotData: # Generate Checks for Test Data then = self.robot.get_checks(test_name=test.name, apiutils=self.apiutil) # Generate Request for Test Data when = self.robot.get_request(test_name=test.name) test_case = { 'name': test.name, 'permutation_tp_id': f'{self.base_TP_id}/{test.name.split(" ")[0]}', Loading @@ -246,7 +252,8 @@ class GenerateRobotData: 'template': test.template, 'content-type': content_type, 'body': body, 'then': then 'then': then, 'when': when } try: Loading doc/analysis/parserobotfile.py +18 −1 Original line number Diff line number Diff line import re import os from doc.analysis.checks import Checks from doc.analysis.requests import Requests class ParseRobotFile: Loading Loading @@ -118,6 +119,12 @@ class ParseRobotFile: return result def get_request(self, test_name): print(test_name) data = Requests(variables=self.variables, apiutils_variables=self.apiutils.variables) description = data.get_description(string=self.test_cases[test_name]) return description def generate_then_content(self, content): if len(content) > 1: checks = " and\n ".join(content) Loading @@ -129,6 +136,16 @@ class ParseRobotFile: return checks def generate_when_content(self, http_verb, endpoint, when): url = f"URL set to '/ngsi-ld/v1/{endpoint}'" method = f"method set to '{http_verb}'" when = (f"when {{\n the SUT receives a Request from the client containing:\n" f" {url}\n" f" {method}\n" f" {when}") return when def get_data_check(self, test_case, checks, line): content = line.split(" ") aux = len(content) Loading doc/analysis/requests.py 0 → 100644 +135 −0 Original line number Diff line number Diff line import re class Requests: def __init__(self, variables, apiutils_variables): self.op = { 'Create Entity Selecting Content Type': { 'positions': [1, 3], 'params': ['filename', 'content_type'] }, 'Create Subscription': { 'positions': [2, 3], 'params': ['filename', 'content_type'] }, 'Create Or Update Temporal Representation Of Entity Selecting Content Type': { 'positions': [2, 3], 'params': ['filename', 'content_type'] }, 'Batch Create Entities': { 'positions': [2], 'params': ['content_type'] }, 'Create Context Source Registration With Return': { 'positions': [1], 'params': ['filename'] } } self.description = { 'Create Entity Selecting Content Type': Requests.create_entity_selecting_content_type, 'Create Subscription': Requests.create_entity_selecting_content_type, 'Create Or Update Temporal Representation Of Entity Selecting Content Type': Requests.create_entity_selecting_content_type, 'Batch Create Entities': Requests.batch_create_entities, 'Create Context Source Registration With Return': Requests.create_context_source_registration_with_return } self.variables = variables self.apiutils_variables = apiutils_variables def get_description(self, string): keys = self.op.keys() params = dict() index = None for k in keys: index = string.find(k) if index != -1: break pattern = f"^.*{k}.*\n" lines_starting_with_request = re.findall(pattern, string, re.MULTILINE) for line in lines_starting_with_request: data = line.strip().split(" ") if len(data) == 2: # We are in multiline definition params = self.find_attributes_next_line(string=string, position=index, request_name=k) else: # The definition of the request is in the same line params = self.find_attributes_in_the_same_line(request_name=k, params=data[1:]) description = self.description[k](params) return description def find_attributes_in_the_same_line(self, request_name, params): param = dict() for i in range(0, len(self.op[request_name]['positions'])): param_position = self.op[request_name]['positions'][i] param_key = self.op[request_name]['params'][i] param_value = self.get_value(params=params, param_position=param_position) param[param_key] = param_value return param def find_attributes_next_line(self, string, position, request_name): aux = string[position+len(request_name)+1:].split('\n') params = list() for a in range(0, len(aux)): param = aux[a] if param.startswith(" ..."): params.append(param.split(' ')[-1]) else: break param = dict() for i in range(0, len(self.op[request_name]['positions'])): print(i) param_position = self.op[request_name]['positions'][i] - 1 param_value = self.get_value(params=params, param_position=param_position) param_key = self.op[request_name]['params'][i] param[param_key] = param_value return param @staticmethod def create_entity_selecting_content_type(kwargs) -> str: if 'filename' in kwargs and 'content_type' in kwargs: result = (f"Request Header['Content-Type'] set to '{kwargs['content_type']}' and\n " f"payload defined in file: '{kwargs['filename']}'") return result else: raise Exception(f"ERROR, expected filename and content_type attributes, but received {kwargs}") @staticmethod def batch_create_entities(kwargs) -> str: if 'content_type' in kwargs: result = (f"Request Header['Content-Type'] set to '{kwargs['content_type']}' and\n " f"payload set to a list of entities to be created") return result else: raise Exception(f"ERROR, expected content_type attribute, but received {kwargs}") @staticmethod def create_context_source_registration_with_return(kwargs) -> str: if 'filename' in kwargs: result = (f"Request Header['Content-Type'] set to 'application/ld+json' and\n " f"payload defined in file: '{kwargs['filename']}'") return result else: raise Exception(f"ERROR, expected filename attribute, but received {kwargs}") def get_value(self, params, param_position): try: value = self.variables[params[param_position]] return value except KeyError: try: value = self.apiutils_variables[params[param_position]] return value except KeyError: return params[param_position] Loading
doc/analysis/checks.py +58 −9 Original line number Diff line number Diff line Loading @@ -85,24 +85,69 @@ class Checks: 'params': ['status_code'], 'position': [1] }, 'Check Response Body Type When Using Session Request': { 'position': [2], }, 'Check Response Body Containing ProblemDetails Element Containing Type Element set to': { 'params': ['type'], 'position': [2], 'position': [2] }, 'Check Response Headers Containing Content-Type set to': { 'params': ['content_type'], 'position': [] }, 'Check Response Body Containing an Attribute set to': { 'params': ['attribute_name'], 'position': [] }, 'Check Response Body Containing List Containing EntityTemporal elements': { 'params': ['timeRel', 'timeAt'], 'position': [] }, 'Check Response Body Containing List Containing Subscription elements': { 'params': ['number'], 'position': [] }, 'Check Response Body Containing Number Of Entities': { 'params': ['entity_type', 'number_entities'], 'position': [] }, 'Check Response Body Containing Context Source Registration element': { 'params': ['csr_description'], 'position': [] }, 'Check Response Body Containing EntityTypeList element': { 'params': ['description'], 'position': [] }, 'Check Response Body Containing EntityType element': { 'params': ['description'], 'position': [] }, 'Check Response Body Type When Using Session Request': { 'params': ['type'], 'position': [2] }, 'Check RL Response Body Containing ProblemDetails Element Containing Type Element set to': { 'position': [2], 'params': ['type'], 'position': [2] }, 'Check JSON Value In Response Body': { 'position': [1, 2], 'params': ['key', 'value'], 'position': [1, 2] }, 'Check Pagination Prev And Next Headers': { 'position': [2, 3], 'params': ['previous', 'next'], 'position': [2, 3] }, 'Check Updated Resources Set To': { 'params': ['number_entities'], 'position': [] }, 'Check SUT Not Containing Resource': { 'position': [1], 'params': ['status_code'], 'position': [1] }, 'Check NotificationParams': { 'params': ['format', 'uri', 'accept', 'status', 'timesSent'], 'position': [] } } Loading Loading @@ -227,7 +272,6 @@ class Checks: else: raise Exception(f"ERROR, expected csr_description attribute, but received: {kwargs}") @staticmethod def check_response_body_containing_entitytypelist_element(kwargs: list) -> str: if 'description' in kwargs: Loading Loading @@ -332,14 +376,17 @@ class Checks: def check_created_resource_set_to(kwargs: list) -> str: return "Created Entity set to ${entity}" @staticmethod def check_updated_resource_set_to(kwargs: list) -> str: return "Updated Entity set to ${entity}" @staticmethod def check_updated_resources_set_to(kwargs: list) -> str: if 'number_entities' in kwargs: number_entities = kwargs['number_entities'] return f"Updated Entities set to '{number_entities}' valid entities" @staticmethod def check_sut_not_containing_resource(kwargs: list) -> str: if "status_code" in kwargs: status_code = kwargs['status_code'] Loading @@ -347,9 +394,11 @@ class Checks: else: raise Exception(f'ERROR, Expected status_code parameter but received: {kwargs}') @staticmethod def check_sut_not_containing_resources(kwargs: list) -> str: return f'Response body is empty' @staticmethod def check_notificationparams(kwargs: list) -> str: expected_parameters = ["format", "uri", "accept", "status", "timesSent"] result = [x for x in expected_parameters if x not in kwargs] Loading
doc/analysis/generaterobotdata.py +8 −1 Original line number Diff line number Diff line Loading @@ -108,6 +108,9 @@ class GenerateRobotData: self.test_cases[index]['http_verb'] = verb self.test_cases[index]['endpoint'] = self.get_header_value(key=url) self.test_cases[index]['when'] = self.robot.generate_when_content(http_verb=self.test_cases[index]['http_verb'], endpoint=self.test_cases[index]['endpoint'], when=self.test_cases[index]['when']) #expected_status_code = self.robot.get_expected_status_code(keyword='Check Response Status Code') #self.test_cases[index]['expected_status_code'] = expected_status_code Loading Loading @@ -236,6 +239,9 @@ class GenerateRobotData: # Generate Checks for Test Data then = self.robot.get_checks(test_name=test.name, apiutils=self.apiutil) # Generate Request for Test Data when = self.robot.get_request(test_name=test.name) test_case = { 'name': test.name, 'permutation_tp_id': f'{self.base_TP_id}/{test.name.split(" ")[0]}', Loading @@ -246,7 +252,8 @@ class GenerateRobotData: 'template': test.template, 'content-type': content_type, 'body': body, 'then': then 'then': then, 'when': when } try: Loading
doc/analysis/parserobotfile.py +18 −1 Original line number Diff line number Diff line import re import os from doc.analysis.checks import Checks from doc.analysis.requests import Requests class ParseRobotFile: Loading Loading @@ -118,6 +119,12 @@ class ParseRobotFile: return result def get_request(self, test_name): print(test_name) data = Requests(variables=self.variables, apiutils_variables=self.apiutils.variables) description = data.get_description(string=self.test_cases[test_name]) return description def generate_then_content(self, content): if len(content) > 1: checks = " and\n ".join(content) Loading @@ -129,6 +136,16 @@ class ParseRobotFile: return checks def generate_when_content(self, http_verb, endpoint, when): url = f"URL set to '/ngsi-ld/v1/{endpoint}'" method = f"method set to '{http_verb}'" when = (f"when {{\n the SUT receives a Request from the client containing:\n" f" {url}\n" f" {method}\n" f" {when}") return when def get_data_check(self, test_case, checks, line): content = line.split(" ") aux = len(content) Loading
doc/analysis/requests.py 0 → 100644 +135 −0 Original line number Diff line number Diff line import re class Requests: def __init__(self, variables, apiutils_variables): self.op = { 'Create Entity Selecting Content Type': { 'positions': [1, 3], 'params': ['filename', 'content_type'] }, 'Create Subscription': { 'positions': [2, 3], 'params': ['filename', 'content_type'] }, 'Create Or Update Temporal Representation Of Entity Selecting Content Type': { 'positions': [2, 3], 'params': ['filename', 'content_type'] }, 'Batch Create Entities': { 'positions': [2], 'params': ['content_type'] }, 'Create Context Source Registration With Return': { 'positions': [1], 'params': ['filename'] } } self.description = { 'Create Entity Selecting Content Type': Requests.create_entity_selecting_content_type, 'Create Subscription': Requests.create_entity_selecting_content_type, 'Create Or Update Temporal Representation Of Entity Selecting Content Type': Requests.create_entity_selecting_content_type, 'Batch Create Entities': Requests.batch_create_entities, 'Create Context Source Registration With Return': Requests.create_context_source_registration_with_return } self.variables = variables self.apiutils_variables = apiutils_variables def get_description(self, string): keys = self.op.keys() params = dict() index = None for k in keys: index = string.find(k) if index != -1: break pattern = f"^.*{k}.*\n" lines_starting_with_request = re.findall(pattern, string, re.MULTILINE) for line in lines_starting_with_request: data = line.strip().split(" ") if len(data) == 2: # We are in multiline definition params = self.find_attributes_next_line(string=string, position=index, request_name=k) else: # The definition of the request is in the same line params = self.find_attributes_in_the_same_line(request_name=k, params=data[1:]) description = self.description[k](params) return description def find_attributes_in_the_same_line(self, request_name, params): param = dict() for i in range(0, len(self.op[request_name]['positions'])): param_position = self.op[request_name]['positions'][i] param_key = self.op[request_name]['params'][i] param_value = self.get_value(params=params, param_position=param_position) param[param_key] = param_value return param def find_attributes_next_line(self, string, position, request_name): aux = string[position+len(request_name)+1:].split('\n') params = list() for a in range(0, len(aux)): param = aux[a] if param.startswith(" ..."): params.append(param.split(' ')[-1]) else: break param = dict() for i in range(0, len(self.op[request_name]['positions'])): print(i) param_position = self.op[request_name]['positions'][i] - 1 param_value = self.get_value(params=params, param_position=param_position) param_key = self.op[request_name]['params'][i] param[param_key] = param_value return param @staticmethod def create_entity_selecting_content_type(kwargs) -> str: if 'filename' in kwargs and 'content_type' in kwargs: result = (f"Request Header['Content-Type'] set to '{kwargs['content_type']}' and\n " f"payload defined in file: '{kwargs['filename']}'") return result else: raise Exception(f"ERROR, expected filename and content_type attributes, but received {kwargs}") @staticmethod def batch_create_entities(kwargs) -> str: if 'content_type' in kwargs: result = (f"Request Header['Content-Type'] set to '{kwargs['content_type']}' and\n " f"payload set to a list of entities to be created") return result else: raise Exception(f"ERROR, expected content_type attribute, but received {kwargs}") @staticmethod def create_context_source_registration_with_return(kwargs) -> str: if 'filename' in kwargs: result = (f"Request Header['Content-Type'] set to 'application/ld+json' and\n " f"payload defined in file: '{kwargs['filename']}'") return result else: raise Exception(f"ERROR, expected filename attribute, but received {kwargs}") def get_value(self, params, param_position): try: value = self.variables[params[param_position]] return value except KeyError: try: value = self.apiutils_variables[params[param_position]] return value except KeyError: return params[param_position]